Skip to content

Commit 09901e5

Browse files
0x7f454c46gregkh
authored andcommitted
netlink: Don't shift on 64 for ngroups
commit 91874ec upstream. It's legal to have 64 groups for netlink_sock. As user-supplied nladdr->nl_groups is __u32, it's possible to subscribe only to first 32 groups. The check for correctness of .bind() userspace supplied parameter is done by applying mask made from ngroups shift. Which broke Android as they have 64 groups and the shift for mask resulted in an overflow. Fixes: 61f4b23 ("netlink: Don't shift with UB on nlk->ngroups") Cc: "David S. Miller" <[email protected]> Cc: Herbert Xu <[email protected]> Cc: Steffen Klassert <[email protected]> Cc: [email protected] Cc: [email protected] Reported-and-Tested-by: Nathan Chancellor <[email protected]> Signed-off-by: Dmitry Safonov <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2d89891 commit 09901e5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/netlink/af_netlink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,8 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
981981

982982
if (nlk->ngroups == 0)
983983
groups = 0;
984-
else
985-
groups &= (1ULL << nlk->ngroups) - 1;
984+
else if (nlk->ngroups < 8*sizeof(groups))
985+
groups &= (1UL << nlk->ngroups) - 1;
986986

987987
bound = nlk->bound;
988988
if (bound) {

0 commit comments

Comments
 (0)