netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netlabel: fix shift wrapping bug in netlbl_catmap_setlong()
@ 2023-06-08 13:57 Dmitry Mastykin
  2023-06-08 18:57 ` Paul Moore
  2023-06-10 19:02 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Mastykin @ 2023-06-08 13:57 UTC (permalink / raw)
  To: paul, netdev, linux-security-module; +Cc: Dmitry Mastykin

There is a shift wrapping bug in this code on 32-bit architectures.
NETLBL_CATMAP_MAPTYPE is u64, bitmap is unsigned long.
Every second 32-bit word of catmap becomes corrupted.

Signed-off-by: Dmitry Mastykin <dmastykin@astralinux.ru>
---
 net/netlabel/netlabel_kapi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
index 54c083003947..27511c90a26f 100644
--- a/net/netlabel/netlabel_kapi.c
+++ b/net/netlabel/netlabel_kapi.c
@@ -857,7 +857,8 @@ int netlbl_catmap_setlong(struct netlbl_lsm_catmap **catmap,
 
 	offset -= iter->startbit;
 	idx = offset / NETLBL_CATMAP_MAPSIZE;
-	iter->bitmap[idx] |= bitmap << (offset % NETLBL_CATMAP_MAPSIZE);
+	iter->bitmap[idx] |= (NETLBL_CATMAP_MAPTYPE)bitmap
+			     << (offset % NETLBL_CATMAP_MAPSIZE);
 
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] netlabel: fix shift wrapping bug in netlbl_catmap_setlong()
  2023-06-08 13:57 [PATCH] netlabel: fix shift wrapping bug in netlbl_catmap_setlong() Dmitry Mastykin
@ 2023-06-08 18:57 ` Paul Moore
  2023-06-10 19:02 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Moore @ 2023-06-08 18:57 UTC (permalink / raw)
  To: Dmitry Mastykin; +Cc: netdev, linux-security-module

On Thu, Jun 8, 2023 at 9:58 AM Dmitry Mastykin <dmastykin@astralinux.ru> wrote:
>
> There is a shift wrapping bug in this code on 32-bit architectures.
> NETLBL_CATMAP_MAPTYPE is u64, bitmap is unsigned long.
> Every second 32-bit word of catmap becomes corrupted.
>
> Signed-off-by: Dmitry Mastykin <dmastykin@astralinux.ru>
> ---
>  net/netlabel/netlabel_kapi.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Thanks Dmitry.

Acked-by: Paul Moore <paul@paul-moore.com>

> diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
> index 54c083003947..27511c90a26f 100644
> --- a/net/netlabel/netlabel_kapi.c
> +++ b/net/netlabel/netlabel_kapi.c
> @@ -857,7 +857,8 @@ int netlbl_catmap_setlong(struct netlbl_lsm_catmap **catmap,
>
>         offset -= iter->startbit;
>         idx = offset / NETLBL_CATMAP_MAPSIZE;
> -       iter->bitmap[idx] |= bitmap << (offset % NETLBL_CATMAP_MAPSIZE);
> +       iter->bitmap[idx] |= (NETLBL_CATMAP_MAPTYPE)bitmap
> +                            << (offset % NETLBL_CATMAP_MAPSIZE);
>
>         return 0;
>  }
> --
> 2.30.2

-- 
paul-moore.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] netlabel: fix shift wrapping bug in netlbl_catmap_setlong()
  2023-06-08 13:57 [PATCH] netlabel: fix shift wrapping bug in netlbl_catmap_setlong() Dmitry Mastykin
  2023-06-08 18:57 ` Paul Moore
@ 2023-06-10 19:02 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-10 19:02 UTC (permalink / raw)
  To: Dmitry Mastykin; +Cc: paul, netdev, linux-security-module

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Thu,  8 Jun 2023 16:57:54 +0300 you wrote:
> There is a shift wrapping bug in this code on 32-bit architectures.
> NETLBL_CATMAP_MAPTYPE is u64, bitmap is unsigned long.
> Every second 32-bit word of catmap becomes corrupted.
> 
> Signed-off-by: Dmitry Mastykin <dmastykin@astralinux.ru>
> ---
>  net/netlabel/netlabel_kapi.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Here is the summary with links:
  - netlabel: fix shift wrapping bug in netlbl_catmap_setlong()
    https://git.kernel.org/netdev/net/c/b403643d154d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-10 19:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08 13:57 [PATCH] netlabel: fix shift wrapping bug in netlbl_catmap_setlong() Dmitry Mastykin
2023-06-08 18:57 ` Paul Moore
2023-06-10 19:02 ` patchwork-bot+netdevbpf

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