From: Bob Copeland <me@bobcopeland.com>
To: Matthew Wilcox <matthew@wil.cx>
Cc: Valerie Aurora <vaurora@redhat.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Karel Zak <kzak@redhat.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] VFS: Sanity check mount flags passed to change_mnt_propagation()
Date: Sat, 28 Aug 2010 09:15:16 -0400 [thread overview]
Message-ID: <20100828131516.GA5053@hash.localnet> (raw)
In-Reply-To: <20100828105707.GD3521@parisc-linux.org>
On Sat, Aug 28, 2010 at 04:57:07AM -0600, Matthew Wilcox wrote:
> > Didn't read surrounding code, but is that supposed to be '||'?
> >
> > Otherwise the case where only a single non-propagation flag is
> > set no longer returns 0...
>
> Val's original code returned 0 as failure. So a single non-propagation
> flag set shouldn't return 0.
Not to belabor the point -- but her original code did return zero in
that case (2nd assertion fails):
#include <linux/fs.h>
#include <stdio.h>
#include <assert.h>
#define hweight32 dumb_hweight32
int dumb_hweight32(int a)
{
int i;
int weight = 0;
for (i=0; i < 32; i++)
weight += !!(a & (1 << i));
return weight;
}
static int flags_to_propagation_type(int flags) {
int type = flags & ~MS_REC;
/* Fail if any non-propagation flags are set */
if (type & ~(MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
return 0;
/* Only one propagation flag should be set */
if (((type & (MS_SHARED)) && (type & ~MS_SHARED)) ||
((type & (MS_PRIVATE)) && (type & ~MS_PRIVATE)) ||
((type & (MS_SLAVE)) && (type & ~MS_SLAVE)) ||
((type & (MS_UNBINDABLE)) && (type & ~MS_UNBINDABLE)))
return 0;
return type;
}
static int flags_to_propagation_type_2(int flags) {
int type = flags & ~MS_REC;
/* Only one propagation flag should be set, and no others */
if (hweight32(type) != 1 &&
(type & ~(MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE)))
return 0;
return type;
}
int main(int argc, char *argv[])
{
int mytype = MS_RDONLY;
assert(flags_to_propagation_type(mytype) == 0);
assert(flags_to_propagation_type_2(mytype) == 0);
}
--
Bob Copeland %% www.bobcopeland.com
next prev parent reply other threads:[~2010-08-28 13:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-26 20:03 [PATCH] VFS: Sanity check mount flags passed to change_mnt_propagation() Valerie Aurora
2010-08-27 1:14 ` Matthew Wilcox
2010-08-27 17:43 ` Valerie Aurora
2010-08-27 17:51 ` Bob Copeland
2010-08-27 18:12 ` Valerie Aurora
2010-08-28 10:57 ` Matthew Wilcox
2010-08-28 13:15 ` Bob Copeland [this message]
2010-08-28 21:23 ` Linus Torvalds
2010-08-30 18:26 ` Valerie Aurora
2010-08-27 10:36 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100828131516.GA5053@hash.localnet \
--to=me@bobcopeland.com \
--cc=kzak@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew@wil.cx \
--cc=vaurora@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).