Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5064290pxb; Mon, 15 Feb 2021 08:34:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJw60bL/lkc9iEhbEd8cDW6Gy2XcMB4wxhrhpyflsi1JUHLvxQIsjiN6WRtnecUBqwpSQDNo X-Received: by 2002:a50:aade:: with SMTP id r30mr16187897edc.15.1613406852390; Mon, 15 Feb 2021 08:34:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613406852; cv=none; d=google.com; s=arc-20160816; b=SSdBxP0dssRXDW5JHzds8VeY+KvpaHoGkFyh564E9mouNzhwo3uCY0nhAYT4EGJ0ou Ig6/WC9UQq29eCfSRZynxCfICeBRxbCc0TY1dlc9h+jfgJfflAgu+ayASTTYip8C4QIr zNNY8P/JZbuJ/hs0nWfRmZSP86ITi+Vr5uCWIz6MuBXk1kTJw2SZkJAYxfIi1Fel+twt n0f2vyYd8tZu61ZUnGV6rKnZcl0c1FNj5PXyFGC5OwG7T9TI5zkrDlrFUQi5XLcIlee1 mFWhRXkxKosaKbO3ikDlYBz2uMzAHftiuJGHSwUhqpXke/EFZD84mvMOboFTFytbp4if FWWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3QFcYbUi3UbnTAwsG/wAlzB1pi3PBDRHPmrHx4HbeVM=; b=BAM0ocbf9UVVfX7p4bLtH1UNOw2VUkhPfOWmVE8iQHfUD1JWnBzBDeSVqtKsFc4lLA op3uGxASKj8r9uX4EE8bDQNwevqi0HjbUMpH6s1E5nwxPHDpTHH2GOAib4p0mUIoSIBb xwt0ucNp7/l5mzu7pTpW0dcIKNRz5H5HXOI5ueRYnwNfAkhj+1kTgG9WiTftQge4+4mK /qX4ZT4UPFq4QP3IrVfQrQNtyyOVXXFcEmY7/j/nuKZD8GWwnQbzP65cPGzN0acO++ZC n06j5URAMXJST2W6/oiGp3qkgNjIlFR34cofF/HIup9x5kxOc/zLyPDWn8rXbkrJ39TQ 8twg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y0Cqf4dK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si4863956edh.345.2021.02.15.08.33.48; Mon, 15 Feb 2021 08:34:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y0Cqf4dK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232237AbhBOQdF (ORCPT + 99 others); Mon, 15 Feb 2021 11:33:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:50014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231394AbhBOPhe (ORCPT ); Mon, 15 Feb 2021 10:37:34 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 00A9964E2B; Mon, 15 Feb 2021 15:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403175; bh=EfpinbcHLPPvDJOkQagkohqGBIe9x5GA2yQAJgFeMq0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y0Cqf4dKN6Y9GTYJZsulAwnseYjlYNeBIgBt5RyRPgQ8OrH+eAd6XjDRcGlsi9D5k 7z/MQj4DM/gMdix4Oo1iU4Hhp7oIuML2Qm7nvOWbjKE2Q2FmwDwfg0WwbNN9kEHmb/ Rvzviamr5w3+yGbibqKS0J+MDdJb8GHJTdo7xQLk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bui Quang Minh , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.10 056/104] bpf: Check for integer overflow when using roundup_pow_of_two() Date: Mon, 15 Feb 2021 16:27:09 +0100 Message-Id: <20210215152721.291084523@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bui Quang Minh [ Upstream commit 6183f4d3a0a2ad230511987c6c362ca43ec0055f ] On 32-bit architecture, roundup_pow_of_two() can return 0 when the argument has upper most bit set due to resulting 1UL << 32. Add a check for this case. Fixes: d5a3b1f69186 ("bpf: introduce BPF_MAP_TYPE_STACK_TRACE") Signed-off-by: Bui Quang Minh Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20210127063653.3576-1-minhquangbui99@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/stackmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index 06065fa271241..6e83bf8c080db 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -116,6 +116,8 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr) /* hash table size must be power of 2 */ n_buckets = roundup_pow_of_two(attr->max_entries); + if (!n_buckets) + return ERR_PTR(-E2BIG); cost = n_buckets * sizeof(struct stack_map_bucket *) + sizeof(*smap); cost += n_buckets * (value_size + sizeof(struct stack_map_bucket)); -- 2.27.0