Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp700278ybh; Tue, 10 Mar 2020 06:42:50 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvzQadoCosCU3OVyHvABfR9hJeXLZW22pVti9GFRamAsdaQ5BJlz/822wUtI1KbzcoFui7f X-Received: by 2002:a9d:3e89:: with SMTP id b9mr17255254otc.3.1583847770589; Tue, 10 Mar 2020 06:42:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583847770; cv=none; d=google.com; s=arc-20160816; b=xX+4X43tZV91dSCBH7cgt0SCA3+N7ope43589scX+If4Ntpu6Vm6TpyZV1d4OTUZ6h hpW6NNOrWZpa6gViGJI24vGZb4PfyeC5tY82oYBCsqpziCDu573GdNvlF+3R/1GRz5ZS CD43NGrPyP2eaG4r+B1CowEK33uK6jQL5BicrV0Vy7l8Nf+a3dYK2M94+06EHhujaspl ct4gvIk4D7nFZXlN9n4gLzyDj/wSWvySrRIUJ5uKDSYLJLuT/EPDMlRuMYAb/dVFZYje Hm0VNVXLxL/Mew+dde3G5pSOY7dysClKsYkfW0372mLYwYvVtjn7vhjLi/x7ztMiyAbY xTZw== 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=O0La1FFpm7RqanNKU8LkdzRnj13d6987AybgKViYRBs=; b=bQndHLSiXcg8ZfZyO48M5eSeb7rP67diBf6jCVD9WnXuKdGP8JPV6X1VuA0ryn8kOl PDLJCv5sfvah6sxXAoOB3rXSIqJiw3uxwyT49TAz4tSke6CL5oNicXvnoBOirs2V2U/Q dmRyIuNvmEVmyFESeJ5s9ZZUP/SOPHbv+kZsojg3dKUai2fGpunrHVIeu40Ckg+pwMtE XPaysjHcpTEJ7H+F/ABvx4UTD627E7NYbes+e3Q0CQ4GDyRkXLu/qdwrYFiTZ+wkQUXD hik1lvb3+QQZ4I2ka+5veMWtNf4ZxK6pIooAnWxgs4aiIQsvzdmqC0tvOd7uSUDpHXtD is5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GGEOo0Cu; 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 l14si7561341otn.157.2020.03.10.06.42.38; Tue, 10 Mar 2020 06:42:50 -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=GGEOo0Cu; 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 S1731110AbgCJNIZ (ORCPT + 99 others); Tue, 10 Mar 2020 09:08:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:54740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731105AbgCJNIX (ORCPT ); Tue, 10 Mar 2020 09:08:23 -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 5B339208E4; Tue, 10 Mar 2020 13:08:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583845701; bh=MssbFzVM8wHJST/MuhBvHAIOuQyMU4VQfLFQ9W1nvNI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GGEOo0CuLgu68ahC/8YqvVjCqBa7ZCwMAXMiWiuhGqH3iAQUQoxpTFtxbSady4zLC tABRKWAxXTilMyWawZXY3FVkU6VndLkRQcJQV2TaWhMdSp0vxP9E1cyykewpDdgk8a 1BZ7f6bX/bk1h6Lb1ZEZdIC3d0GDQxUDFHKYAAT4= 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.14 052/126] net: netlink: cap max groups which will be considered in netlink_bind() Date: Tue, 10 Mar 2020 13:41:13 +0100 Message-Id: <20200310124207.551126300@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310124203.704193207@linuxfoundation.org> References: <20200310124203.704193207@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 @@ -997,7 +997,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); @@ -1016,7 +1017,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); goto unlock; } }