vfs: O_* bit numbers uniqueness check
PATCH 4/6 vfs: O_* bit numbers uniqueness check
From: Wu Fengguang <[email protected]>
The 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 | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-)
fs/fcntl.c renamed from fs/fcntl.c~vfs-o_-bit-numbers-uniqueness-check +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 renamed from include/asm-generic/fcntl.h~vfs-o_-bit-numbers-uniqueness-check +2 -0
@@ -4,6 +4,8 @@#include <linux/types.h> /* +* When introducing new O_* bits, please check its uniqueness in fcntl_init(). +* * FMODE_EXEC is 0x20 * FMODE_NONOTIFY is 0x1000000 * These cannot be used by userspace O_* until internal and external open
_
Quoted 5 lines · On Thu, 2010-03-11 at 14:11 -0800, [email protected] wrote:
From: Wu Fengguang <[email protected]>
The 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.
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....
-Eric
Quoted 57 lines
Signed-off-by Wu Fengguang <[email protected]>Cc David Miller <[email protected]>Cc Stephen Rothwell <[email protected]>Cc Al Viro <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Eric Paris <[email protected]>Cc Roland Dreier <[email protected]>Cc Jamie Lokier <[email protected]>Cc Andreas Schwab <[email protected]>Signed-off-by Andrew Morton <[email protected]>---
fs/fcntl.c | 14 ++++++++++++-- include/asm-generic/fcntl.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-)diff -puN
fs/fcntl.c~vfs-o_-bit-numbers-uniqueness-checkfs/fcntl.cfs/fcntl.c renamed from fs/fcntl.c~vfs-o_-bit-numbers-uniqueness-check +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)diff -puN
include/asm-generic/fcntl.h~vfs-o_-bit-numbers-uniqueness-checkinclude/asm-generic/fcntl.hinclude/asm-generic/fcntl.h renamed from include/asm-generic/fcntl.h~vfs-o_-bit-numbers-uniqueness-check +2
-0@@ -4,6 +4,8 @@#include <linux/types.h> /* +* When introducing new O_* bits, please check its uniqueness in fcntl_init(). +* * FMODE_EXEC is 0x20 * FMODE_NONOTIFY is 0x1000000 * These cannot be used by userspace O_* until internal and external open _
PATCH 1/1 vfs: O_* bit numbers uniqueness check fix
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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fcntl.c +2 -1
@@ -748,7 +748,8 @@ static int __init fcntl_init(void)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",
Re: [PATCH] vfs: O_* bit numbers uniqueness check fix
Quoted 16 lines · Wu Fengguang
Follow the comment by Eric:
Until the
FMODE_and O_ bits do not overload I think we need to checkFMODE_EXECandFMODE_NONOTIFY(if you have that one) insidefcntl_init()as well. I guess I'll send a patch to someone ?Al? to addFMODE_EXECto the list....CC Eric Paris <[email protected]>Signed-off-by Wu Fengguang <[email protected]>--- fs/fcntl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fcntl.c static int __init fcntl_init(void) · line 753
Quoted 7 lines
fs/fcntl.c +2
-1@@ -748,7 +748,8 @@ static int __init fcntl_init(void)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 ));
I think we need to update the hweight as well, otherwise I sure hope this would panic....
-Eric
Re: [PATCH] vfs: O_* bit numbers uniqueness check fix
Quoted 14 lines · Eric Paris
Quoted 13 lines · Wu Fengguang
Follow the comment by Eric:
Until the
FMODE_and O_ bits do not overload I think we need to checkFMODE_EXECandFMODE_NONOTIFY(if you have that one) insidefcntl_init()as well. I guess I'll send a patch to someone ?Al? to addFMODE_EXECto the list....CC Eric Paris <[email protected]>Signed-off-by Wu Fengguang <[email protected]>--- fs/fcntl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines
fs/fcntl.c static int __init fcntl_init(void) · line 753
Quoted 10 lines
fs/fcntl.c +2
-1@@ -748,7 +748,8 @@ static int __init fcntl_init(void)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 ));I think we need to update the hweight as well, otherwise I sure hope this would panic....
Ah faint.. Here is the fixed one.
Thanks,
Fengguang
---
Subject: vfs: O_* bit numbers uniqueness check fix
From: Wu Fengguang <[email protected]>
Date: Fri Mar 12 21:38:54 CST 2010
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 (17 !=HWEIGHT32 ( +BUILD_BUG_ON (18 !=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",
Re: [PATCH] vfs: O_* bit numbers uniqueness check fix
Quoted 4 lines
Quoted 2 lines
I think we need to update the hweight as well, otherwise I sure hope this would panic....
Ah faint.. Here is the fixed one.
And the second one.
---
Subject: vfs: O_* bit numbers uniqueness check fix 2
From: Wu Fengguang <[email protected]>
Date: Fri Mar 12 21:39:10 CST 2010
Follow 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(18 != 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 |
fs/fcntl.c void kill_fasync(struct fasync_struct ** · line 752
Quoted 11 lines · On 2010-03-11, at 15:11, [email protected] wrote:
+static int
__initfcntl_init(void)
{fs/fcntl.c renamed from fs/fcntl.c~vfs-o_-bit-numbers-uniqueness-check +9
-0+/* 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 + ));
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(
...Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
PATCH 1/1 vfs: O_* bit numbers uniqueness check fix 2
Follow 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 |