Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp2877544rwb; Sat, 6 Aug 2022 07:53:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR6dkFvID4qKooAkIdw6WDpj054LEw3MamDaXVVzlzO8tWB8lW7SQcV6ttbgiR6uCIA0m/Wq X-Received: by 2002:a05:6402:240a:b0:437:d2b6:3dde with SMTP id t10-20020a056402240a00b00437d2b63ddemr10937851eda.62.1659797610010; Sat, 06 Aug 2022 07:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659797610; cv=none; d=google.com; s=arc-20160816; b=Qw3CCED02S1qMBcbfZEEDqaQY8HFkCXm7ELVeTL1m7AYYHczhltM/hodhYP4p+sRjD iICGzI4s7VSbqsABSDOUXSE05IVGNW0/CfEw541KbpYghTGR7tmCbLrHArdeipTlufxM 8myhJWw61wINuHPKEWPas3Ma41Ld+6jom9EaRc38H8DU9OTbM29+KJJSfZ3Fwnyg3u4Q ++enoExEnzVtwa+YKlRaSbrltSpWopWFPF/vLXa8C6nj/gPjFir7COGN6M+7zGwH+Xr2 JcKZdknjpRAY0A+kwE/RVl3h1FmxS4pbQCDOUBTGQiOE5SE4VAdfXdT7n9xumpqE8XkV geiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=io15jxipwkxp8dnmKQw0UQoEYG0T27HzvS5H04/lWlA=; b=eIHQQdTG5jDEDnDxFFZTYq+ubFrk//fyB41Df1u8R7arQ1f/zq9A1lMNXE4HJ5H5y0 tas8Exs9r91kwRGIry7IAT91WuGWGI1D041pFraTlMP7zxva3jLgf+8wUp5Vt0rUXMYu gLVDDBTXVmRfeyVvh3rxnk5TKNQs0AqQiDAwXUe4kqFnaDw0/cKedQkxG1yAff9lMuzi gMTQpX5eva8xsGDg8pVXXtYt0jjR4kU8XO266bFwdoBnfuuW9TwjArTXiHu7zLuOJPfZ qTA4Xose+xmQtAqMaPiZU8MNfZvcx5vG2PBXl+bPzUI/Ky66g6fADFxektbCECEeFPU4 2/dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=h+R+2Yg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx26-20020a05640222ba00b0043e16a07ebasi1955967edb.70.2022.08.06.07.52.53; Sat, 06 Aug 2022 07:53:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=h+R+2Yg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231468AbiHFOcT (ORCPT + 99 others); Sat, 6 Aug 2022 10:32:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbiHFOcS (ORCPT ); Sat, 6 Aug 2022 10:32:18 -0400 Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6BFCDF43; Sat, 6 Aug 2022 07:32:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=io15jxipwkxp8dnmKQ w0UQoEYG0T27HzvS5H04/lWlA=; b=h+R+2Yg4qw9b3KWTETWmceCkMhBzCnoN9F cGCKHNvFMLsZOTPF7Etoxo86gHbFWEEHSN6tFhybBWBsCswzqjS5QvpIN2DLTFtZ RI86nWWRDsN1gHndU8wqXFfo8N3HdDYvaSUb4Q/5947Rg3rvewmgt6Y9e63zNexP 4Wsd/QoDE= Received: from user-virtual-machine.localdomain (unknown [124.133.191.247]) by smtp4 (Coremail) with SMTP id HNxpCgDXZ94be+5icYDGTQ--.25852S4; Sat, 06 Aug 2022 22:31:19 +0800 (CST) From: Jialiang Wang To: simon.horman@corigine.com, kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, niejianglei2021@163.com, wangjialiang0806@163.com Cc: oss-drivers@corigine.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] nfp: fix use-after-free in area_cache_get() Date: Sat, 6 Aug 2022 22:30:43 +0800 Message-Id: <20220806143043.106787-1-wangjialiang0806@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: HNxpCgDXZ94be+5icYDGTQ--.25852S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7uw1Utw1kKryrGr1fWF4rZrb_yoW8Ar1UpF WrJ3yFkr48XrsrXw4DJayxX34rCa9xtFyrW345Cw4rua4avr13JF1xKr45ZF4DurW8Jayx AFyjqa4fGrs8J3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jwDGrUUUUU= X-Originating-IP: [124.133.191.247] X-CM-SenderInfo: pzdqwy5ldoxtdqjqmiqw6rljoofrz/1tbivxdVzlWB0wjmhAAAse X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org area_cache_get() calls cpp->op->area_init() and uses cache->area by nfp_cpp_area_priv(area), but in nfp_cpp_area_release()->nfp_cpp_area_put()->__release_cpp_area() we already freed the cache->area. To avoid the use-after-free, reallocate a piece of memory for the cache->area by nfp_cpp_area_alloc(). Note: This vulnerability is triggerable by providing emulated device equipped with specified configuration. BUG: KASAN: use-after-free in nfp6000_area_init+0x74/0x1d0 [nfp] Write of size 4 at addr ffff888005b490a0 by task insmod/226 Call Trace: dump_stack_lvl+0x33/0x46 print_report.cold.12+0xb2/0x6b7 ? nfp6000_area_init+0x74/0x1d0 [nfp] kasan_report+0xa5/0x120 ? nfp6000_area_init+0x74/0x1d0 [nfp] nfp6000_area_init+0x74/0x1d0 [nfp] area_cache_get.constprop.8+0x2da/0x360 [nfp] Signed-off-by: Jialiang Wang --- drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c index 34c0d2ddf9ef..99091f24d2ba 100644 --- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c +++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.c @@ -871,6 +871,10 @@ area_cache_get(struct nfp_cpp *cpp, u32 id, nfp_cpp_area_release(cache->area); cache->id = 0; cache->addr = 0; + cache->area = nfp_cpp_area_alloc(cpp, + NFP_CPP_ID(7, + NFP_CPP_ACTION_RW, 0), + 0, cache->size); } /* Adjust the start address to be cache size aligned */ -- 2.17.1