BPF Archive mirror
 help / color / mirror / Atom feed
From: felix <fuzhen5@huawei.com>
To: <paul@paul-moore.com>, <casey@schaufler-ca.com>,
	<roberto.sassu@huawei.com>, <stefanb@linux.ibm.com>,
	<zohar@linux.ibm.com>, <kamrankhadijadj@gmail.com>,
	<andrii@kernel.org>, <omosnace@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <bpf@vger.kernel.org>,
	<xiujianfeng@huawei.com>, <wangweiyang2@huawei.com>
Subject: [PATCH -next] lsm: fix default return value for inode_set(remove)xattr
Date: Mon, 29 Apr 2024 19:46:36 +0800	[thread overview]
Message-ID: <20240429114636.123395-1-fuzhen5@huawei.com> (raw)

From: Felix Fu <fuzhen5@huawei.com>

The return value of security_inode_set(remove)xattr should
be 1. If it return 0, cap_inode_setxattr would not be
executed when no lsm exist, which is not what we expected,
any user could set some security.* xattr for a file.

Before commit 260017f31a8c ("lsm: use default hook return
value in call_int_hook()") was approved, this issue would
still happened when lsm only include bpf, because bpf_lsm_
inode_setxattr return 0 by default which cause cap_inode_set
xattr to be not executed.

Fixes: 260017f31a8c ("lsm: use default hook return value in call_int_hook()")
Signed-off-by: Felix Fu <fuzhen5@huawei.com>
---
 include/linux/lsm_hook_defs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index f804b76cde44..9c768b954264 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -144,14 +144,14 @@ LSM_HOOK(int, 0, inode_setattr, struct mnt_idmap *idmap, struct dentry *dentry,
 LSM_HOOK(void, LSM_RET_VOID, inode_post_setattr, struct mnt_idmap *idmap,
 	 struct dentry *dentry, int ia_valid)
 LSM_HOOK(int, 0, inode_getattr, const struct path *path)
-LSM_HOOK(int, 0, inode_setxattr, struct mnt_idmap *idmap,
+LSM_HOOK(int, 1, inode_setxattr, struct mnt_idmap *idmap,
 	 struct dentry *dentry, const char *name, const void *value,
 	 size_t size, int flags)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_setxattr, struct dentry *dentry,
 	 const char *name, const void *value, size_t size, int flags)
 LSM_HOOK(int, 0, inode_getxattr, struct dentry *dentry, const char *name)
 LSM_HOOK(int, 0, inode_listxattr, struct dentry *dentry)
-LSM_HOOK(int, 0, inode_removexattr, struct mnt_idmap *idmap,
+LSM_HOOK(int, 1, inode_removexattr, struct mnt_idmap *idmap,
 	 struct dentry *dentry, const char *name)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry,
 	 const char *name)
-- 
2.34.1


             reply	other threads:[~2024-04-29 11:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-29 11:46 felix [this message]
2024-05-01 16:02 ` [PATCH -next] lsm: fix default return value for inode_set(remove)xattr Paul Moore
2024-05-01 20:47   ` Paul Moore

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=20240429114636.123395-1-fuzhen5@huawei.com \
    --to=fuzhen5@huawei.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=kamrankhadijadj@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huawei.com \
    --cc=stefanb@linux.ibm.com \
    --cc=wangweiyang2@huawei.com \
    --cc=xiujianfeng@huawei.com \
    --cc=zohar@linux.ibm.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).