Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp322734pxm; Wed, 2 Mar 2022 16:22:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+cB7iRXTc/lOzwR7jyOxh64efcXjzB40PeEgRXjdLT5swQg/NjB4gqov+2NXt6KQQcG5C X-Received: by 2002:a05:6a00:2d0:b0:4f4:1f34:e39d with SMTP id b16-20020a056a0002d000b004f41f34e39dmr14991820pft.14.1646266923823; Wed, 02 Mar 2022 16:22:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646266923; cv=none; d=google.com; s=arc-20160816; b=jIZseCUVlBY5WhC/VXhRDUsGzL64JzMAuo77aHW+1omTK2pMc44tBy3KSq0B21HyL5 BCEfJ/juXSbt3E59/AP6OolQIVLBG5buTsrjZVdmI+BbHZ0jWucI5e428qHkZEsbL5fk e3tT720LwlXyDwYPKubDc91xzJpcbAi5KBHzbfPF2xVH2nyzc2RRwVW5R/rhLzOWCMn2 UpdqqcPQOzsd5/+amDBHMFf2S7xAwAsPzT68x9tAts718EYBOwDF2hCp9nLjqNj+V2Rw UX39bjl6tYSBC+2rI0WPgw9+r7wzMYqNZTDUL71ci/Ai022ieQL5DNwrWFdcDX6yimTI j5WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JGZE0bvysohYUpkupChxa3EWr4j93F81DU4moq+5lLk=; b=wnD9EPnpYqjLwxDSEwNgxfhlFuMf4IL2YFIgOJmBydJh5JfLhTEs8TukFZr0z+quLf 8C/KukfeF2Yjm1F42N2rnDOYjHHvuUZ/7DBzAHsZapLAjDvAYBq/Km6wKi6rbZTWdBrX REiemSUZG2xrLEAvPz0AjEi3WGG3L9UZbeRBtGNVZbiqHKeZTot25KFQJ4CFO/GoNje9 gfJ11+JhOtY2HpiGl69er5RfPYRE+8crCYB9eKLBpF1DJYboP6Ey3hJghdwfZn3Lczkk hL4W12j76Na3hkdnw9ySljP6NQjq3dJ/l4dpIVEPfb/pkd6xJVAWvLjYMCLfWUsYARsg L81g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pFiF5ZBB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o19-20020a656a53000000b00364fd3d64d4si669942pgu.584.2022.03.02.16.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:22:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pFiF5ZBB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 841ED46169; Wed, 2 Mar 2022 15:35:00 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236896AbiCBQjn (ORCPT + 99 others); Wed, 2 Mar 2022 11:39:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232862AbiCBQjl (ORCPT ); Wed, 2 Mar 2022 11:39:41 -0500 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E02931369 for ; Wed, 2 Mar 2022 08:38:58 -0800 (PST) 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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.25.1