diff mbox

[-V1,05/22] vfs: Add new file and directory create permission flags

Message ID 1398615293-22931-6-git-send-email-aneesh.kumar@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Aneesh Kumar K.V April 27, 2014, 4:14 p.m. UTC
From: Andreas Gruenbacher <agruen@kernel.org>

Some permission models distinguish between the permission to create a
non-directory and a directory.  Pass this information down to
inode_permission() as mask flags

Signed-off-by: Andreas Gruenbacher <agruen@kernel.org>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/namei.c         | 21 ++++++++++++---------
 include/linux/fs.h |  2 ++
 2 files changed, 14 insertions(+), 9 deletions(-)

Comments

Jeff Layton April 28, 2014, 11:23 a.m. UTC | #1
On Sun, 27 Apr 2014 21:44:36 +0530
"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:

> From: Andreas Gruenbacher <agruen@kernel.org>
> 
> Some permission models distinguish between the permission to create a
> non-directory and a directory.  Pass this information down to
> inode_permission() as mask flags
> 
> Signed-off-by: Andreas Gruenbacher <agruen@kernel.org>
> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> ---
>  fs/namei.c         | 21 ++++++++++++---------
>  include/linux/fs.h |  2 ++
>  2 files changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/namei.c b/fs/namei.c
> index 7d93d195f0e5..028bc8bcf77c 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -445,7 +445,8 @@ static int sb_permission(struct super_block *sb, struct inode *inode, int mask)
>   * this, letting us set arbitrary permissions for filesystem access without
>   * changing the "normal" UIDs which are used for other things.
>   *
> - * When checking for MAY_APPEND, MAY_WRITE must also be set in @mask.
> + * When checking for MAY_APPEND, MAY_CREATE_FILE, MAY_CREATE_DIR,
> + * MAY_WRITE must also be set in @mask.
>   */
>  int inode_permission(struct inode *inode, int mask)
>  {
> @@ -2444,14 +2445,16 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)
>   *  3. We should have write and exec permissions on dir
>   *  4. We can't do it if dir is immutable (done in permission())
>   */
> -static inline int may_create(struct inode *dir, struct dentry *child)
> +static inline int may_create(struct inode *dir, struct dentry *child, bool isdir)
>  {
> +	int mask = isdir ? MAY_CREATE_DIR : MAY_CREATE_FILE;
> +
>  	audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE);
>  	if (child->d_inode)
>  		return -EEXIST;
>  	if (IS_DEADDIR(dir))
>  		return -ENOENT;
> -	return inode_permission(dir, MAY_WRITE | MAY_EXEC);
> +	return inode_permission(dir, MAY_WRITE | MAY_EXEC | mask);
>  }
>  
>  /*
> @@ -2501,7 +2504,7 @@ EXPORT_SYMBOL(unlock_rename);
>  int vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
>  		bool want_excl)
>  {
> -	int error = may_create(dir, dentry);
> +	int error = may_create(dir, dentry, 0);

nit: since the third argument here is a bool, this should be "false"
and not "0". Ditto for all of the other calls of may_create.

>  	if (error)
>  		return error;
>  
> @@ -3363,7 +3366,7 @@ EXPORT_SYMBOL(user_path_create);
>  
>  int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
>  {
> -	int error = may_create(dir, dentry);
> +	int error = may_create(dir, dentry, 0);
>  
>  	if (error)
>  		return error;
> @@ -3455,7 +3458,7 @@ SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, d
>  
>  int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
>  {
> -	int error = may_create(dir, dentry);
> +	int error = may_create(dir, dentry, 1);
>  	unsigned max_links = dir->i_sb->s_max_links;
>  
>  	if (error)
> @@ -3785,7 +3788,7 @@ SYSCALL_DEFINE1(unlink, const char __user *, pathname)
>  
>  int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname)
>  {
> -	int error = may_create(dir, dentry);
> +	int error = may_create(dir, dentry, 0);
>  
>  	if (error)
>  		return error;
> @@ -3871,7 +3874,7 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
>  	if (S_ISDIR(inode->i_mode))
>  		return -EPERM;
>  
> -	error = may_create(dir, new_dentry);
> +	error = may_create(dir, new_dentry, 0);
>  	if (error)
>  		return error;
>  
> @@ -4062,7 +4065,7 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
>  		return error;
>  
>  	if (!target) {
> -		error = may_create(new_dir, new_dentry);
> +		error = may_create(new_dir, new_dentry, is_dir);
>  	} else {
>  		new_is_dir = d_is_dir(new_dentry);
>  
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 1f524b4b652d..da5521de04ab 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -77,6 +77,8 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
>  #define MAY_CHDIR		0x00000040
>  /* called from RCU mode, don't block */
>  #define MAY_NOT_BLOCK		0x00000080
> +#define MAY_CREATE_FILE		0x00000100
> +#define MAY_CREATE_DIR		0x00000200
>  
>  /*
>   * flags in file.f_mode.  Note that FMODE_READ and FMODE_WRITE must correspond
Dave Chinner April 29, 2014, 12:04 a.m. UTC | #2
On Mon, Apr 28, 2014 at 07:23:01AM -0400, Jeff Layton wrote:
> On Sun, 27 Apr 2014 21:44:36 +0530
> "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
> 
> > From: Andreas Gruenbacher <agruen@kernel.org>
> > 
> > Some permission models distinguish between the permission to create a
> > non-directory and a directory.  Pass this information down to
> > inode_permission() as mask flags
> > 
> > Signed-off-by: Andreas Gruenbacher <agruen@kernel.org>
> > Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> > ---
> >  fs/namei.c         | 21 ++++++++++++---------
> >  include/linux/fs.h |  2 ++
> >  2 files changed, 14 insertions(+), 9 deletions(-)
> > 
> > diff --git a/fs/namei.c b/fs/namei.c
> > index 7d93d195f0e5..028bc8bcf77c 100644
> > --- a/fs/namei.c
> > +++ b/fs/namei.c
> > @@ -445,7 +445,8 @@ static int sb_permission(struct super_block *sb, struct inode *inode, int mask)
> >   * this, letting us set arbitrary permissions for filesystem access without
> >   * changing the "normal" UIDs which are used for other things.
> >   *
> > - * When checking for MAY_APPEND, MAY_WRITE must also be set in @mask.
> > + * When checking for MAY_APPEND, MAY_CREATE_FILE, MAY_CREATE_DIR,
> > + * MAY_WRITE must also be set in @mask.
> >   */
> >  int inode_permission(struct inode *inode, int mask)
> >  {
> > @@ -2444,14 +2445,16 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)
> >   *  3. We should have write and exec permissions on dir
> >   *  4. We can't do it if dir is immutable (done in permission())
> >   */
> > -static inline int may_create(struct inode *dir, struct dentry *child)
> > +static inline int may_create(struct inode *dir, struct dentry *child, bool isdir)
> >  {
> > +	int mask = isdir ? MAY_CREATE_DIR : MAY_CREATE_FILE;
> > +
> >  	audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE);
> >  	if (child->d_inode)
> >  		return -EEXIST;
> >  	if (IS_DEADDIR(dir))
> >  		return -ENOENT;
> > -	return inode_permission(dir, MAY_WRITE | MAY_EXEC);
> > +	return inode_permission(dir, MAY_WRITE | MAY_EXEC | mask);
> >  }
> >  
> >  /*
> > @@ -2501,7 +2504,7 @@ EXPORT_SYMBOL(unlock_rename);
> >  int vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
> >  		bool want_excl)
> >  {
> > -	int error = may_create(dir, dentry);
> > +	int error = may_create(dir, dentry, 0);
> 
> nit: since the third argument here is a bool, this should be "false"
> and not "0". Ditto for all of the other calls of may_create.

IMO, the third argument should be MAY_CREATE_FILE or MAY_CREATE_DIR,
which is what the boolean evaluates to in may_create()....

Cheers,

Dave.
Aneesh Kumar K.V May 1, 2014, 3:16 p.m. UTC | #3
Dave Chinner <david@fromorbit.com> writes:

> On Mon, Apr 28, 2014 at 07:23:01AM -0400, Jeff Layton wrote:
>> On Sun, 27 Apr 2014 21:44:36 +0530
>> "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> wrote:
>> 
>> > From: Andreas Gruenbacher <agruen@kernel.org>
>> > 
>> > Some permission models distinguish between the permission to create a
>> > non-directory and a directory.  Pass this information down to
>> > inode_permission() as mask flags
>> > 
>> > Signed-off-by: Andreas Gruenbacher <agruen@kernel.org>
>> > Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
>> > ---
>> >  fs/namei.c         | 21 ++++++++++++---------
>> >  include/linux/fs.h |  2 ++
>> >  2 files changed, 14 insertions(+), 9 deletions(-)
>> > 
>> > diff --git a/fs/namei.c b/fs/namei.c
>> > index 7d93d195f0e5..028bc8bcf77c 100644
>> > --- a/fs/namei.c
>> > +++ b/fs/namei.c
>> > @@ -445,7 +445,8 @@ static int sb_permission(struct super_block *sb, struct inode *inode, int mask)
>> >   * this, letting us set arbitrary permissions for filesystem access without
>> >   * changing the "normal" UIDs which are used for other things.
>> >   *
>> > - * When checking for MAY_APPEND, MAY_WRITE must also be set in @mask.
>> > + * When checking for MAY_APPEND, MAY_CREATE_FILE, MAY_CREATE_DIR,
>> > + * MAY_WRITE must also be set in @mask.
>> >   */
>> >  int inode_permission(struct inode *inode, int mask)
>> >  {
>> > @@ -2444,14 +2445,16 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)
>> >   *  3. We should have write and exec permissions on dir
>> >   *  4. We can't do it if dir is immutable (done in permission())
>> >   */
>> > -static inline int may_create(struct inode *dir, struct dentry *child)
>> > +static inline int may_create(struct inode *dir, struct dentry *child, bool isdir)
>> >  {
>> > +	int mask = isdir ? MAY_CREATE_DIR : MAY_CREATE_FILE;
>> > +
>> >  	audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE);
>> >  	if (child->d_inode)
>> >  		return -EEXIST;
>> >  	if (IS_DEADDIR(dir))
>> >  		return -ENOENT;
>> > -	return inode_permission(dir, MAY_WRITE | MAY_EXEC);
>> > +	return inode_permission(dir, MAY_WRITE | MAY_EXEC | mask);
>> >  }
>> >  
>> >  /*
>> > @@ -2501,7 +2504,7 @@ EXPORT_SYMBOL(unlock_rename);
>> >  int vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
>> >  		bool want_excl)
>> >  {
>> > -	int error = may_create(dir, dentry);
>> > +	int error = may_create(dir, dentry, 0);
>> 
>> nit: since the third argument here is a bool, this should be "false"
>> and not "0". Ditto for all of the other calls of may_create.
>
> IMO, the third argument should be MAY_CREATE_FILE or MAY_CREATE_DIR,
> which is what the boolean evaluates to in may_create()....

Will do that.

Thanks
-aneesh

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/namei.c b/fs/namei.c
index 7d93d195f0e5..028bc8bcf77c 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -445,7 +445,8 @@  static int sb_permission(struct super_block *sb, struct inode *inode, int mask)
  * this, letting us set arbitrary permissions for filesystem access without
  * changing the "normal" UIDs which are used for other things.
  *
- * When checking for MAY_APPEND, MAY_WRITE must also be set in @mask.
+ * When checking for MAY_APPEND, MAY_CREATE_FILE, MAY_CREATE_DIR,
+ * MAY_WRITE must also be set in @mask.
  */
 int inode_permission(struct inode *inode, int mask)
 {
@@ -2444,14 +2445,16 @@  static int may_delete(struct inode *dir, struct dentry *victim, bool isdir)
  *  3. We should have write and exec permissions on dir
  *  4. We can't do it if dir is immutable (done in permission())
  */
-static inline int may_create(struct inode *dir, struct dentry *child)
+static inline int may_create(struct inode *dir, struct dentry *child, bool isdir)
 {
+	int mask = isdir ? MAY_CREATE_DIR : MAY_CREATE_FILE;
+
 	audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE);
 	if (child->d_inode)
 		return -EEXIST;
 	if (IS_DEADDIR(dir))
 		return -ENOENT;
-	return inode_permission(dir, MAY_WRITE | MAY_EXEC);
+	return inode_permission(dir, MAY_WRITE | MAY_EXEC | mask);
 }
 
 /*
@@ -2501,7 +2504,7 @@  EXPORT_SYMBOL(unlock_rename);
 int vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
 		bool want_excl)
 {
-	int error = may_create(dir, dentry);
+	int error = may_create(dir, dentry, 0);
 	if (error)
 		return error;
 
@@ -3363,7 +3366,7 @@  EXPORT_SYMBOL(user_path_create);
 
 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
 {
-	int error = may_create(dir, dentry);
+	int error = may_create(dir, dentry, 0);
 
 	if (error)
 		return error;
@@ -3455,7 +3458,7 @@  SYSCALL_DEFINE3(mknod, const char __user *, filename, umode_t, mode, unsigned, d
 
 int vfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
 {
-	int error = may_create(dir, dentry);
+	int error = may_create(dir, dentry, 1);
 	unsigned max_links = dir->i_sb->s_max_links;
 
 	if (error)
@@ -3785,7 +3788,7 @@  SYSCALL_DEFINE1(unlink, const char __user *, pathname)
 
 int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname)
 {
-	int error = may_create(dir, dentry);
+	int error = may_create(dir, dentry, 0);
 
 	if (error)
 		return error;
@@ -3871,7 +3874,7 @@  int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
 	if (S_ISDIR(inode->i_mode))
 		return -EPERM;
 
-	error = may_create(dir, new_dentry);
+	error = may_create(dir, new_dentry, 0);
 	if (error)
 		return error;
 
@@ -4062,7 +4065,7 @@  int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 		return error;
 
 	if (!target) {
-		error = may_create(new_dir, new_dentry);
+		error = may_create(new_dir, new_dentry, is_dir);
 	} else {
 		new_is_dir = d_is_dir(new_dentry);
 
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 1f524b4b652d..da5521de04ab 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -77,6 +77,8 @@  typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 #define MAY_CHDIR		0x00000040
 /* called from RCU mode, don't block */
 #define MAY_NOT_BLOCK		0x00000080
+#define MAY_CREATE_FILE		0x00000100
+#define MAY_CREATE_DIR		0x00000200
 
 /*
  * flags in file.f_mode.  Note that FMODE_READ and FMODE_WRITE must correspond