Skip to contentSkip to conversation

O_* bit numbers uniqueness check patches

PATCH New Wu Fengguang 1 participant 4 messages Mar 16, 2010

Subsystems (3)
lore
Share & tools
lore
#2 lore raw

PATCH 2/3 vfs: O_* bit numbers uniqueness check fix

In reply to Wu Fengguang

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",
#1 lore raw

PATCH 1/3 vfs: O_* bit numbers uniqueness check

In reply to Wu Fengguang

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.

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]>

---

 fs/fcntl.c                  |   14 ++++++++++++--
 include/asm-generic/fcntl.h |    2 ++
 2 files changed, 14 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 +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
#3 lore raw

PATCH 3/3 vfs: O_* bit numbers uniqueness check fix 2

In reply to Wu Fengguang

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(

CC Andreas Dilger <[email protected]>
---
 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	|
#0 lore raw

cover O_* bit numbers uniqueness check patches

Andrew,

These are the patches to do O_* bit numbers uniqueness check. The first one should already be in your tree, so only need to pull the next twos.

Thanks,
Fengguang