From: Paul Moore <paul@paul-moore.com>
To: "Christian Göttsche" <cgzones@googlemail.com>
Cc: selinux@vger.kernel.org,
Stephen Smalley <stephen.smalley.work@gmail.com>,
Eric Paris <eparis@parisplace.org>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Ondrej Mosnacek <omosnace@redhat.com>,
Serge Hallyn <serge@hallyn.com>, Austin Kim <austin.kim@lge.com>,
Jiapeng Chong <jiapeng.chong@linux.alibaba.com>,
Casey Schaufler <casey@schaufler-ca.com>,
Yang Li <yang.lee@linux.alibaba.com>,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH 5/5] selinux: drop unnecessary NULL check
Date: Fri, 18 Feb 2022 11:22:46 -0500 [thread overview]
Message-ID: <CAHC9VhSup7QDQSGxDhbHrpEVNJZ7C0ReDcvuLF=S+1Mb=xRUdQ@mail.gmail.com> (raw)
In-Reply-To: <20220217142133.72205-4-cgzones@googlemail.com>
On Thu, Feb 17, 2022 at 9:22 AM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> Commit e3489f8974e1 ("selinux: kill selinux_sb_get_mnt_opts()")
> introduced a NULL check on the context after a successful call to
> security_sid_to_context(). This is on the one hand redundant after
> checking for success and on the other hand insufficient on an actual
> NULL pointer, since the context is passed to seq_escape() leading to a
> call of strlen() on it.
>
> Reported by Clang analyzer:
>
> In file included from security/selinux/hooks.c:28:
> In file included from ./include/linux/tracehook.h:50:
> In file included from ./include/linux/memcontrol.h:13:
> In file included from ./include/linux/cgroup.h:18:
> ./include/linux/seq_file.h:136:25: warning: Null pointer passed as 1st argument to string length function [unix.cstring.NullArg]
> seq_escape_mem(m, src, strlen(src), flags, esc);
> ^~~~~~~~~~~
Interesting. If I'm understanding this correctly, Clang is reporting
on a potential NULL pointer simply because we are checking for a NULL
pointer a few lines earlier, even though @context should not be NULL
if (rc != 0)?
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
> ---
> security/selinux/hooks.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 1e69f88eb326..ac802b99d36c 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -1020,7 +1020,7 @@ static int show_sid(struct seq_file *m, u32 sid)
> rc = security_sid_to_context(&selinux_state, sid,
> &context, &len);
> if (!rc) {
> - bool has_comma = context && strchr(context, ',');
> + bool has_comma = strchr(context, ',');
>
> seq_putc(m, '=');
> if (has_comma)
> --
> 2.35.1
--
paul-moore.com
next prev parent reply other threads:[~2022-02-18 16:23 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-17 14:21 [PATCH 2/5] selinux: use correct type for context length Christian Göttsche
2022-02-17 14:21 ` [PATCH 3/5] selinux: use consistent pointer types for boolean arrays Christian Göttsche
2022-02-18 16:01 ` Paul Moore
2022-03-08 15:57 ` Christian Göttsche
2022-02-17 14:21 ` [PATCH 4/5] selinux: declare data arrays const Christian Göttsche
2022-02-18 16:13 ` Paul Moore
2022-02-18 17:24 ` Nick Desaulniers
2022-02-22 23:16 ` Paul Moore
2022-03-08 16:55 ` [PATCH v2 " Christian Göttsche
2022-04-04 20:03 ` Paul Moore
2022-05-02 14:43 ` [PATCH v3] " Christian Göttsche
2022-05-03 19:59 ` Paul Moore
2022-02-17 14:21 ` [PATCH 5/5] selinux: drop unnecessary NULL check Christian Göttsche
2022-02-18 16:22 ` Paul Moore [this message]
2022-02-18 17:31 ` Nick Desaulniers
2022-03-08 16:09 ` Christian Göttsche
2022-05-02 13:43 ` Christian Göttsche
2022-05-04 11:15 ` Ondrej Mosnacek
2022-06-07 21:22 ` Paul Moore
2022-06-07 21:26 ` Nick Desaulniers
2022-06-07 21:35 ` Paul Moore
2022-02-17 14:21 ` [PATCH 1/5] selinux: drop return statement at end of void functions Christian Göttsche
2022-02-18 15:44 ` Paul Moore
2022-02-18 15:47 ` [PATCH 2/5] selinux: use correct type for context length 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='CAHC9VhSup7QDQSGxDhbHrpEVNJZ7C0ReDcvuLF=S+1Mb=xRUdQ@mail.gmail.com' \
--to=paul@paul-moore.com \
--cc=austin.kim@lge.com \
--cc=casey@schaufler-ca.com \
--cc=cgzones@googlemail.com \
--cc=eparis@parisplace.org \
--cc=jiapeng.chong@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=omosnace@redhat.com \
--cc=selinux@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=stephen.smalley.work@gmail.com \
--cc=yang.lee@linux.alibaba.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 NNTP newsgroup(s).