diff mbox series

netlabel: fix shift wrapping bug in netlbl_catmap_setlong()

Message ID 20230608135754.25044-1-dmastykin@astralinux.ru (mailing list archive)
State Accepted
Delegated to: Paul Moore
Headers show
Series netlabel: fix shift wrapping bug in netlbl_catmap_setlong() | expand

Commit Message

Dmitry Mastykin June 8, 2023, 1:57 p.m. UTC
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(-)

Comments

Paul Moore June 8, 2023, 6:57 p.m. UTC | #1
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
patchwork-bot+netdevbpf@kernel.org June 10, 2023, 7:02 p.m. UTC | #2
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!
diff mbox series

Patch

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