All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiu Jianfeng <xiujianfeng@huawei.com>
To: <gregkh@linuxfoundation.org>, <rafael@kernel.org>,
	<viro@zeniv.linux.org.uk>, <brauner@kernel.org>,
	<dhowells@redhat.com>, <code@tyhicks.com>,
	<hirofumi@mail.parknet.co.jp>, <linkinjeon@kernel.org>,
	<sfrench@samba.org>, <senozhatsky@chromium.org>, <tom@talpey.com>,
	<chuck.lever@oracle.com>, <jlayton@kernel.org>,
	<miklos@szeredi.hu>, <paul@paul-moore.com>, <jmorris@namei.org>,
	<serge@hallyn.com>, <stephen.smalley.work@gmail.com>,
	<eparis@parisplace.org>, <casey@schaufler-ca.com>,
	<dchinner@redhat.com>, <john.johansen@canonical.com>,
	<mcgrof@kernel.org>, <mortonm@chromium.org>,
	<fred@cloudflare.com>, <mic@digikod.net>, <mpe@ellerman.id.au>,
	<nathanl@linux.ibm.com>, <gnoack3000@gmail.com>,
	<roberto.sassu@huawei.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>,
	<linux-cachefs@redhat.com>, <ecryptfs@vger.kernel.org>,
	<linux-cifs@vger.kernel.org>, <linux-nfs@vger.kernel.org>,
	<linux-unionfs@vger.kernel.org>,
	<linux-security-module@vger.kernel.org>,
	<selinux@vger.kernel.org>, <wangweiyang2@huawei.com>
Subject: [PATCH -next 0/2] lsm: Change inode_setattr() to take struct
Date: Fri, 5 May 2023 16:11:58 +0800	[thread overview]
Message-ID: <20230505081200.254449-1-xiujianfeng@huawei.com> (raw)

Hi,

I am working on adding xattr/attr support for landlock [1], so we can
control fs accesses such as chmod, chown, uptimes, setxattr, etc.. inside
landlock sandbox. the LSM hooks as following are invoved:
1.inode_setattr
2.inode_setxattr
3.inode_removexattr
4.inode_set_acl
5.inode_remove_acl
which are controlled by LANDLOCK_ACCESS_FS_WRITE_METADATA.

and
1.inode_getattr
2.inode_get_acl
3.inode_getxattr
4.inode_listxattr
which are controlled by LANDLOCK_ACCESS_FS_READ_METADATA

Some of these hooks only take struct dentry as a argument, However, for
path-based LSMs such Landlock, Apparmor and Tomoyo, struct path instead
of struct dentry required to make sense of attr/xattr accesses. So we
need to refactor these hooks to take a struct path argument.

This patchset only refators inode_setattr hook as part of whole work.

Also, I have a problem about file_dentry() in __file_remove_privs() of the
first patch, before changes in commit c1892c37769cf ("vfs: fix deadlock in
file_remove_privs() on overlayfs"), it gets dentry and inode as belows:

struct dentry *dentry = file->f_path.dentry;
struct inode *inode = d_inode(dentry);

That would be clear to change it to pass &file->f_path to
__remove_privs()->notify_change()->inode_setattr().
After that commit, it has been changed to:

struct dentry *dentry = file_dentry(file);
struct inode *inode = file_inode(file);

If I understand correctly, the dentry from file_dentry() maybe the upper
or the lower, it can be different from file->f_path.dentry. It can't just
go back to use &file->f_path otherwise the bug will come back for
overlayfs. So for such scenario, how to get a path from file if the file
maybe or not from overlayfs, and which kind of overlayfs path is ok for
Landlock?

Xiu Jianfeng (2):
  fs: Change notify_change() to take struct path argument
  lsm: Change inode_setattr hook to take struct path argument

 drivers/base/devtmpfs.c       |  5 +++--
 fs/attr.c                     |  7 ++++---
 fs/cachefiles/interface.c     |  4 ++--
 fs/coredump.c                 |  2 +-
 fs/ecryptfs/inode.c           | 18 +++++++++---------
 fs/fat/file.c                 |  2 +-
 fs/inode.c                    |  8 +++++---
 fs/ksmbd/smb2pdu.c            |  6 +++---
 fs/ksmbd/smbacl.c             |  2 +-
 fs/namei.c                    |  2 +-
 fs/nfsd/vfs.c                 | 12 ++++++++----
 fs/open.c                     | 19 ++++++++++---------
 fs/overlayfs/overlayfs.h      |  4 +++-
 fs/utimes.c                   |  2 +-
 include/linux/fs.h            |  4 ++--
 include/linux/lsm_hook_defs.h |  2 +-
 include/linux/security.h      |  4 ++--
 security/security.c           | 10 +++++-----
 security/selinux/hooks.c      |  3 ++-
 security/smack/smack_lsm.c    |  5 +++--
 20 files changed, 67 insertions(+), 54 deletions(-)

-- 
2.17.1


             reply	other threads:[~2023-05-05  8:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05  8:11 Xiu Jianfeng [this message]
2023-05-05  8:11 ` [PATCH -next 1/2] fs: Change notify_change() to take struct path argument Xiu Jianfeng
2023-05-05 17:22   ` [PATCH -next 1/2] " Chuck Lever III
2023-05-05  8:12 ` [PATCH -next 2/2] lsm: Change inode_setattr hook " Xiu Jianfeng
2023-05-10  0:58 ` [PATCH -next 0/2] lsm: Change inode_setattr() to take struct xiujianfeng
2023-05-15 15:12 ` Christian Brauner
2023-05-26 16:33   ` Mickaël Salaün
2023-05-30 13:58     ` Christian Brauner
2023-05-30 14:28       ` Christoph Hellwig
2023-05-30 14:55         ` Casey Schaufler
2023-05-30 16:01           ` Christian Brauner
2023-05-30 22:15             ` Casey Schaufler
2023-05-31  8:36               ` Christian Brauner
2023-05-31 16:44                 ` Casey Schaufler
2023-05-31 13:22           ` Christoph Hellwig
2023-05-31 14:17             ` Casey Schaufler
2023-05-31 15:22         ` Mickaël Salaün

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=20230505081200.254449-1-xiujianfeng@huawei.com \
    --to=xiujianfeng@huawei.com \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=chuck.lever@oracle.com \
    --cc=code@tyhicks.com \
    --cc=dchinner@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=ecryptfs@vger.kernel.org \
    --cc=eparis@parisplace.org \
    --cc=fred@cloudflare.com \
    --cc=gnoack3000@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=jlayton@kernel.org \
    --cc=jmorris@namei.org \
    --cc=john.johansen@canonical.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=mic@digikod.net \
    --cc=miklos@szeredi.hu \
    --cc=mortonm@chromium.org \
    --cc=mpe@ellerman.id.au \
    --cc=nathanl@linux.ibm.com \
    --cc=paul@paul-moore.com \
    --cc=rafael@kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=selinux@vger.kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=serge@hallyn.com \
    --cc=sfrench@samba.org \
    --cc=stephen.smalley.work@gmail.com \
    --cc=tom@talpey.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wangweiyang2@huawei.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.