From patchwork Sat Feb 24 10:54:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Paul_Heidekr=C3=BCger?= X-Patchwork-Id: 13570372 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 A5609C48BF6 for ; Sat, 24 Feb 2024 10:54:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95B686B006E; Sat, 24 Feb 2024 05:54:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 90B346B0071; Sat, 24 Feb 2024 05:54:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 784AA6B0072; Sat, 24 Feb 2024 05:54:27 -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 655466B006E for ; Sat, 24 Feb 2024 05:54:27 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id EA8211C1063 for ; Sat, 24 Feb 2024 10:54:26 +0000 (UTC) X-FDA: 81826388532.29.D728CF1 Received: from postout2.mail.lrz.de (postout2.mail.lrz.de [129.187.255.138]) by imf03.hostedemail.com (Postfix) with ESMTP id 2D2FB20009 for ; Sat, 24 Feb 2024 10:54:23 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=tum.de header.s=tu-postout21 header.b="S cx8/Ed"; spf=pass (imf03.hostedemail.com: domain of paul.heidekrueger@tum.de designates 129.187.255.138 as permitted sender) smtp.mailfrom=paul.heidekrueger@tum.de; dmarc=pass (policy=none) header.from=tum.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708772065; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uRexiL1hDopWJGrXPsILxKWh+xq4dfVumK602P+IOzs=; b=voAJB0AJr2hlwEEb26h9WJ7qLFWZRO596Cr+zOjtdif9d1lX/CwRgLxsXnVwkfK0CFn+II KzDS1vbcy4auSEIfsIEH7vysWgFI6IO4g02oRw49uWS3KMaZoJuKgo2AS6t3R6sjtxBpwH bpw8aDVGiQS9tSIlC2A0sGnD5LXOwbE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708772065; a=rsa-sha256; cv=none; b=pyluL827TGFLswqT2ZI3WEs8simlcVxXGQmdkeg8lDca+r4f0Ca3NLgr6+pnGjQ1zorSfj svNKucmtGPUP+h8KFq6sYL2KCvjBUJSzjoD2n7lPxytiwQ3SiLbHH/A1WSrQg63BQibk0H yMTYDxHPjvKiZArlPDXE9waLnpjmexQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=tum.de header.s=tu-postout21 header.b="S cx8/Ed"; spf=pass (imf03.hostedemail.com: domain of paul.heidekrueger@tum.de designates 129.187.255.138 as permitted sender) smtp.mailfrom=paul.heidekrueger@tum.de; dmarc=pass (policy=none) header.from=tum.de Received: from lxmhs52.srv.lrz.de (localhost [127.0.0.1]) by postout2.mail.lrz.de (Postfix) with ESMTP id 4ThkK95Rs3zyZG; Sat, 24 Feb 2024 11:54:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tum.de; h= content-transfer-encoding:content-type:content-type:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received; s=tu-postout21; t= 1708772061; bh=TZfMEar/WGv3z6Vr+zFmVB2K7TNo7XIS9DBxR4kHKAM=; b=S cx8/Edgu2nmGsS4l7bzFuVLeZygh4C5RVN7X0385BXX0YcaMDMGFBRcwcBofkFcK abzN375IT+cn+QMTgM4E6YKnis9fnZgmPZtc3Rt+D2SQVjfr4S0hiC6gX9gY4eYs Aps6ZlPnGCv8pfJuMW8G221NmA8cG8q9FVp2jtU9GwvdxYDKw7pZcPe3fwOvdge3 i+zfPPMjaDsC4B7Jxaxy7dhFINOXAAZme3xwEXUtdboZBPI5GIaPiiqD1+lofJSE 1PXWbcwvLOunAb+QWe+DkQUOiZjcQBxJK9d1HsvpEwxbFPBjrm++tCLtSeKSVk2r +pofugRBOoMfjFbyVQDmg== X-Virus-Scanned: by amavisd-new at lrz.de in lxmhs52.srv.lrz.de Received: from postout2.mail.lrz.de ([127.0.0.1]) by lxmhs52.srv.lrz.de (lxmhs52.srv.lrz.de [127.0.0.1]) (amavisd-new, port 20024) with LMTP id t3smiUimcLMl; Sat, 24 Feb 2024 11:54:21 +0100 (CET) Received: from sienna.fritz.box (ppp-93-104-78-110.dynamic.mnet-online.de [93.104.78.110]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by postout2.mail.lrz.de (Postfix) with ESMTPSA id 4ThkK821SYzyZF; Sat, 24 Feb 2024 11:54:20 +0100 (CET) From: =?utf-8?q?Paul_Heidekr=C3=BCger?= To: akpm@linux-foundation.org Cc: andreyknvl@gmail.com, dvyukov@google.com, elver@google.com, glider@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mark.rutland@arm.com, paul.heidekrueger@tum.de, ryabinin.a.a@gmail.com, vincenzo.frascino@arm.com Subject: [PATCH] kasan: fix a2 allocation and remove explicit cast in atomic tests Date: Sat, 24 Feb 2024 10:54:14 +0000 Message-Id: <20240224105414.211995-1-paul.heidekrueger@tum.de> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240223161020.9b4184e1e74b35f906e0ec78@linux-foundation.org> References: <20240223161020.9b4184e1e74b35f906e0ec78@linux-foundation.org> MIME-Version: 1.0 X-Stat-Signature: 1wnf6sze8kqts87cmgrjqpegx335sodc X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2D2FB20009 X-Rspam-User: X-HE-Tag: 1708772063-425987 X-HE-Meta: U2FsdGVkX1/ryOlvePPilZDabmIyjCqhzMMveZSzcp/QAnAP68Wx/d8Ubbk1wkwE+W+rjkAST0g+9/FpwA+MCUCT4zDi438pOwdyr47Iky/twNDKaUOiRYhM8UqxG2khNkk9N7WmzqTI4qk6FtDOA3cgXNXKtHTnnPP79tlJKrdfYhZglnceizSDjqBarBEEMLGbpXU0tbMa39ZbuVIINHxPC0j7YSocsl6PcvnL30qnuz/TERxEM8sbg/9YXED2WoZn4RooEApLSEm2N3qt+Ie56EZaMJQyYvYLEyyNFru4nmqLt1E/II3uTeRlGOB9zLD6K913i6JN21GE14rYGSMVLz/ynCmjEh/XOEFCmyAG5R4iDq2Q20Qme845SCA0mmUXxBzeUcej5b7+gGzsuijYWtr6RZAReD72mLwIEgHUrQJjGbhsI0nHHT+QQ8QpUYveHl5n549bW0+Bq+XAvnH+TJf70mZykV9RGkOrKtrpzxicJNB68QfGe5qVdEM7uXXPcuUlKkuXpwIGTC2/PW5Qi2/haoJowuxTKbymNU8s0SveNR60OUiGQTRcJ8bp0EdSZ3DArrbFyYTyCEvGAo51k58QZdhzq4wmZfevPF0OXCHSSG7/qMn7L33TBxXJiJ4hhzPrHhAL2tvBFiZxnkOo9tS/amsOh6aoE/sEtb5Ww91cX2rbZvXcPZI8In0v50sSXJPuMtPaRj+57BaT1+DV4V5AxX3d6DpFIGF+l3ofoETKxKqHjvgOeS5EripgLvSGfHWU1TakUx0+DfaU+r62kHuFevfcRKWnzQ+VILkw5DzMTYX8luJWCvhiUnesdbCqQlEuLnLXjAEuNupNLdbHST47LQ0vMoxjhCyZeoLXXNVBtnfoinSwpGy2eIlhveiSRC9NMqY2+UgD4/1LtAietMKs4LdDhk6WRC/c8vSpvrBMF0maczLXtcqq4RONq+YPouXRfyql1E0XJrR EjfPWoaM i1D9ez0gq6dZep/Q27Q8ZMEsddJp6pygAcSwq8bYVlxO7hZ6UYP/+kFyIAPQx4icycjP6MsvLPIzrThnYCRyUWFxS6t5DnQcFUJf0Sl+a4pbc4BquAE3hLlZDe4LnUHya2HHHduJ1D+8LajOpT4UjlwuLrIJO/IfBUvgXx+l+S92ltb1il7gPvRu5xNEeIRcxht9qJP06KYlHT2t9+aKna66a6BRyPSTunawAup+50QNtfU0sLgHRlACXYV0nG5jpR3PvF9SOW7rVlfESyybmXPucWtcqW1zRcA2e1yj7ba5nmE9CbJyRFGnA5WZdsu7I/g+Jt1mBwXG/XBYLY7kS9SJchlASvsyYnyODU+sRKC+zw8J8+1TXLPUX5+m4gMIdTVzwjAem/UnDgBVQ7dXFw8HJ4eC47fXFuEEm6PyxpZwt/QoogfeaUKXpLZGB6deHdHY1cN8TqqLf1yx0AtMcETo4qfNGzgh06bWJXVtyi9M0mSEFxu6ca2Sd8oMnTiOXKXs1 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: Address the additional feedback since "kasan: add atomic tests" (4e76c8cc3378a20923965e3345f40f6b8ae0bdba) by removing an explicit cast and fixing the size as well as the check of the allocation of `a2`. CC: Marco Elver CC: Andrey Konovalov Link: https://lore.kernel.org/all/20240131210041.686657-1-paul.heidekrueger@tum.de/T/#u Fixes: 4e76c8cc3378a20923965e3345f40f6b8ae0bdba Closes: https://bugzilla.kernel.org/show_bug.cgi?id=214055 Reviewed-by: Marco Elver Tested-by: Marco Elver Acked-by: Mark Rutland Reviewed-by: Andrey Konovalov Signed-off-by: Paul Heidekrüger --- @Andrew: I wasn't sure whether you'd be squashing this patch into v1 or if it'll end up as a separate commit. Hope this works either way! Changes PATCH v2 -> PATCH v3: * Fix the wrong variable being used when checking a2 after allocation * Add Andrey's reviewed-by tag Changes PATCH v1 -> PATCH v2: * Make explicit cast implicit as per Mark's feedback * Increase the size of the "a2" allocation as per Andrey's feedback * Add tags Changes PATCH RFC v2 -> PATCH v1: * Remove casts to void* * Remove i_safe variable * Add atomic_long_* test cases * Carry over comment from kasan_bitops_tags() Changes PATCH RFC v1 -> PATCH RFC v2: * Adjust size of allocations to make kasan_atomics() work with all KASan modes * Remove comments and move tests closer to the bitops tests * For functions taking two addresses as an input, test each address in a separate function call. * Rename variables for clarity * Add tests for READ_ONCE(), WRITE_ONCE(), smp_load_acquire() and smp_store_release() mm/kasan/kasan_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 4ef2280c322c..7f0f87a2c3c4 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -1152,7 +1152,7 @@ static void kasan_bitops_tags(struct kunit *test) static void kasan_atomics_helper(struct kunit *test, void *unsafe, void *safe) { - int *i_unsafe = (int *)unsafe; + int *i_unsafe = unsafe; KUNIT_EXPECT_KASAN_FAIL(test, READ_ONCE(*i_unsafe)); KUNIT_EXPECT_KASAN_FAIL(test, WRITE_ONCE(*i_unsafe, 42)); @@ -1218,8 +1218,8 @@ static void kasan_atomics(struct kunit *test) */ a1 = kzalloc(48, GFP_KERNEL); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, a1); - a2 = kzalloc(sizeof(int), GFP_KERNEL); - KUNIT_ASSERT_NOT_ERR_OR_NULL(test, a1); + a2 = kzalloc(sizeof(atomic_long_t), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, a2); /* Use atomics to access the redzone. */ kasan_atomics_helper(test, a1 + 48, a2);