Re: [PATCH 1/2] SELinux: Fix lsm_get_self_attr()

From: Paul Moore
Date: Fri Feb 23 2024 - 16:06:52 EST


On Fri, Feb 23, 2024 at 3:04 PM Mickaël Salaün <mic@xxxxxxxxxxx> wrote:
>
> On Fri, Feb 23, 2024 at 08:59:34PM +0100, Mickaël Salaün wrote:
> > On Fri, Feb 23, 2024 at 08:05:45PM +0100, Mickaël Salaün wrote:
> > > selinux_lsm_getattr() may not initialize the value's pointer in some
> > > case. As for proc_pid_attr_read(), initialize this pointer to NULL in
> > > selinux_getselfattr() to avoid an UAF in the kfree() call.
> >
> > Not UAF but NULL pointer dereference (both patches)...
>
> Well, that may be the result (as observed with the kfree() call), but
> the cause is obviously an uninitialized pointer.

Adding the SELinux list to the CC line; SELinux folks the original post is here:

* https://lore.kernel.org/all/20240223190546.3329966-1-mic@xxxxxxxxxxx

Thanks for finding this and testing the patch, based on our off-list
discussion, do you mind if I add a Suggested-by? Looking at this a
bit more I think we'll want to make a few changes to
selinux_lsm_getattr() later, but this patch is a good one for stable
as it not only fixes the bug, but it is a trivial one-liner with very
low risk.

I do think we need to tweak the commit description a bit, what do you
think of the following?

"selinux_getselfattr() doesn't properly initialize the string
pointer it passes to selinux_lsm_getattr() which can cause a
problem when an attribute hasn't been explicitly set;
selinux_lsm_getattr() returns 0/success, but does not set or
initialize the string label/attribute. Failure to properly
initialize the string causes problems later in
selinux_getselfattr() when the function attempts to kfree()
the string."

--
paul-moore.com