Skip to content

Commit 91874ec

Browse files
0x7f454c46davem330
authored andcommitted
netlink: Don't shift on 64 for ngroups
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]>
1 parent 5dbfb6e commit 91874ec

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
@@ -1013,8 +1013,8 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
10131013

10141014
if (nlk->ngroups == 0)
10151015
groups = 0;
1016-
else
1017-
groups &= (1ULL << nlk->ngroups) - 1;
1016+
else if (nlk->ngroups < 8*sizeof(groups))
1017+
groups &= (1UL << nlk->ngroups) - 1;
10181018

10191019
bound = nlk->bound;
10201020
if (bound) {

0 commit comments

Comments
 (0)