一个不太明显的安全问题
在内核里面,程序的结构大概是这样:
函数开始……
struct bar foo;
某些处理(没动foo),然后……
strlcpy(foo.field, k->field, sizeof(k->field));
其他对foo其他字段的赋值处理……
最后
error = copyout(&foo, someaddress, sizeof(foo));
现在问题来了,上面这些东西的问题是什么?应该如何解决?
共 58 篇文章。
在内核里面,程序的结构大概是这样:
函数开始……
struct bar foo;
某些处理(没动foo),然后……
strlcpy(foo.field, k->field, sizeof(k->field));
其他对foo其他字段的赋值处理……
最后
error = copyout(&foo, someaddress, sizeof(foo));
现在问题来了,上面这些东西的问题是什么?应该如何解决?
今天被一个程序折腾了很久。大致的流程是这样:
事件处理:
锁的机制没有大毛病,可是数据死活不对。
Derived from the ancient BSD Unix, *BSD has a set of queue related macros which are described in queue(3), and implemented in src/sys/sys/queue.h. These are primarily used in the kernel, but also useful for userland applications.
So time comes that we should consider whether some of our string operations is not optimial and needs some operation. NetBSD seems to have done a lot of good work to make their MD layer better, and we should take these improvements if they are proven.
David O’Brien has pointed out that we should be careful on this, however, since some micro optimizations may hinder performance in a large scenario. With this concern in mind, I will redo some more benchmarks and request for -arch@’s idea before considering commiting the patchset. Currently, the NetBSD implementation of swab(2) is proven to be slower than the GCC generated code by about 25%. I will look into the assembly code generated to see whether I can help to solve this.
| |
I have an idea: let we have “a” is the number to determine.
return ( (0 == (a & (a-1))) && (a > 0))
Despite the style of the code, is there some better solution? Note that a is a native integer type (say, int, long, long long, etc).
Apparantly des@ has pointed out a serious problem with my patchset, say, the inconsistency of underlying API is the root of evil(tm), and should be corrected.
Let’s go go go!
So I got this in libmsun’s bsdsrc :-)
I started the work almost four months ago, but I have lost all my work last month. Therefore, I’m trying to integrate as much as possible whenever possible. The current workflow is:
What is strict aliasing? To make the long thing short, it means that the compiler apply strictest aliasing rules applicable to the language and having these assumptions the optimizer can do further optimizations.
To quote gcc manual: