Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5032816pxb; Mon, 15 Feb 2021 07:50:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzp3iENVLOH3lpRXv5dNY2Y9XiJ4O38pLwOX4cSYWqoq1s9viL4/r55b99Xrl6CML39f8N7 X-Received: by 2002:a17:906:1f85:: with SMTP id t5mr16658629ejr.530.1613404233042; Mon, 15 Feb 2021 07:50:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613404233; cv=none; d=google.com; s=arc-20160816; b=vbQU0cyWn3dowfeCL1JvEueDuORbrfD1FuRSAdEmHv3DbuKcfRQgKmCStWOWIAVey6 sRle4Col/dC4upb4FSBVUedR2pq5g7Gc6oW5txW6XnGmqEsR5l4eyFEht8mY+vWt3+Eq m+MdcENiC8dw1K7pkNn3JmSD/0lWX6m4aSzpEGj5oUwO25bPBEKpyLBSIUd3J0MKWH5p 2wmGGAeH0yY1PCiDXxt1ga+aG+Gu6p4BhqwlyoNcRFOhQv9nNbSz3ZFjCsyd0527aybk A+4kwB1X/+laOmTiUPlGHvqEYkdZHjw7YPs3sGKXaIJBoXXl3xwVDJYnRLOaIb2+iCXh Zumw== 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=LPe8fWHWIrvB4nNEzskdxyGIMwC7iJQ+pMOpy/cWOBQ=; b=M4me8gwpk9mK7xkr4TwS1qJn7wJDF9S/9UrdrfoOZPR4rb+YQklEfNXPy0NP3zEIyT n6YSgxpU0LT1ZSAfbE0z7DWFAQrTAvlXA2nQnbFn9FFIoeR6jDU/sDNiWqxzSFfTP+ne Y83Y1ZC8FL3/xUC8Qe/cKVwSZ0xoGkOgund7BLOEZTw+Ud/E2PvaaPxsoOtkRMH98YL5 eXrxwKrBjsJn3aY/YGnEU5zUwzB7cSA3SYqiPM5q0wbOq4DBAyLiUPRsnRKOuXJ/fSaJ QwNF/qnliTvl6tTZFwaAzF1qSwW0AJCFfoeTkbAUxGINv+xfBy7XhpldRFk8RyNv5c70 g4Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ehr1V4Sr; 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 jv10si12475153ejc.625.2021.02.15.07.50.08; Mon, 15 Feb 2021 07:50:33 -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=ehr1V4Sr; 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 S231436AbhBOPrK (ORCPT + 99 others); Mon, 15 Feb 2021 10:47:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:46646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbhBOPbO (ORCPT ); Mon, 15 Feb 2021 10:31:14 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A081664E73; Mon, 15 Feb 2021 15:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613402941; bh=ThCW5h/ivFEqJnOLqJsAg6AO9Oe0MmGyUOz/J2rwNYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ehr1V4SrFXLfajT39GvjV/92v1RSHiAViyO6N24wEwMfxNo5mWntgfbhbcHfdD1db cQAQa4oCUo8gq2jiL7+mtefSuA139lmZiND3t1L6tw0JRJ1yRLz0Hsu3riuOAVvgJn IZnhstduzOMOM9/dAIVEPO9DAOINjrMSS/Ecldro= 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.4 28/60] bpf: Check for integer overflow when using roundup_pow_of_two() Date: Mon, 15 Feb 2021 16:27:16 +0100 Message-Id: <20210215152716.249107879@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@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 173e983619d77..fba2ade28fb3a 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -112,6 +112,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