From patchwork Mon Oct 23 16:22:49 2023 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: 156984 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1410305vqx; Mon, 23 Oct 2023 09:26:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrH5wh98eNd4zrMW1pLe/L6GgBKvcT6gaf3b3peO/mYRgG/w8pLSUvdq8sjXB+vG8GR+Fj X-Received: by 2002:a05:6a00:c82:b0:690:41a1:9b6a with SMTP id a2-20020a056a000c8200b0069041a19b6amr11958562pfv.5.1698078400058; Mon, 23 Oct 2023 09:26:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698078400; cv=none; d=google.com; s=arc-20160816; b=t0Hgxsm7uwgmXEsqkwwA9Ftzgocq8tBB7QHzLzepQeIuOJ1GhfOKpqLQHtFHzhoPxG A1Mfe+9sYYifAuiV3HuTp2K9K6CNLwSAxnI6BuLOwV4M9yM2FgPILZgcMDMZ7mSVB+kp /Fv4DDVmk1gpYLRRexyGI9C5EQXeFOo+na1WXwi41uOqKoQNCBuuR4Mvr2ECaXsI+Au2 SdnBeEN61BdZJ6Aw4LygIOpxitTmPXnAW5C0S1Ijb3+naFHOvUlMEp4uQJqSzwSBX5/h bU8mNbV173Kh657MTRXpIenUuyNxRKLdSO2altEx1yy/m1jbDcqMDgM1rJ45iCQmuBHq 7gSA== 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=uhMrVBrzgAoT1gwViC8KxLkH9OMZhix/uhvoEc70W98=; fh=nfQSbTp1dWHt2Ier1Up8UhVNdXOqoJJLNvTrpT3jJEk=; b=gSNIWKjYAckIL2InUUcuEu4zFiFe1smdvtSveP2nwrf3LZCST9zfEytdkHmWfO4wx7 2v6nUplTmD0j+2SklOCAm5N426mnlJvQEohTqblYWWRlUaxU97UwJLSaC6rOxuz7mC7i syXitUfT4lblZCuef5VWQyzXq+A9JJGrEQ00lubcNNZNeMyEdgz4dQlfNsKlZ3XXuNkO iu2mJ1rscYL8+myIhmLoFKciZQwM9zk7BjP02lhKqKsZH5BX/sZBOAirK6TD1Ui/EtfA qHvl6KSjuPBJmS03DSI61Cu1OV3bRsLRHs1ifhEzszlUulnNxaUkiieDH21PmuS2MrQj yfYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ne3J1RXv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id j5-20020a056a00234500b0068fb6fc3ff1si6677974pfj.209.2023.10.23.09.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 09:26:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ne3J1RXv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B500880A1A7E; Mon, 23 Oct 2023 09:26:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229544AbjJWQ0a (ORCPT + 27 others); Mon, 23 Oct 2023 12:26:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233582AbjJWQ0R (ORCPT ); Mon, 23 Oct 2023 12:26:17 -0400 X-Greylist: delayed 129 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 23 Oct 2023 09:26:15 PDT Received: from out-210.mta1.migadu.com (out-210.mta1.migadu.com [IPv6:2001:41d0:203:375::d2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18C2F10E for ; Mon, 23 Oct 2023 09:26:14 -0700 (PDT) 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=1698078373; 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=uhMrVBrzgAoT1gwViC8KxLkH9OMZhix/uhvoEc70W98=; b=Ne3J1RXv7CfIkYMjEOEAo2MOXXrLjJl0MG/nn5TuOVSCeJC7ACQ8Zc+U0+7fVaprnL1TwV YcPWlAN0bBL1/0CJWM+oWPOfzdH5fmC91XjSmronfj3U3HMmSByKdvCQOOSWPbS9RJ3nc5 z58ccvrjKa1GY9FZizpTtMWzArqCzuI= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Oscar Salvador , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v3 18/19] kasan: check object_size in kasan_complete_mode_report_info Date: Mon, 23 Oct 2023 18:22:49 +0200 Message-Id: <97721c54e9ccacc494dbcfcd0cbd5f5aaab6973b.1698077459.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 23 Oct 2023 09:26:37 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780564256883331010 X-GMAIL-MSGID: 1780564256883331010 From: Andrey Konovalov Check the object size when looking up entries in the stack ring. If the size of the object for which a report is being printed does not match the size of the object for which a stack trace has been saved in the stack ring, the saved stack trace is irrelevant. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- Changes v2->v3: - Added missing "../slab.h" include for accessing a kmem_cache field. Changes v1->v2: - This is a new patch. --- mm/kasan/report_tags.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c index 78abdcde5da9..55154743f915 100644 --- a/mm/kasan/report_tags.c +++ b/mm/kasan/report_tags.c @@ -7,6 +7,7 @@ #include #include "kasan.h" +#include "../slab.h" extern struct kasan_stack_ring stack_ring; @@ -58,7 +59,8 @@ void kasan_complete_mode_report_info(struct kasan_report_info *info) entry = &stack_ring.entries[i % stack_ring.size]; if (kasan_reset_tag(entry->ptr) != info->object || - get_tag(entry->ptr) != get_tag(info->access_addr)) + get_tag(entry->ptr) != get_tag(info->access_addr) || + info->cache->object_size != entry->size) continue; if (entry->is_free) {