From patchwork Fri Mar 25 01:12:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12791185 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 441FCC433EF for ; Fri, 25 Mar 2022 01:12:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2A3E8D002B; Thu, 24 Mar 2022 21:12:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD5F58D0005; Thu, 24 Mar 2022 21:12:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4FE98D002B; Thu, 24 Mar 2022 21:12:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id A27BA8D0005 for ; Thu, 24 Mar 2022 21:12:52 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 873B2120399 for ; Fri, 25 Mar 2022 01:12:52 +0000 (UTC) X-FDA: 79281134184.07.DCB988E Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id DB3F140013 for ; Fri, 25 Mar 2022 01:12:51 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 7FF7ECE279F; Fri, 25 Mar 2022 01:12:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E099DC340ED; Fri, 25 Mar 2022 01:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1648170767; bh=Pj7hruJwztHMQZ1mKwF/mJfZ6Lv6QyXGVkerKId+sIA=; h=Date:To:From:In-Reply-To:Subject:From; b=mqBlQG3YBs+42gRv8TZORdPTsEU59PdVRp9RMmmm09HoEMo0W5CqM6VcxfAhaIyQL eol9ZodvW/9/yp6NLQEtZmpuLa1rXn4hulxae1nu4uutO34Mqnz2i8PFS1E6LGKERF KG+zdHB8o78HTwG7CGf1KntHUnHHMyOdQe0XM5/M= Date: Thu, 24 Mar 2022 18:12:46 -0700 To: ryabinin.a.a@gmail.com,glider@google.com,elver@google.com,dvyukov@google.com,andreyknvl@google.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220324180758.96b1ac7e17675d6bc474485e@linux-foundation.org> Subject: [patch 084/114] kasan: simplify kasan_find_first_bad_addr call sites Message-Id: <20220325011246.E099DC340ED@smtp.kernel.org> X-Stat-Signature: 7mcrb4cjkx89c5p8bh7zi6fhfawd1sew Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=mqBlQG3Y; spf=pass (imf11.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: DB3F140013 X-HE-Tag: 1648170771-858051 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000074, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Subject: kasan: simplify kasan_find_first_bad_addr call sites Move the addr_has_metadata() check into kasan_find_first_bad_addr(). Link: https://lkml.kernel.org/r/a49576f7a23283d786ba61579cb0c5057e8f0b9b.1646237226.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov Cc: Alexander Potapenko Cc: Andrey Ryabinin Cc: Dmitry Vyukov Cc: Marco Elver Signed-off-by: Andrew Morton --- 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(-) --- a/mm/kasan/report.c~kasan-simplify-kasan_find_first_bad_addr-call-sites +++ a/mm/kasan/report.c @@ -444,10 +444,7 @@ static void __kasan_report(void *addr, s 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; --- a/mm/kasan/report_generic.c~kasan-simplify-kasan_find_first_bad_addr-call-sites +++ a/mm/kasan/report_generic.c @@ -34,8 +34,12 @@ void *kasan_find_first_bad_addr(void *ad { 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; } --- a/mm/kasan/report_hw_tags.c~kasan-simplify-kasan_find_first_bad_addr-call-sites +++ a/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); } --- a/mm/kasan/report_sw_tags.c~kasan-simplify-kasan_find_first_bad_addr-call-sites +++ a/mm/kasan/report_sw_tags.c @@ -36,8 +36,12 @@ void *kasan_find_first_bad_addr(void *ad 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; }