From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6CBBC4338F for ; Thu, 29 Jul 2021 13:47:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8BA0760C41 for ; Thu, 29 Jul 2021 13:47:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8BA0760C41 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id EFE7E8D0002; Thu, 29 Jul 2021 09:47:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EAE638D0001; Thu, 29 Jul 2021 09:47:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D75FA8D0002; Thu, 29 Jul 2021 09:47:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id BAC8C8D0001 for ; Thu, 29 Jul 2021 09:47:34 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6FBB3184383E1 for ; Thu, 29 Jul 2021 13:47:34 +0000 (UTC) X-FDA: 78415752828.33.16C8DE3 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf14.hostedemail.com (Postfix) with ESMTP id 16C436001981 for ; Thu, 29 Jul 2021 13:47:33 +0000 (UTC) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16TDXWBw110609; Thu, 29 Jul 2021 09:47:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : references : date : in-reply-to : message-id : mime-version : content-type; s=pp1; bh=9O/GEXoZTqlR+xJfXv/WGh/M7l0aIVQd0qAa+HW+Jb4=; b=coJYu/Zt4KQyNuAJsFjZKgC2d9R85IJRz0q/e8r6/5m+RSV6IN9G1K0a6XkBIy9TP2OI fHwl3ccbMPd9m7nrH6gj+FLL8b98Z+DpQ0NQ1wRg4HUj7imZ42r/KwjNtXzMowZDHzFU VYo+Z8PPrFE4wBMrIbtFHN+WxhKoUBH+CYZ/wfgtuBn3hCs1LKuQf/TC6pv1x2J/GzOX kP6EsMclJkS6Z9KLjUdYk7Cq3Anv6yQOgRhIB/db6pYmF8sbq8j9GqUJACk80o/FdzPV esdO0Dl/NErjdG3p59+3Jl1fiTXMjuf9G+qeUASNY78+uLBRiM7URIkK8UdWFHxl0EsL YQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3a3tw7nkue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jul 2021 09:47:32 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 16TDYInm117541; Thu, 29 Jul 2021 09:47:32 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3a3tw7nktt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jul 2021 09:47:32 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 16TDZnjZ002896; Thu, 29 Jul 2021 13:47:30 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 3a235ks4ry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jul 2021 13:47:30 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 16TDigBD25428294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Jul 2021 13:44:42 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BF0C6A4051; Thu, 29 Jul 2021 13:47:25 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 58190A4080; Thu, 29 Jul 2021 13:47:25 +0000 (GMT) Received: from tuxmaker.linux.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 29 Jul 2021 13:47:25 +0000 (GMT) From: Sven Schnelle To: Alexander Potapenko Cc: Heiko Carstens , Marco Elver , Vasily Gorbik , Christian Borntraeger , kasan-dev , Linux Memory Management List , LKML , linux-s390 Subject: Re: [PATCH 2/4] kfence: add function to mask address bits References: <20210728190254.3921642-1-hca@linux.ibm.com> <20210728190254.3921642-3-hca@linux.ibm.com> Date: Thu, 29 Jul 2021 15:47:24 +0200 In-Reply-To: (Alexander Potapenko's message of "Thu, 29 Jul 2021 14:43:51 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 1Grps8gXUt09Y6zVx3mspHN6fv6-rv4W X-Proofpoint-GUID: dN18rwQmbCZAayJ0xzHHDeX5X82kCHcf X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-29_10:2021-07-29,2021-07-29 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 spamscore=0 impostorscore=0 malwarescore=0 phishscore=0 priorityscore=1501 clxscore=1011 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2107290087 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b="coJYu/Zt"; spf=pass (imf14.hostedemail.com: domain of svens@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=svens@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-Rspamd-Server: rspam02 X-Stat-Signature: jbe68x8k9kquiijy9h6u8h8ecbtmagcq X-Rspamd-Queue-Id: 16C436001981 X-HE-Tag: 1627566453-914064 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: Alexander Potapenko writes: > On Wed, Jul 28, 2021 at 9:03 PM Heiko Carstens wrote: >> >> From: Sven Schnelle >> >> s390 only reports the page address during a translation fault. >> To make the kfence unit tests pass, add a function that might >> be implemented by architectures to mask out address bits. >> >> Signed-off-by: Sven Schnelle >> Signed-off-by: Heiko Carstens >> --- >> mm/kfence/kfence_test.c | 13 ++++++++++++- >> 1 file changed, 12 insertions(+), 1 deletion(-) >> >> diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c >> index 942cbc16ad26..eb6307c199ea 100644 >> --- a/mm/kfence/kfence_test.c >> +++ b/mm/kfence/kfence_test.c >> @@ -23,8 +23,15 @@ >> #include >> #include >> >> +#include >> + >> #include "kfence.h" >> >> +/* May be overridden by . */ >> +#ifndef arch_kfence_test_address >> +#define arch_kfence_test_address(addr) (addr) >> +#endif >> + >> /* Report as observed from console. */ >> static struct { >> spinlock_t lock; >> @@ -82,6 +89,7 @@ static const char *get_access_type(const struct expect_report *r) >> /* Check observed report matches information in @r. */ >> static bool report_matches(const struct expect_report *r) >> { >> + unsigned long addr = (unsigned long)r->addr; >> bool ret = false; >> unsigned long flags; >> typeof(observed.lines) expect; >> @@ -131,22 +139,25 @@ static bool report_matches(const struct expect_report *r) >> switch (r->type) { >> case KFENCE_ERROR_OOB: >> cur += scnprintf(cur, end - cur, "Out-of-bounds %s at", get_access_type(r)); >> + addr = arch_kfence_test_address(addr); > > Can we normalize addr once before (or after) this switch? > I don't think so. When reporing corrupted memory or an invalid free the address is not generated by hardware but kfence itself, and therefore we would strip valid bits. >> break; >> case KFENCE_ERROR_UAF: >> cur += scnprintf(cur, end - cur, "Use-after-free %s at", get_access_type(r)); >> + addr = arch_kfence_test_address(addr); >> break; >> case KFENCE_ERROR_CORRUPTION: >> cur += scnprintf(cur, end - cur, "Corrupted memory at"); >> break; >> case KFENCE_ERROR_INVALID: >> cur += scnprintf(cur, end - cur, "Invalid %s at", get_access_type(r)); >> + addr = arch_kfence_test_address(addr); >> break; >> case KFENCE_ERROR_INVALID_FREE: >> cur += scnprintf(cur, end - cur, "Invalid free of"); >> break; >> } >> >> - cur += scnprintf(cur, end - cur, " 0x%p", (void *)r->addr); >> + cur += scnprintf(cur, end - cur, " 0x%p", (void *)addr); >> >> spin_lock_irqsave(&observed.lock, flags); >> if (!report_available()) >> -- >> 2.25.1 >>