From: Ingyu Jang <ingyujang25@gmail.com>
To: Paul Moore <paul@paul-moore.com>,
Stephen Smalley <stephen.smalley.work@gmail.com>,
Ondrej Mosnacek <omosnace@redhat.com>
Cc: Ingyu Jang <ingyujang25@gmail.com>,
selinux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] selinux: Handle NULL return from selinux_inode in inode_security_rcu
Date: Fri, 17 Jan 2025 04:55:25 +0900 [thread overview]
Message-ID: <20250116195526.2303758-1-ingyujang25@gmail.com> (raw)
The 'selinux_inode' function may return NULL if 'inode->i_security' is
uninitialized or if 'inode->i_security' is NULL.
Previously, this scenario was not explicitly handled in
'inode_security_rcu', which might lead to NULL Pointer dereference.
This patch modifies 'inode_security_rcu' to call 'selinux_inode' and
check its return value.
If 'selinux_inode' returns NULL, '-EACCES' is returned to ensure
consistent error handling.
Furthermore, analysis confirmed that all current usages of
'inode_security_rcu' check the return value using 'IS_ERR', ensuring
compatibility with this change.
Signed-off-by: Ingyu Jang <ingyujang25@gmail.com>
---
security/selinux/hooks.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 171dd7fceac5..61c9191bafbe 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -310,11 +310,17 @@ static struct inode_security_struct *inode_security_novalidate(struct inode *ino
static struct inode_security_struct *inode_security_rcu(struct inode *inode, bool rcu)
{
int error;
+ struct inode_security_struct *isec;
error = __inode_security_revalidate(inode, NULL, !rcu);
if (error)
return ERR_PTR(error);
- return selinux_inode(inode);
+
+ isec = selinux_inode(inode);
+ if (!isec)
+ return ERR_PTR(-EACCES);
+
+ return isec;
}
/*
--
2.34.1
next reply other threads:[~2025-01-16 19:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-16 19:55 Ingyu Jang [this message]
2025-01-16 20:37 ` Stephen Smalley
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=20250116195526.2303758-1-ingyujang25@gmail.com \
--to=ingyujang25@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=omosnace@redhat.com \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
--cc=stephen.smalley.work@gmail.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
all inboxes | Powered by JetHome®