From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitry Safonov Subject: [PATCHv2] netlink: Don't shift on 64 for ngroups Date: Sun, 5 Aug 2018 01:35:53 +0100 Message-ID: <20180805003553.11104-1-dima@arista.com> Cc: Dmitry Safonov , Nathan Chancellor , "David S. Miller" , Herbert Xu , Steffen Klassert , netdev@vger.kernel.org, stable@vger.kernel.org To: linux-kernel@vger.kernel.org Return-path: Received: from mail-ed1-f67.google.com ([209.85.208.67]:38161 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbeHECia (ORCPT ); Sat, 4 Aug 2018 22:38:30 -0400 Received: by mail-ed1-f67.google.com with SMTP id t2-v6so3453988edr.5 for ; Sat, 04 Aug 2018 17:35:57 -0700 (PDT) Sender: netdev-owner@vger.kernel.org List-ID: 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: 61f4b23769f0 ("netlink: Don't shift with UB on nlk->ngroups") Cc: "David S. Miller" Cc: Herbert Xu Cc: Steffen Klassert Cc: netdev@vger.kernel.org Cc: stable@vger.kernel.org Reported-and-Tested-by: Nathan Chancellor Signed-off-by: Dmitry Safonov --- v2: sizeof() is in bytes net/netlink/af_netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 7d860a22e5fb..d6ff4d409437 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -1011,8 +1011,8 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr, if (nlk->ngroups == 0) groups = 0; - else - groups &= (1ULL << nlk->ngroups) - 1; + else if (nlk->ngroups < 8*sizeof(groups)) + groups &= (1UL << nlk->ngroups) - 1; bound = nlk->bound; if (bound) { -- 2.13.6