Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp698693ybh; Tue, 10 Mar 2020 06:41:16 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuqvVlGHn7VfYT4tK314EIMef6RguvbrFFKhhjLPkTISJcNJFSswVxKVPKzrpPUV3nB70yI X-Received: by 2002:a54:4501:: with SMTP id l1mr1188441oil.33.1583847676845; Tue, 10 Mar 2020 06:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583847676; cv=none; d=google.com; s=arc-20160816; b=AB34vQtWc4pRDiCMF6VNI4+xfRnN/7MYcQ0oTH+R6DdNild1pzhZU+kq/tjYSgu0a+ sT+pZGJ5pZ0IObiNpDXg6g5qQKRZ8p/3y59ZCRE1OlZz24/Ab8sh22sE37284maepaIs 08xy7Qjbg3CIkGx5zE2ZZc3nnUDcjzctoP9bH2ez3iSKo9aPgv4hkHjfDvu5u3PsIcqi B7bsvn9TJ2MSTkjZqS4hL5HIF4yJ0mlgG4CbmdJtu4bCIaPGz8NRYnYRsEJikTe2wgIl PpXeEeqwxUEco2ZVMVgOKpfvCctxNNlluGKQH4s89URtGrPyxL+Ag9H336n8C8Mcj4eH 4/bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FqEN646HRfBNHsYu4R4UeN8mB4PkYBm4OwWdb10prvE=; b=EjvzUZayKAGnnQznNPgmVLS1CR9pjcryl7h2BwAwdDbSQXzG/GrnllEO8aSCaCKUQj b62eVtKSz8hRX1Rtas6Zcuu7DXfn8h7kk8iQYAoOP5rBfeQy2CPJkgJmGtaGtZRtzlMv 6Z/F6y1R76NbtCIa8/1InxTGlGlTPROmkUXByMsmNPiZzXhnXcH6ZM28702pe8bJiI8n IfJN2pXeyCNjhtxGR7yux/0bapGEzIvFQbLd3iMbmmC9lptjRlFeK4XQOmlPPhvr+m+n UIGLOchDVfS58RldK/3MKtYUeuoWit1p8SHPVHA2kpf/jvIJdruM1DWXZAAvLJXayIMr vQVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wBwn9OFP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o18si7707297otk.80.2020.03.10.06.41.03; Tue, 10 Mar 2020 06:41:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wBwn9OFP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbgCJMld (ORCPT + 99 others); Tue, 10 Mar 2020 08:41:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:41112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726977AbgCJMlc (ORCPT ); Tue, 10 Mar 2020 08:41:32 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 12CEF24691; Tue, 10 Mar 2020 12:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583844091; bh=lH07DyGfCpn7Umrw/EPCa6h0VuEhaCMiaDb8h6et0cI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wBwn9OFPyBs6B9hZQNcxyKvYkihzXqFAObiGESqF3o1/57u6A94hk4sLVMLnEPCdG Q3wT4fs9bAcwsSCK2csb+fuJU7r4JvsWsOAHgDY7OTDY6cLBd3YNPFBwnZLoNaAC9u VL2MMoMNcCv/DeV55p5sSL2DOYkc/CDA5kGOq1fo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christophe Leroy , Richard Guy Briggs , "Erhard F." , Nikolay Aleksandrov , "David S. Miller" Subject: [PATCH 4.4 28/72] net: netlink: cap max groups which will be considered in netlink_bind() Date: Tue, 10 Mar 2020 13:38:41 +0100 Message-Id: <20200310123608.604232620@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310123601.053680753@linuxfoundation.org> References: <20200310123601.053680753@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nikolay Aleksandrov commit 3a20773beeeeadec41477a5ba872175b778ff752 upstream. Since nl_groups is a u32 we can't bind more groups via ->bind (netlink_bind) call, but netlink has supported more groups via setsockopt() for a long time and thus nlk->ngroups could be over 32. Recently I added support for per-vlan notifications and increased the groups to 33 for NETLINK_ROUTE which exposed an old bug in the netlink_bind() code causing out-of-bounds access on archs where unsigned long is 32 bits via test_bit() on a local variable. Fix this by capping the maximum groups in netlink_bind() to BITS_PER_TYPE(u32), effectively capping them at 32 which is the minimum of allocated groups and the maximum groups which can be bound via netlink_bind(). CC: Christophe Leroy CC: Richard Guy Briggs Fixes: 4f520900522f ("netlink: have netlink per-protocol bind function return an error code.") Reported-by: Erhard F. Signed-off-by: Nikolay Aleksandrov Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/netlink/af_netlink.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -1003,7 +1003,8 @@ static int netlink_bind(struct socket *s if (nlk->netlink_bind && groups) { int group; - for (group = 0; group < nlk->ngroups; group++) { + /* nl_groups is a u32, so cap the maximum groups we can bind */ + for (group = 0; group < BITS_PER_TYPE(u32); group++) { if (!test_bit(group, &groups)) continue; err = nlk->netlink_bind(net, group + 1); @@ -1022,7 +1023,7 @@ static int netlink_bind(struct socket *s netlink_insert(sk, nladdr->nl_pid) : netlink_autobind(sock); if (err) { - netlink_undo_bind(nlk->ngroups, groups, sk); + netlink_undo_bind(BITS_PER_TYPE(u32), groups, sk); return err; } }