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: 13552955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFE9DC48297 for ; Mon, 12 Feb 2024 11:16:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EC816B0075; Mon, 12 Feb 2024 06:16:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 572EA6B0078; Mon, 12 Feb 2024 06:16:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43AE56B007B; Mon, 12 Feb 2024 06:16:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 2FD846B0075 for ; Mon, 12 Feb 2024 06:16:22 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 00BDC1C129F for ; Mon, 12 Feb 2024 11:16:21 +0000 (UTC) X-FDA: 81782898162.28.E59B6AB Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf10.hostedemail.com (Postfix) with ESMTP id 01C37C0019 for ; Mon, 12 Feb 2024 11:16:19 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Uat5jhPa; spf=pass (imf10.hostedemail.com: domain of arnd@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=arnd@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707736580; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=CamwcnDtE7Zyewx1uYQjtN0DOfd5vYuD5XVgyaMVNbU=; b=d8/SgiLS9DofpZoFugqSQKK+emah8Y9bg65m1CuEILQ6IoJ9ickP7tAZb7miVecIWGt7U6 KSze5vkAm3ebuYlLlhN0emBLkoqbS7Kw2UX3zaJxK/xzMfce3wnfK8vbd61PniZ3VxtKx6 npmbaMETbYnTiRjZfqYSi3OIP7Rv1Bc= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Uat5jhPa; spf=pass (imf10.hostedemail.com: domain of arnd@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=arnd@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707736580; a=rsa-sha256; cv=none; b=qjSrsjlnmV9D8QuKnONHLqkWocjoFYusGqglgKL6l1cl8nhFXm5MODj4MwqCUc1VZClyVm h9YMs78TE2kvAQ+kTFZxDOsNiA/lDGjtahuYTEsAY370eHAYk7qbkc8GPsWg0z0swyyLjh zDBb7BASw71HJX9vUabeOHPa15zK6HU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 7B56FCE1152; Mon, 12 Feb 2024 11:16:16 +0000 (UTC) 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 MIME-Version: 1.0 X-Rspamd-Queue-Id: 01C37C0019 X-Rspam-User: X-Stat-Signature: 5socdtzrs94et5gn18xyt3hri6ocfxa8 X-Rspamd-Server: rspam01 X-HE-Tag: 1707736579-111690 X-HE-Meta: U2FsdGVkX1/Nz5HKpZbSderopUBdPnRlzBxpiyQM/W9ItCohrbfRohLO6HT+UYZo6gaK34FBrr8jFQKItktx2ZBgrlovxO2YanJ8zrzlkmtWqlLoGrohS3bgENS0lw3FwpBCTOufS7E/iFjYuNxKAdMqdcFqjCS9J5JvPRmyLzDRlzvJJzO3grE20alb9ZE9deCIBlSaaLzvurzPAtRJj8OJlrS8Z1rOPYV8G45KK2qMJoFOii8eifBV/Ff5VrKyqTmrvRLeGXxQvHp1lPZ0gHjsEL9FsFZhq1OUrzHMb4QbV1U6lb4SCDP0ee2JVoGh1Lw+5SpnidU7BfoqbjUBxFyhp/iXnMYPG9vq48CMxU4KbYxxlVsX2GkdpbHOnyDp9Sqb6Gfsbslmm1I0Hqbla0FWyi6zWhuwU3jpIJyDLadlhMjfld9Jxh7ERNtcUfBVAZcIyoZj1Np9tqWaGiEZt3W2wwvlyNqLGdIkEQTvnu5hpjFs2B8Ob/H7ox46z7uJ7bzT6W6HUtOk/0p5bUzUHP3euqrS6A6qw3PVhvOINYNuq5vRSdeEZmHER2+YmAnjcgcFNmRjCKj7MI1fqSwociLRWlhPnO1CSkV3ts57moI1du5AoZ2iLsz7oR0O83r1B1f+8bEGbxDZHHCJTHYY4LQicIEbyKMVc/sjHQ5sBMO6iZ+EJ4WIrArB8xochrBpRZHKcQc/Stco5DcwI3lLv/dmpFaU4mdxbMjSV9+MAs1RCuY5BLy4o1LM1HR6CzIjqVFPrLolfjYe+aE4iLUydTDSS/VkC5dvcTgbe7m+E/n5JI81mrBAXF0uigPJ7tai3f5yNvJCGecxrZnsVwOQtUTDqEXVPADDsfL08xVSWJ9dc8gbEOj1xGBdJhlbjbd6q6A8M93K3JF6HNQkpGcuXPsDywDyshiLUi1OmeEd0voE3MXV7k9FhWM9kZvISWxKdsFog18UnUzQEmZMCaS XRvSLNyX 91KYSeh2Vc2ZAMSuZIDJVhQUFb8/uko3V2sVlb9Dandf8PNK84CxQHhE2TgpKIOXQiXmzir2aOsUuXplxymqNMeqf4PIjqgKQ4YEtFbUiUcIAUNoF/VhqC4Win1zcBOPC4dJLOykojAU+KcOVF2jWcHxBFUsOzSwwlSxQThMCfxLOYJ5rDZpV2KjAOCKf4PdqvYqVu7SkjOp49mlP6LWhCVxZaRA9iJyykEmUZ/W5+6wvHufxB20HbOO+3Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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);