From patchwork Mon Feb 12 11:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 199658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2362412dyd; Mon, 12 Feb 2024 03:16:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5R8DMj+2MW/l5kdk80mLhPhCLjEPEzFmbeUUwOhj92m4zohejASqTncdV/c10XJveEBpb X-Received: by 2002:a05:6102:3217:b0:46e:c865:6b4a with SMTP id r23-20020a056102321700b0046ec8656b4amr140806vsf.34.1707736593196; Mon, 12 Feb 2024 03:16:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707736593; cv=pass; d=google.com; s=arc-20160816; b=YgJEQse2VIKM6Es2ISSTgCxV1MnXnsKe3kPJrq3pyOpFYWtIJXQp9w55Q4GVJSnxrL 6fPz5Wf3RmOKVPP3TqABtyM4PTxp+//HZVwX8683sXxpfEjlAhePgtegCVfcYneqfvO4 v3lYl6/1MVmlvsyIQQKm6IYoD0tE/5xyPyj9evoLB/UZk5yx5LVH4nX4BMP1VJWnU4qj C9jjAAt5ZhxCabgOb+3g/UBnR9JmbxeTVz26z8OOHjM5bQvdojugH+wg3Apj6ikhMjES WieYDAKZjDWemE1IOSChKQbeBSiC3Ne4Y9e3d9Uf4yM6dvtKZPOQXNB+lFLl9qC7O8BY 38Kg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=CamwcnDtE7Zyewx1uYQjtN0DOfd5vYuD5XVgyaMVNbU=; fh=h2/aLiZuwJj7dF6FzMUx27zmqPMHPrZASxBjV82VsPE=; b=z9pmOAav1jMsWrKUUfdtYaQN2zlgoUSUffTXTAZ9AxhlqJhetKbW73Wq3qpu3TFA2U rtzLMa+dSTGC/Yu0zYFXJep3kRdi47n086dz3cxAEti/BSkmPf9sP/MxkWFoXHTRYuxA WrpdfjQzrOS/aMUfNGzPFfv/Zqqma00HUlOk4igl9ZANQFS3pqgyu0Pz1fvCsW1FvLpZ bCwJMmOWHxFDwE8qPW+H3//x3SyjhR8vM6TK5ApdqQk/2TN2k03nV+XIhZ0bEaGdm2N6 J8yZhqTPz5O84xPvANhbb921xgzf81hkcYQN5jLoPgfo5u5DifBvwEqp3WiAh+dbT1ea 32tg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Uat5jhPa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61404-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61404-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXTOfEKT8hGz/uaesJqzFEWEIUCOTNoPHHQG5ShjTO3aVl0TzUx/P/lMA7SxrBF9rl85hhjdgUABEgYbyhzrznkgsG75g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jf11-20020a0562142a4b00b00680b0f40fb4si130785qvb.206.2024.02.12.03.16.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 03:16:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61404-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Uat5jhPa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61404-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61404-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id F2D7B1C214D6 for ; Mon, 12 Feb 2024 11:16:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4A6638FBC; Mon, 12 Feb 2024 11:16:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Uat5jhPa" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DBB32556F for ; Mon, 12 Feb 2024 11:16:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707736576; cv=none; b=p0Apve79Gf8mB1aCW17SXhark6KLLzPyxn4aeVjVqm488oqczcVWGVIdH3kjYxokGpJSzd2WZ0ljpPGRqbQiMNF2AvF2Pqd/j/WPng7RtpPe9ffe9zVzzUaaEKTJq3lSPSoV7mxEex5f+A9ZvrxALQ1tXvT4gLT7f2G+DmnALDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707736576; c=relaxed/simple; bh=JUd8RDIFqXlGYjM49KPBEs03On+rhHeulIrFh10Rab4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=h7dNovvZrxKrkY4LfLMiC6m0/GPPRhcz52aNGWiHREA8Lp4DwXih5ahAliP97MKopgsW0LTQZSbO8KXM2Y2nzoleZmQTHunSUqXkikDedB0fOr90PhrRgbJZRfVf3hkoBRcr3X5w17J1cRmvX3yEhgxLCLqs4RR+pp32eTVzZlM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uat5jhPa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C9ADC433C7; Mon, 12 Feb 2024 11:16:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707736575; bh=JUd8RDIFqXlGYjM49KPBEs03On+rhHeulIrFh10Rab4=; h=From:To:Cc:Subject:Date:From; b=Uat5jhPaeUUrwYrIKBEryRRlqkfa88iUDMr1PYuLdACxfXQO34FSlFzP6SGV6PrcZ 7a/AFWdH+Ju2C+eaaCmn0hr+PZJEuhvMLKROYfBm9XNRwiSaamy3ipGQIvYLsKJq9h 0p0x7RVrs0oSUxsFjhLK2w1QJpnxXtuAIJ2v2ohf5bsPZEjm3JGf74tKmM2hYw2nWK dqSfxfqxt4ib7Bfaq20e1Wq109Yulw3EiCvIVmu0DlO8dsclSnIaj2Ow4YZp8bD1mj MZnFPGGhFcESTW92kZHzVutBN7H1xc+hRozLgyh+1SopSAHK2Fj6KHpSUDeLTtCpQg 4rwbDbFGf3L6g== From: Arnd Bergmann To: Andrey Ryabinin , Andrew Morton , Andrey Konovalov Cc: Arnd Bergmann , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Marco Elver , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] kasan/test: avoid gcc warning for intentional overflow Date: Mon, 12 Feb 2024 12:15:52 +0100 Message-Id: <20240212111609.869266-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790691605817953077 X-GMAIL-MSGID: 1790691605817953077 From: Arnd Bergmann The out-of-bounds test allocates an object that is three bytes too short in order to validate the bounds checking. Starting with gcc-14, this causes a compile-time warning as gcc has grown smart enough to understand the sizeof() logic: mm/kasan/kasan_test.c: In function 'kmalloc_oob_16': mm/kasan/kasan_test.c:443:14: error: allocation of insufficient size '13' for type 'struct ' with size '16' [-Werror=alloc-size] 443 | ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL); | ^ Hide the actual computation behind a RELOC_HIDE() that ensures the compiler misses the intentional bug. Fixes: 3f15801cdc23 ("lib: add kasan test module") Signed-off-by: Arnd Bergmann Reviewed-by: Andrey Konovalov --- mm/kasan/kasan_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 318d9cec111a..2d8ae4fbe63b 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -440,7 +440,8 @@ static void kmalloc_oob_16(struct kunit *test) /* This test is specifically crafted for the generic mode. */ KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_GENERIC); - ptr1 = kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL); + /* RELOC_HIDE to prevent gcc from warning about short alloc */ + ptr1 = RELOC_HIDE(kmalloc(sizeof(*ptr1) - 3, GFP_KERNEL), 0); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr1); ptr2 = kmalloc(sizeof(*ptr2), GFP_KERNEL);