From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2310FC433E0 for ; Tue, 26 Jan 2021 11:28:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D426C207D0 for ; Tue, 26 Jan 2021 11:28:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392381AbhAZL16 (ORCPT ); Tue, 26 Jan 2021 06:27:58 -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-Google-Smtp-Source: ABdhPJyCGPCvmzSWUJppoFAjsEUtCf8KWSJC0FJrI/QII7dvxqZrr5XBPR4F3kafupLvwui/f8oqxjIf8OmPtbBhies= 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