From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitry Safonov Subject: [PATCH] netlink: Don't shift on 64 for ngroups Date: Sun, 5 Aug 2018 00:55:44 +0100 Message-ID: <20180804235544.10347-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-f66.google.com ([209.85.208.66]:39540 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729669AbeHEB6M (ORCPT ); Sat, 4 Aug 2018 21:58:12 -0400 Received: by mail-ed1-f66.google.com with SMTP id h4-v6so3442167edi.6 for ; Sat, 04 Aug 2018 16:55:47 -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 --- 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..e44edadfad20 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 < sizeof(long unsigned int)) + groups &= (1UL << nlk->ngroups) - 1; bound = nlk->bound; if (bound) { -- 2.13.6