Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3619315pxb; Sun, 24 Oct 2021 06:55:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYcBpiXWnKe/dFZQ6aJejKcCO9i4FnAAnotIM7X+YVmP2YjMV3dp5/wgeePzyqkjSITW/W X-Received: by 2002:a63:dc42:: with SMTP id f2mr9168487pgj.152.1635083726723; Sun, 24 Oct 2021 06:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635083726; cv=none; d=google.com; s=arc-20160816; b=RxHoy4vfBcpBybzE8hGVYLj8Qh7sg8cZcK3SDBIDSyTF9/VdJXB+XBkhpckFw2L4nu eFpYKdk617/pCbYGV5OVGGXVWEAlL5HTK7TMjxZtC9w2HYiE4Sw8tpGF7wxF8f7OOrB8 3/Yxh6FTFVmAxjLL90QaNE72Wauu/iskwl2cqhAN34MZTR35RAWMb3AKRPGdbcmoDwQ7 gGm3AgvLwH8REFT9uLFwDEO0PAfC0Pqdl95/jhRXSshk0cBvl1jf5XNGuuuGkxnG5X/W WG8Dz1I0jKWiiwIDfvofWmEbUsJbKTUgJD97SSsMkdkLl5tbaLWp7bdhg58hPwK3NDD6 11Kg== 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=id1p4qGVhAju1dNKS9ewXd/BAGNoNoVxYAeg/MMzZkk=; b=mKK6GGDGn0a9GjccTWW/4odbwE6iHp0gzjJfx6g+bGrGgme0aoSeR1B7SEs1vn7HnR QhqihrsYJ4h+HN1CrfJUYF5E2X9TAf5IjowrK/ydURaXNqNAnKttRfAL1EuwwZ11bGPT js4WTnLs8ea7qpF4fYJFm08BL18xjxC4/rNQwdkrvYAayrQr2DdCD3QS3/hsKRy96PmG pAnvz15ouJjX2/fJ2sZffkv/cmoaayRlomIX6OtZK36o/rc8/wRj0G+f6rKn/ygRtFB3 aqDvc+aPow/Xi2uRcrkFtEB10VFzhlrPH0b2KTNY/mND0lw16WCJVrOxTu2/YUHji0Mr /H3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="S7J2ND/k"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si20900443pgv.167.2021.10.24.06.55.03; Sun, 24 Oct 2021 06:55:26 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b="S7J2ND/k"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231454AbhJXNyf (ORCPT + 99 others); Sun, 24 Oct 2021 09:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbhJXNye (ORCPT ); Sun, 24 Oct 2021 09:54:34 -0400 Received: from mail-vk1-xa35.google.com (mail-vk1-xa35.google.com [IPv6:2607:f8b0:4864:20::a35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 735FFC061764 for ; Sun, 24 Oct 2021 06:52:13 -0700 (PDT) Received: by mail-vk1-xa35.google.com with SMTP id o42so3868239vkf.9 for ; Sun, 24 Oct 2021 06:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=id1p4qGVhAju1dNKS9ewXd/BAGNoNoVxYAeg/MMzZkk=; b=S7J2ND/kmDgFgy4AH1WOhj0CUNoHlN2y+ArUyM1B26rKOQ8Ax8jXgz8ou6NJqRrH5X VQcJJIZ1OJBzSD7cW03ffYhT5wnSiG02IY8lj3QReK9OmkiIgUcVqfnRMlAwAGw5V7xy Sfp0M9wvNWJnH6aO1HhKwXg8uIpani44NbMRtNLbxZBf95TyIpc9Kd1dcYUWJ37R+/jQ 7Pm3jQc8CodMCVtUMzgbHxXuEqZh3sgOAlDJNgoSvK/D+wRx4yM1viMwDxHPj6+Jtk8S jEyOe6gFlDpwZ9HrUsiaW2etn7WeNTRQwET3c5kzxi7uaAhWGwYTVIGtFwur6YjO25/6 0K7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=id1p4qGVhAju1dNKS9ewXd/BAGNoNoVxYAeg/MMzZkk=; b=mTpGopt+8UW+lYqwMVwmWMFa4QrI7UlK69cPHvYyHbAZ3kvE2awYywfNFRAQMHRUkZ 0Tgzq24ygkITB9EDy0s2ZYKA9RHPVtBP1CS7T1M4g2yxKzZk5i+u4qpNkf/vRY0xNuxY Fi2FVnQ2nLMAFexqq+lRfCvKRjSIZPIT/Tj18xR7jiLxeys/iuYq+nejwerilv46I4kW KZrYCS4CiOLD9beFaMaJsPLa8h95wpzHvwuOC+HktWEL2EJwT/tRfHuqz0NCxLnI4Swg 9GUk4gDCTDRts7XjZQztDQibVGpJjd3uG5mqCZYO3Ddt4jke124HI5ptUITLUKgE6N7p aqIg== X-Gm-Message-State: AOAM532iOQrYC+W3cb+UHIJeDn/IV7/KXScYsSQAI1IVmscJAlNsg00b Mqr3heAPMcabtFb18uGSugdSqCFzWXA= X-Received: by 2002:a05:6122:2029:: with SMTP id l41mr10703566vkd.10.1635083532605; Sun, 24 Oct 2021 06:52:12 -0700 (PDT) Received: from mail-ua1-f49.google.com (mail-ua1-f49.google.com. [209.85.222.49]) by smtp.gmail.com with ESMTPSA id 10sm7880219vkl.55.2021.10.24.06.52.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 24 Oct 2021 06:52:12 -0700 (PDT) Received: by mail-ua1-f49.google.com with SMTP id e2so16883988uax.7 for ; Sun, 24 Oct 2021 06:52:12 -0700 (PDT) X-Received: by 2002:a67:e0d1:: with SMTP id m17mr10843041vsl.22.1635083531874; Sun, 24 Oct 2021 06:52:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Willem de Bruijn Date: Sun, 24 Oct 2021 09:51:35 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] gve: Fix a possible invalid memory access To: Christophe JAILLET Cc: jeroendb@google.com, csully@google.com, awogbemila@google.com, davem@davemloft.net, kuba@kernel.org, bcf@google.com, gustavoars@kernel.org, edumazet@google.com, jfraker@google.com, yangchun@google.com, xliutaox@google.com, sagis@google.com, lrizzo@google.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 24, 2021 at 7:52 AM Christophe JAILLET wrote: > > It is spurious to allocate a bitmap for 'num_qpls' bits and record the > size of this bitmap with another value. > > 'qpl_map_size' is used in 'drivers/net/ethernet/google/gve/gve.h' with > 'find_[first|next]_zero_bit()'. > So, it looks that memory after the allocated 'qpl_id_map' could be > scanned. find_first_zero_bit takes a length argument in bits: /** * find_first_zero_bit - find the first cleared bit in a memory region * @addr: The address to start the search at * @size: The maximum number of bits to search qpl_map_size is passed to find_first_zero_bit. It does seem roundabout to compute first the number of longs needed to hold num_qpl bits BITS_TO_LONGS(num_qpls) then again compute the number of bits in this buffer * sizeof(unsigned long) * BITS_PER_BYTE Which will simply be num_qpls again. But, removing BITS_PER_BYTE does not arrive at the right number. > > Remove the '* BITS_PER_BYTE' to have allocation and length be the same. > > Fixes: f5cedc84a30d ("gve: Add transmit and receive support") > Signed-off-by: Christophe JAILLET > --- > This patch is completely speculative and un-tested! > You'll be warned. > --- > drivers/net/ethernet/google/gve/gve_main.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c > index 7647cd05b1d2..19fe9e9b62f5 100644 > --- a/drivers/net/ethernet/google/gve/gve_main.c > +++ b/drivers/net/ethernet/google/gve/gve_main.c > @@ -866,7 +866,7 @@ static int gve_alloc_qpls(struct gve_priv *priv) > } > > priv->qpl_cfg.qpl_map_size = BITS_TO_LONGS(num_qpls) * > - sizeof(unsigned long) * BITS_PER_BYTE; > + sizeof(unsigned long); > priv->qpl_cfg.qpl_id_map = kvcalloc(BITS_TO_LONGS(num_qpls), > sizeof(unsigned long), GFP_KERNEL); > if (!priv->qpl_cfg.qpl_id_map) { > -- > 2.30.2 >