From patchwork Wed Mar 2 16:36:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12766299 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 A7E68C433F5 for ; Wed, 2 Mar 2022 16:38:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C8648D0003; Wed, 2 Mar 2022 11:38:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 377258D0002; Wed, 2 Mar 2022 11:38:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28E7D8D0003; Wed, 2 Mar 2022 11:38:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0161.hostedemail.com [216.40.44.161]) by kanga.kvack.org (Postfix) with ESMTP id 184AF8D0002 for ; Wed, 2 Mar 2022 11:38:59 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CC6A1181CAC6D for ; Wed, 2 Mar 2022 16:38:58 +0000 (UTC) X-FDA: 79200005556.20.901CDD3 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf05.hostedemail.com (Postfix) with ESMTP id 4DED3100002 for ; Wed, 2 Mar 2022 16:38:58 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1646239137; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JGZE0bvysohYUpkupChxa3EWr4j93F81DU4moq+5lLk=; b=pFiF5ZBBKwtr5haHzZ+mlJbBIPwPTTGaaQU/estweYKXFq/g+JBe8ekDyrppDB98msQPnO MZPXUBggNulqGy/S/jMmMd7r0Mufkp/3WPqcCmDVpa+EQXPQm/NWEjD/X8xNgK3Chg+g85 0qMysA0AKdryYWdV+sdDRlnH0dqADD4= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 12/22] kasan: simplify kasan_find_first_bad_addr call sites Date: Wed, 2 Mar 2022 17:36:32 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: 4aqrzoxnyqqpyzhkk3gscgc9czkmozag Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pFiF5ZBB; spf=pass (imf05.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspamd-Queue-Id: 4DED3100002 X-HE-Tag: 1646239138-103245 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000167, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Move the addr_has_metadata() check into kasan_find_first_bad_addr(). Signed-off-by: Andrey Konovalov --- mm/kasan/report.c | 5 +---- mm/kasan/report_generic.c | 4 ++++ mm/kasan/report_hw_tags.c | 1 + mm/kasan/report_sw_tags.c | 4 ++++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index bb4c29b439b1..a0d4a9d3f933 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -444,10 +444,7 @@ static void __kasan_report(void *addr, size_t size, bool is_write, start_report(&flags, true); info.access_addr = addr; - if (addr_has_metadata(addr)) - info.first_bad_addr = kasan_find_first_bad_addr(addr, size); - else - info.first_bad_addr = addr; + info.first_bad_addr = kasan_find_first_bad_addr(addr, size); info.access_size = size; info.is_write = is_write; info.ip = ip; diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 7e03cca569a7..182239ca184c 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -34,8 +34,12 @@ void *kasan_find_first_bad_addr(void *addr, size_t size) { void *p = addr; + if (!addr_has_metadata(p)) + return p; + while (p < addr + size && !(*(u8 *)kasan_mem_to_shadow(p))) p += KASAN_GRANULE_SIZE; + return p; } diff --git a/mm/kasan/report_hw_tags.c b/mm/kasan/report_hw_tags.c index 5dbbbb930e7a..f3d3be614e4b 100644 --- a/mm/kasan/report_hw_tags.c +++ b/mm/kasan/report_hw_tags.c @@ -17,6 +17,7 @@ void *kasan_find_first_bad_addr(void *addr, size_t size) { + /* Return the same value regardless of whether addr_has_metadata(). */ return kasan_reset_tag(addr); } diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c index 44577b8d47a7..68724ba3d814 100644 --- a/mm/kasan/report_sw_tags.c +++ b/mm/kasan/report_sw_tags.c @@ -35,8 +35,12 @@ void *kasan_find_first_bad_addr(void *addr, size_t size) void *p = kasan_reset_tag(addr); void *end = p + size; + if (!addr_has_metadata(p)) + return p; + while (p < end && tag == *(u8 *)kasan_mem_to_shadow(p)) p += KASAN_GRANULE_SIZE; + return p; }