From patchwork Mon Jun 13 20:14:18 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: 12880103 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 2DCECC433EF for ; Mon, 13 Jun 2022 20:19:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63CF48D01DB; Mon, 13 Jun 2022 16:19:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59E608D01D8; Mon, 13 Jun 2022 16:19:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 292D58D01DD; Mon, 13 Jun 2022 16:19:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E29B38D01DB for ; Mon, 13 Jun 2022 16:19:52 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C00B761103 for ; Mon, 13 Jun 2022 20:19:52 +0000 (UTC) X-FDA: 79574328624.25.34A0F6D Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf18.hostedemail.com (Postfix) with ESMTP id 466101C0075 for ; Mon, 13 Jun 2022 20:19:52 +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=1655151585; 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=bgGIoP7jXmxJI/MRAshv+0ZSBU3qLuiELKkrVE3erv8=; b=Tx3ufgGib+OSKMRv+3CRINt/7OLqN5cTferSwJ6ogYbMF4V+m/d6x2YflQZxIH1DxTkbs+ djLDhQRR9ITw8i3XavtHbQZ4Xi93tpCSo+pVwH6pNEdeNdh3NKk7rEyn4uB+qK7BZVTgjf ongP+RFoY9TadvbK5JxiwaupvUxSI3c= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Peter Collingbourne , Evgenii Stepanov , Florian Mayer , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 27/32] kasan: introduce complete_report_info Date: Mon, 13 Jun 2022 22:14:18 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655151592; a=rsa-sha256; cv=none; b=GedXBxuwoF2+aoPCL7J9NxkkBk1jKG+8q9073/4IREl7ddF5HRsuDO5tZuRVtpcDvAoyKi NJ36twhHLLv/1JzhakfcrLLA43EBaBF2OlmlxScAxRgW/GLhgPmjf2uK/Lios0trDl6Iry vduWNzYLYneztjxpJaReNwAgB4oAbeY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Tx3ufgGi; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655151592; 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:in-reply-to:references:references:dkim-signature; bh=bgGIoP7jXmxJI/MRAshv+0ZSBU3qLuiELKkrVE3erv8=; b=btJ5JVPYZPm+rPK3SWGgCGsI9KKx7gyUmVRTTz/Vbuj6LltFGtAUcUJMJkfecKBPl2hkiT CbE2CCmHEW+umeNeLtzzLLD+T6zBLe6jsFK7IC5DqceGXbJPOpnnjHgK1KtE0XVW1KUE2P I3PEQc3iVJa0JXNsQ0HT9Nqc8BKuqNA= X-Stat-Signature: 79w5ay3qd7xq4oja6zeskpupeci4oiqa X-Rspamd-Queue-Id: 466101C0075 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Tx3ufgGi; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1655151592-77554 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: From: Andrey Konovalov Introduce a complete_report_info() function that fills in the first_bad_addr field of kasan_report_info instead of doing it in kasan_report_*(). This function will be extended in the next patch. Signed-off-by: Andrey Konovalov --- mm/kasan/kasan.h | 5 ++++- mm/kasan/report.c | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index e3f100833154..0261d1530055 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -147,12 +147,15 @@ static inline bool kasan_requires_meta(void) #define META_ROWS_AROUND_ADDR 2 struct kasan_report_info { + /* Filled in by kasan_report_*(). */ void *access_addr; - void *first_bad_addr; size_t access_size; bool is_free; bool is_write; unsigned long ip; + + /* Filled in by the common reporting code. */ + void *first_bad_addr; }; /* Do not change the struct layout: compiler ABI. */ diff --git a/mm/kasan/report.c b/mm/kasan/report.c index cc35c8c1a367..214ba7cb654c 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -407,6 +407,17 @@ static void print_report(struct kasan_report_info *info) } } +static void complete_report_info(struct kasan_report_info *info) +{ + void *addr = kasan_reset_tag(info->access_addr); + + if (info->is_free) + info->first_bad_addr = addr; + else + info->first_bad_addr = kasan_find_first_bad_addr( + info->access_addr, info->access_size); +} + void kasan_report_invalid_free(void *ptr, unsigned long ip) { unsigned long flags; @@ -423,12 +434,13 @@ void kasan_report_invalid_free(void *ptr, unsigned long ip) start_report(&flags, true); info.access_addr = ptr; - info.first_bad_addr = kasan_reset_tag(ptr); info.access_size = 0; info.is_write = false; info.is_free = true; info.ip = ip; + complete_report_info(&info); + print_report(&info); end_report(&flags, ptr); @@ -456,12 +468,13 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write, start_report(&irq_flags, true); info.access_addr = ptr; - info.first_bad_addr = kasan_find_first_bad_addr(ptr, size); info.access_size = size; info.is_write = is_write; info.is_free = false; info.ip = ip; + complete_report_info(&info); + print_report(&info); end_report(&irq_flags, ptr);