O_* bit numbers uniqueness check patches (V2)
cover O_* bit numbers uniqueness check patches (V2)
Andrew,
Please take these 3 patches. They are against todays's mmotm.
Sorry for the confusion!
Note that the FMODE_EXEC change is moved as the last one, so that when removing FMODE_EXEC from the O_* namespace, the commit can be simply reverted.
Thanks,
Fengguang
PATCH 3/3 vfs: O_* bit numbers uniqueness check fix 2
Follow the comment by Eric:
Until the FMODE_ and O_ bits do not overload I think we need to check FMODE_EXEC and FMODE_NONOTIFY (if you have that one) inside fcntl_init() as well. I guess I'll send a patch to someone ?Al? to add FMODE_EXEC to the list....
--- fs/fcntl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/fcntl.c +3 -2
@@ -742,13 +742,14 @@ EXPORT_SYMBOL(kill_fasync);static int __init fcntl_init (void ) {/* please add new bits here to ensure allocation uniqueness */ -BUILD_BUG_ON (18 -1 /* for O_RDONLY being 0 */ !=HWEIGHT32 ( +BUILD_BUG_ON (19 -1 /* for O_RDONLY being 0 */ !=HWEIGHT32 (O_RDONLY |O_WRONLY |O_RDWR |O_CREAT |O_EXCL |O_NOCTTY |O_TRUNC |O_APPEND |O_NONBLOCK | __O_SYNC |O_DSYNC |FASYNC |O_DIRECT |O_LARGEFILE |O_DIRECTORY | -O_NOFOLLOW |O_NOATIME |O_CLOEXEC +O_NOFOLLOW |O_NOATIME |O_CLOEXEC | +FMODE_EXEC )); fasync_cache = kmem_cache_create("fasync_cache",
PATCH 1/3 vfs: O_* bit numbers uniqueness check
In reply to Wu FengguangThe O_* bit numbers are defined in 20+ arch/*, and can silently overlap. Add a compile time check to ensure the uniqueness as suggested by David Miller.
---
fs/fcntl.c | 14 ++++++++++++-- include/asm-generic/fcntl.h | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-)
fs/fcntl.c +12 -2
@@ -739,11 +739,21 @@ void kill_fasync(struct fasync_struct ** }EXPORT_SYMBOL (kill_fasync); -static int __init fasync_init (void ) +static int __init fcntl_init (void ) { +/* please add new bits here to ensure allocation uniqueness */ +BUILD_BUG_ON (17 !=HWEIGHT32 ( +O_RDONLY |O_WRONLY |O_RDWR | +O_CREAT |O_EXCL |O_NOCTTY | +O_TRUNC |O_APPEND |O_NONBLOCK | + __O_SYNC |O_DSYNC |FASYNC | +O_DIRECT |O_LARGEFILE |O_DIRECTORY | +O_NOFOLLOW |O_NOATIME |O_CLOEXEC + )); + fasync_cache =kmem_cache_create ("fasync_cache" ,sizeof (struct fasync_struct ),0 ,SLAB_PANIC ,NULL );return 0 ; } -module_init (fasync_init) +module_init (fcntl_init)
include/asm-generic/fcntl.h +4 -0
@@ -3,6 +3,10 @@#include <linux/types.h> +/* +* When introducing new O_* bits, please check its uniqueness in fcntl_init(). +*/ +#define O_ACCMODE 00000003#define O_RDONLY 00000000#define O_WRONLY 00000001
PATCH 2/3 vfs: O_* bit numbers uniqueness check fix
In reply to Wu FengguangFollow the comment by Andreas:
It's non-obvious why there are 18 flags listed here, but the hweight is only 17? Presumably this is because O_RDONLY has value 0, but that should at least be
listed in a comment, or the test could be written more explicitly, like:
BUILD_BUG_ON(18 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32(
--- fs/fcntl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fcntl.c +1 -1
@@ -742,7 +742,7 @@ EXPORT_SYMBOL(kill_fasync); static int __init fcntl_init(void) { /* please add new bits here to ensure allocation uniqueness */ - BUILD_BUG_ON(17 != HWEIGHT32( + BUILD_BUG_ON(18 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32( O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC | O_APPEND | O_NONBLOCK |