Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3735230pxb; Tue, 26 Jan 2021 03:29:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyrbLbDS7DB174Sx/6D9rj3KqtI5LvkIIAf4u54ILk1gvOd4qXAA4e2Mx74/Rtj+pWpOm0m X-Received: by 2002:a05:6402:402:: with SMTP id q2mr4271541edv.116.1611660557096; Tue, 26 Jan 2021 03:29:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611660557; cv=none; d=google.com; s=arc-20160816; b=IbP9W/3M/3SExgjX7ChKZep+JKIsjeYUcEXHHd+OilHK+u8AdCgk3RLgIdEB5z3Pr1 1cMTZLrI8Uqa59GcUVSmHFiyh0kCy/d/Fyq4SgvJ/S2CBi8hUnHSPJIMDAGv/VLVu8Aw WsMeZs36C6xHNI3VY8OnSiCKCyh4bH+3a3taHuGKklklB5nKLmUXvT/uPUa5H+V71wVK 93YMoh7aJlNQO5/NSjtXVjhe480/AFwz88J9j8gNIZiYZbgz6ihIAyvU4YYAVVFCHkPr yUwo+C5bBmIKQaMw10o+dDTBDvYrJcwRDChuaVTrZ2dj8VlAuDVuxnj+mqAzJv7N5awI ObKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fc97bl9y/fOUWfcqC9Hh9udHha7efiEnc5d5nu4VkAU=; b=HqRT+XFxTE/ge2UYynQIySzWT1bJuKt9rGYlxmbqdgS2Llyth6fEnvsIHmS1+Spa4Z 5HAxWLOLsgl+023Z+ochTlPVoiKbuIAvD6lMS8Dll+GDGbcScGtyriXQXhByU/SDOpcP txLm+Jzn3pL4lfQvMqlInwaJPSOJ5//Upmb5kc0HXLQKLKUYl4/q8F/lQ7Z0DUwsM/Tt 1AkKstuetPdq/0pyZQ4o96CVlJHItQvy3prjIG6c9BX7aAtE+dYHVyAgzN/QmwxE7jwz iVV9pGqmdT88J8THCY5hhhHY29yctMR4q5u4/negl5cdA+uBsPpRs3NLnLErpvvtDEAF y3YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=vd1XuR3g; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay26si7489727edb.317.2021.01.26.03.28.52; Tue, 26 Jan 2021 03:29:17 -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=@cloudflare.com header.s=google header.b=vd1XuR3g; 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=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392484AbhAZL1m (ORCPT + 99 others); Tue, 26 Jan 2021 06:27:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391195AbhAZJhz (ORCPT ); Tue, 26 Jan 2021 04:37:55 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 114BDC0613D6 for ; Tue, 26 Jan 2021 01:37:10 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id f1so12039280lfu.3 for ; Tue, 26 Jan 2021 01:37:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=fc97bl9y/fOUWfcqC9Hh9udHha7efiEnc5d5nu4VkAU=; b=vd1XuR3gcGy119h75Y1qjivJKBqfMQoxlVfdaFE8OOJ2A7JYfLrSDiKeDDulAHSNrA MclXbRVXfHjAiw06826JQERooCqRYe5tGUyUBFnRcU+r4Fnp+nw+ZgwBLpDl9dzSETIN bHIKEFQ9jPwYKMb17EdGRflrasDgMbTkVP248= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=fc97bl9y/fOUWfcqC9Hh9udHha7efiEnc5d5nu4VkAU=; b=szHHtDJ/CUqiGAKXKEJsVKgOqGMklsMdk3TWfcf7fC/LTvdhpqaijaKs3xpKMpCXuP EMxgxt0dDhISEbXVcjfaYnXGHeQ5F6Gme9rAAj0LQmAnBe7sAML/fs0ErSPo4LhK3U8Y UTZGJgMaOYDYgY3SnaEJqsljMQ3fyw3ltK0GQqnHxoB2lo8GLY9BgFWtMn4Fojtb0Zxn 0phc17yHsOFLPSWglytgq8fmARodW5jQc3RanUZPdbinvNpt+QMLsnLCcU2grVDS5Qv1 j5YIW2y+0fBIuFlt8rjPQzK8F6QwiY9UX9LlI95quEjmJoc7CpCgzsxp8VMsN1VeUSzT F8Pg== X-Gm-Message-State: AOAM533/UH93epLtKwPmuGJynWq1V7BahLkK5t2YqH56C38J8irRBoMP BqgKy7uNWvkjzjxNxulfagBZeAQRl/Fh14STXUDoqw== X-Received: by 2002:a19:c56:: with SMTP id 83mr2467065lfm.325.1611653828443; Tue, 26 Jan 2021 01:37:08 -0800 (PST) MIME-Version: 1.0 References: <20210126082606.3183-1-minhquangbui99@gmail.com> In-Reply-To: <20210126082606.3183-1-minhquangbui99@gmail.com> From: Lorenz Bauer Date: Tue, 26 Jan 2021 09:36:57 +0000 Message-ID: Subject: Re: [PATCH] bpf: Fix integer overflow in argument calculation for bpf_map_area_alloc To: Bui Quang Minh Cc: Alexei Starovoitov , Daniel Borkmann , "David S . Miller" , Jakub Kicinski , hawk@kernel.org, John Fastabend , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , kpsingh@kernel.org, Jakub Sitnicki , Networking , bpf , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 Jan 2021 at 08:26, Bui Quang Minh wrote: > > In 32-bit architecture, the result of sizeof() is a 32-bit integer so > the expression becomes the multiplication between 2 32-bit integer which > can potentially leads to integer overflow. As a result, > bpf_map_area_alloc() allocates less memory than needed. > > Fix this by casting 1 operand to u64. Some quick thoughts: * Should this have a Fixes tag? * Seems like there are quite a few similar calls scattered around (cpumap, etc.). Did you audit these as well? * I'd prefer a calloc style version of bpf_map_area_alloc although that might conflict with Fixes tag. Lorenz -- Lorenz Bauer | Systems Engineer 6th Floor, County Hall/The Riverside Building, SE1 7PB, UK www.cloudflare.com