* [patch 4/6] vfs: O_* bit numbers uniqueness check
@ 2010-03-11 22:11 akpm
2010-03-11 23:11 ` Eric Paris
2010-03-12 0:39 ` [patch 4/6] vfs: O_* bit numbers uniqueness check Andreas Dilger
0 siblings, 2 replies; 8+ messages in thread
From: akpm @ 2010-03-11 22:11 UTC (permalink / raw)
To: viro
Cc: linux-fsdevel, akpm, fengguang.wu, davem, eparis, hch, jamie,
rdreier, schwab, sfr
From: Wu Fengguang <fengguang.wu@intel.com>
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.
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Cc: David Miller <davem@davemloft.net>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Eric Paris <eparis@redhat.com>
Cc: Roland Dreier <rdreier@cisco.com>
Cc: Jamie Lokier <jamie@shareable.org>
Cc: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
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-check fs/fcntl.c
--- a/fs/fcntl.c~vfs-o_-bit-numbers-uniqueness-check
+++ a/fs/fcntl.c
@@ -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-check include/asm-generic/fcntl.h
--- a/include/asm-generic/fcntl.h~vfs-o_-bit-numbers-uniqueness-check
+++ a/include/asm-generic/fcntl.h
@@ -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
_
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 4/6] vfs: O_* bit numbers uniqueness check
2010-03-11 22:11 [patch 4/6] vfs: O_* bit numbers uniqueness check akpm
@ 2010-03-11 23:11 ` Eric Paris
2010-03-12 13:41 ` [PATCH] vfs: O_* bit numbers uniqueness check fix Wu Fengguang
2010-03-12 0:39 ` [patch 4/6] vfs: O_* bit numbers uniqueness check Andreas Dilger
1 sibling, 1 reply; 8+ messages in thread
From: Eric Paris @ 2010-03-11 23:11 UTC (permalink / raw)
To: akpm
Cc: viro, linux-fsdevel, fengguang.wu, davem, hch, jamie, rdreier,
schwab, sfr
On Thu, 2010-03-11 at 14:11 -0800, akpm@linux-foundation.org wrote:
> From: Wu Fengguang <fengguang.wu@intel.com>
>
> 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
>
> Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
> Cc: David Miller <davem@davemloft.net>
> Cc: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: Christoph Hellwig <hch@infradead.org>
> Cc: Eric Paris <eparis@redhat.com>
> Cc: Roland Dreier <rdreier@cisco.com>
> Cc: Jamie Lokier <jamie@shareable.org>
> Cc: Andreas Schwab <schwab@linux-m68k.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
> 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-check fs/fcntl.c
> --- a/fs/fcntl.c~vfs-o_-bit-numbers-uniqueness-check
> +++ a/fs/fcntl.c
> @@ -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-check include/asm-generic/fcntl.h
> --- a/include/asm-generic/fcntl.h~vfs-o_-bit-numbers-uniqueness-check
> +++ a/include/asm-generic/fcntl.h
> @@ -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
> _
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] vfs: O_* bit numbers uniqueness check fix
2010-03-11 23:11 ` Eric Paris
@ 2010-03-12 13:41 ` Wu Fengguang
2010-03-12 15:01 ` Eric Paris
0 siblings, 1 reply; 8+ messages in thread
From: Wu Fengguang @ 2010-03-12 13:41 UTC (permalink / raw)
To: Eric Paris
Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org, davem@davemloft.net,
hch@infradead.org, jamie@shareable.org, rdreier@cisco.com,
schwab@linux-m68k.org, sfr@canb.auug.org.au
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....
CC: Eric Paris <eparis@redhat.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
fs/fcntl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--- linux-mm.orig/fs/fcntl.c 2010-03-12 21:27:12.000000000 +0800
+++ linux-mm/fs/fcntl.c 2010-03-12 21:38:51.000000000 +0800
@@ -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",
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] vfs: O_* bit numbers uniqueness check fix
2010-03-12 13:41 ` [PATCH] vfs: O_* bit numbers uniqueness check fix Wu Fengguang
@ 2010-03-12 15:01 ` Eric Paris
2010-03-12 15:14 ` Wu Fengguang
0 siblings, 1 reply; 8+ messages in thread
From: Eric Paris @ 2010-03-12 15:01 UTC (permalink / raw)
To: Wu Fengguang
Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org, davem@davemloft.net,
hch@infradead.org, jamie@shareable.org, rdreier@cisco.com,
schwab@linux-m68k.org, sfr@canb.auug.org.au
On Fri, 2010-03-12 at 21:41 +0800, Wu Fengguang wrote:
> 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....
>
> CC: Eric Paris <eparis@redhat.com>
> Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
> ---
> fs/fcntl.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> --- linux-mm.orig/fs/fcntl.c 2010-03-12 21:27:12.000000000 +0800
> +++ linux-mm/fs/fcntl.c 2010-03-12 21:38:51.000000000 +0800
> @@ -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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] vfs: O_* bit numbers uniqueness check fix
2010-03-12 15:01 ` Eric Paris
@ 2010-03-12 15:14 ` Wu Fengguang
2010-03-12 15:15 ` Wu Fengguang
0 siblings, 1 reply; 8+ messages in thread
From: Wu Fengguang @ 2010-03-12 15:14 UTC (permalink / raw)
To: Eric Paris
Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org, davem@davemloft.net,
hch@infradead.org, jamie@shareable.org, rdreier@cisco.com,
schwab@linux-m68k.org, sfr@canb.auug.org.au
On Fri, Mar 12, 2010 at 11:01:27PM +0800, Eric Paris wrote:
> On Fri, 2010-03-12 at 21:41 +0800, Wu Fengguang wrote:
> > 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....
> >
> > CC: Eric Paris <eparis@redhat.com>
> > Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
> > ---
> > fs/fcntl.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > --- linux-mm.orig/fs/fcntl.c 2010-03-12 21:27:12.000000000 +0800
> > +++ linux-mm/fs/fcntl.c 2010-03-12 21:38:51.000000000 +0800
> > @@ -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 <fengguang.wu@intel.com>
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....
CC: Eric Paris <eparis@redhat.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
fs/fcntl.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
--- linux-mm.orig/fs/fcntl.c 2010-03-12 21:27:12.000000000 +0800
+++ linux-mm/fs/fcntl.c 2010-03-12 23:11:46.000000000 +0800
@@ -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",
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] vfs: O_* bit numbers uniqueness check fix
2010-03-12 15:14 ` Wu Fengguang
@ 2010-03-12 15:15 ` Wu Fengguang
0 siblings, 0 replies; 8+ messages in thread
From: Wu Fengguang @ 2010-03-12 15:15 UTC (permalink / raw)
To: Eric Paris
Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org, davem@davemloft.net,
hch@infradead.org, jamie@shareable.org, rdreier@cisco.com,
schwab@linux-m68k.org, sfr@canb.auug.org.au
> > 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 <fengguang.wu@intel.com>
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(
CC: Andreas Dilger <adilger@sun.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
fs/fcntl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- linux-mm.orig/fs/fcntl.c 2010-03-12 23:11:46.000000000 +0800
+++ linux-mm/fs/fcntl.c 2010-03-12 23:12:05.000000000 +0800
@@ -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 |
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 4/6] vfs: O_* bit numbers uniqueness check
2010-03-11 22:11 [patch 4/6] vfs: O_* bit numbers uniqueness check akpm
2010-03-11 23:11 ` Eric Paris
@ 2010-03-12 0:39 ` Andreas Dilger
2010-03-12 13:42 ` [PATCH] vfs: O_* bit numbers uniqueness check fix 2 Wu Fengguang
1 sibling, 1 reply; 8+ messages in thread
From: Andreas Dilger @ 2010-03-12 0:39 UTC (permalink / raw)
To: akpm
Cc: viro, linux-fsdevel, fengguang.wu, davem, eparis, hch, jamie,
rdreier, schwab, sfr
On 2010-03-11, at 15:11, akpm@linux-foundation.org wrote:
> +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
> + ));
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH] vfs: O_* bit numbers uniqueness check fix 2
2010-03-12 0:39 ` [patch 4/6] vfs: O_* bit numbers uniqueness check Andreas Dilger
@ 2010-03-12 13:42 ` Wu Fengguang
0 siblings, 0 replies; 8+ messages in thread
From: Wu Fengguang @ 2010-03-12 13:42 UTC (permalink / raw)
To: Andreas Dilger
Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
linux-fsdevel@vger.kernel.org, davem@davemloft.net,
eparis@redhat.com, hch@infradead.org, jamie@shareable.org,
rdreier@cisco.com, schwab@linux-m68k.org, sfr@canb.auug.org.au
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 <adilger@sun.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
fs/fcntl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- linux-mm.orig/fs/fcntl.c 2010-03-12 21:39:01.000000000 +0800
+++ linux-mm/fs/fcntl.c 2010-03-12 21:38:42.000000000 +0800
@@ -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 |
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-03-12 15:15 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-11 22:11 [patch 4/6] vfs: O_* bit numbers uniqueness check akpm
2010-03-11 23:11 ` Eric Paris
2010-03-12 13:41 ` [PATCH] vfs: O_* bit numbers uniqueness check fix Wu Fengguang
2010-03-12 15:01 ` Eric Paris
2010-03-12 15:14 ` Wu Fengguang
2010-03-12 15:15 ` Wu Fengguang
2010-03-12 0:39 ` [patch 4/6] vfs: O_* bit numbers uniqueness check Andreas Dilger
2010-03-12 13:42 ` [PATCH] vfs: O_* bit numbers uniqueness check fix 2 Wu Fengguang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).