From: "Serge E. Hallyn" <serge@hallyn.com>
To: "Andrew G. Morgan" <morgan@kernel.org>
Cc: Gaosheng Cui <cuigaosheng1@huawei.com>,
serge@hallyn.com, akpm@linux-foundation.org, ezk@cs.sunysb.edu,
linux-security-module@vger.kernel.org
Subject: Re: [PATCH] capabilities: fix undefined behavior in bit shift for CAP_TO_MASK
Date: Mon, 31 Oct 2022 23:30:23 -0500 [thread overview]
Message-ID: <20221101043023.GA7631@mail.hallyn.com> (raw)
In-Reply-To: <CALQRfL4Ws255bv_ptCt1qS3cbxjwUsawxAuTyV1pnLwg+70_NQ@mail.gmail.com>
On Mon, Oct 31, 2022 at 07:18:54AM -0700, Andrew G. Morgan wrote:
> Acked-by: Andrew G. Morgan <morgan@kernel.org>
>
>
> On Mon, Oct 31, 2022 at 4:25 AM Gaosheng Cui <cuigaosheng1@huawei.com> wrote:
> >
> > Shifting signed 32-bit value by 31 bits is undefined, so changing
> > significant bit to unsigned. The UBSAN warning calltrace like below:
> >
> > UBSAN: shift-out-of-bounds in security/commoncap.c:1252:2
> > left shift of 1 by 31 places cannot be represented in type 'int'
> > Call Trace:
> > <TASK>
> > dump_stack_lvl+0x7d/0xa5
> > dump_stack+0x15/0x1b
> > ubsan_epilogue+0xe/0x4e
> > __ubsan_handle_shift_out_of_bounds+0x1e7/0x20c
> > cap_task_prctl+0x561/0x6f0
> > security_task_prctl+0x5a/0xb0
> > __x64_sys_prctl+0x61/0x8f0
> > do_syscall_64+0x58/0x80
> > entry_SYSCALL_64_after_hwframe+0x63/0xcd
> > </TASK>
> >
> > Fixes: e338d263a76a ("Add 64-bit capability support to the kernel")
> > Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Paul, do you mind including this in your lsm tree?
thanks,
-serge
> > ---
> > include/uapi/linux/capability.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/uapi/linux/capability.h b/include/uapi/linux/capability.h
> > index 463d1ba2232a..3d61a0ae055d 100644
> > --- a/include/uapi/linux/capability.h
> > +++ b/include/uapi/linux/capability.h
> > @@ -426,7 +426,7 @@ struct vfs_ns_cap_data {
> > */
> >
> > #define CAP_TO_INDEX(x) ((x) >> 5) /* 1 << 5 == bits in __u32 */
> > -#define CAP_TO_MASK(x) (1 << ((x) & 31)) /* mask for indexed __u32 */
> > +#define CAP_TO_MASK(x) (1U << ((x) & 31)) /* mask for indexed __u32 */
> >
> >
> > #endif /* _UAPI_LINUX_CAPABILITY_H */
> > --
> > 2.25.1
> >
next prev parent reply other threads:[~2022-11-01 4:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-31 11:25 [PATCH] capabilities: fix undefined behavior in bit shift for CAP_TO_MASK Gaosheng Cui
2022-10-31 14:18 ` Andrew G. Morgan
2022-11-01 4:30 ` Serge E. Hallyn [this message]
2022-11-03 11:57 ` Paul Moore
2022-11-03 13:24 ` Serge E. Hallyn
2022-11-05 5:33 ` Paul Moore
2022-11-05 5:30 ` 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=20221101043023.GA7631@mail.hallyn.com \
--to=serge@hallyn.com \
--cc=akpm@linux-foundation.org \
--cc=cuigaosheng1@huawei.com \
--cc=ezk@cs.sunysb.edu \
--cc=linux-security-module@vger.kernel.org \
--cc=morgan@kernel.org \
/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).