All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andrew G. Morgan" <morgan@kernel.org>
To: Gaosheng Cui <cuigaosheng1@huawei.com>
Cc: 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 07:18:54 -0700	[thread overview]
Message-ID: <CALQRfL4Ws255bv_ptCt1qS3cbxjwUsawxAuTyV1pnLwg+70_NQ@mail.gmail.com> (raw)
In-Reply-To: <20221031112536.4177761-1-cuigaosheng1@huawei.com>

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>
> ---
>  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
>

  reply	other threads:[~2022-10-31 14:19 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 [this message]
2022-11-01  4:30   ` Serge E. Hallyn
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=CALQRfL4Ws255bv_ptCt1qS3cbxjwUsawxAuTyV1pnLwg+70_NQ@mail.gmail.com \
    --to=morgan@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=cuigaosheng1@huawei.com \
    --cc=ezk@cs.sunysb.edu \
    --cc=linux-security-module@vger.kernel.org \
    --cc=serge@hallyn.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.