From patchwork Fri Jun 21 11:35:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13707335 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 0DEEDC27C4F for ; Fri, 21 Jun 2024 11:38:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65E4E6B0184; Fri, 21 Jun 2024 07:37:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46E0C6B017F; Fri, 21 Jun 2024 07:37:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EECA8D015B; Fri, 21 Jun 2024 07:37:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ED6CA8D00DB for ; Fri, 21 Jun 2024 07:37:37 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AA946140CB2 for ; Fri, 21 Jun 2024 11:37:37 +0000 (UTC) X-FDA: 82254695754.17.5368C23 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf11.hostedemail.com (Postfix) with ESMTP id 5A9594001D for ; Fri, 21 Jun 2024 11:37:35 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=EVMWG01B; spf=pass (imf11.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=iii@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718969842; 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=o5OLh1G5igJ7wfCkEas83RRSlonR9xfZGMUuvDY/DE0=; b=QRiCcdkFR4g4baGzhNxsKc2bzoArJ2wCiop+O/O7RvTrTet8ykXUept8JPqS4DGv8c11iC rfGgPRsAWzGvYse+Zftrc+QYpM+wV4SzFEpLUwGmRpoiNZyouLCDIUJivd9UWFGdo8KZRK k5vwb2QbI6X3P2UfumHuKFN1kBglnRU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=EVMWG01B; spf=pass (imf11.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=iii@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718969842; a=rsa-sha256; cv=none; b=ExinAdLWNyoE3N1zNRHhyJomVppaMWuatqqRs04WZeToPv7ec2UiJaKUrloB+8Agu2Duzi qzs9zcue3aPbxJdIOIX9RMiVpdYrWDcdC6d2ZLPyjd54eJAf9I7Yt/2zdLA71dD1GJz464 1S47VUpvqLFN3p1ovAJjqVbPHFv3lhU= Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45L9wphq019602; Fri, 21 Jun 2024 11:37:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=pp1; bh=o5OLh1G5igJ7w fCkEas83RRSlonR9xfZGMUuvDY/DE0=; b=EVMWG01B2oC74lZBbL2kSPnMQZ5Ey GhloJsCiv+elwBctf7BhxcRrVcSkiv0g2G2V9yGfWYfTQfIaRc2bJdcrcGlvrJW3 OWxRPnp1WSA9rr55k6HJbN6/DoWp9IND7o4KAW7MoUK/O2qgZHk/fhTTnx+rCdyh 3H1BjfUk2clfA6ZZpiua3Fsjx+c9IS1AyXnw2+TXz1Jbi6G9VvrXnx7uefnK9+tM QL4sB0UUXmCVQ/8CPXpJ5DKAvAYkgmNOLl7pdqQlkSdxDg10GOL18ycxjPAS3Us6 89uo2XPPczKg1q1E04eP6VRSF8UKl+5IPEFuQvqd/KkHVkGaAfxQyUxkg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yw7by86pd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:28 +0000 (GMT) Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45LBbS0q005032; Fri, 21 Jun 2024 11:37:28 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yw7by86p9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:28 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45L9KGho030990; Fri, 21 Jun 2024 11:37:26 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3yvrssxvbh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:26 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45LBbK5U55378330 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2024 11:37:22 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BF09520043; Fri, 21 Jun 2024 11:37:20 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 351DF2005A; Fri, 21 Jun 2024 11:37:20 +0000 (GMT) Received: from black.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Jun 2024 11:37:20 +0000 (GMT) From: Ilya Leoshkevich To: Alexander Gordeev , Alexander Potapenko , Andrew Morton , Christoph Lameter , David Rientjes , Heiko Carstens , Joonsoo Kim , Marco Elver , Masami Hiramatsu , Pekka Enberg , Steven Rostedt , Vasily Gorbik , Vlastimil Babka Cc: Christian Borntraeger , Dmitry Vyukov , Hyeonggon Yoo <42.hyeyoo@gmail.com>, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Mark Rutland , Roman Gushchin , Sven Schnelle , Ilya Leoshkevich Subject: [PATCH v7 19/38] mm: kfence: Disable KMSAN when checking the canary Date: Fri, 21 Jun 2024 13:35:03 +0200 Message-ID: <20240621113706.315500-20-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240621113706.315500-1-iii@linux.ibm.com> References: <20240621113706.315500-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: qNNzZXoNK5Jx7e0m-RV4t8XuUyzuBdnJ X-Proofpoint-ORIG-GUID: 9nqHha1GsHQHCk2fCPLnLz5EA_SBzbVx X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-21_04,2024-06-21_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210084 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5A9594001D X-Stat-Signature: yn3xx4nr994q5df8wp6x1qiy8jqp48gj X-Rspam-User: X-HE-Tag: 1718969855-878568 X-HE-Meta: U2FsdGVkX1/GMT3YJHPLpGUG6BGGyLD2pekKIHgXSWYTjD2MYMzt8dwoXVWY7JRxhTscokLUCJqAgkIndtA2cbyp24+WFbi7jAKejGgYIgayu4DYwhBNrtASxOWLJ7xVoxIwFRWwDSrJszqQergWYsAKVhmPn1y2Ght03RPL4Pu3BHk9Id8ecWCO1au+vIsD+V/I0tDa4mmNymFj0b81NfFcyQIobakXscgoM6KHOmnIbuKqtBblk/2bk0TiQG0QiCJV/m/D/9ZBPA4+b8n7SCcdXp9lyRurr5rLycVmJsSkC2G6WW9BK0iZV3PyGt4yf9/woUBPBLIFGZC/KPB92TlURnmC58Y+c8H9GWt+7CO3z7IhrUnN5OLNTmvTGMNknKa9IIVx1Tqn6duGyRUemEMXCmpZAugRJJMCLigOVuYbkUSv6ZWUlmQ7sco1dHqsWoTF/7BupGjNgH75cUCu4qWAqEH2JxIdkW+7n0R3q0gQZbtY4GU06TP7Fn0nZ/KHPYI/awPW42Z0Si+3hUSJBMWDZre9j85qgIACzxp12Q+IbiTpu2TOTWlxbLCxzsMk0AnR06OE+kWb3GM6WnRAIX45vrL96sRBRVRlCgtjhM+o6E5mG3TIDuEHS/IDqUOS2SWLRNK9fiQQxV5Jj7qcA+Ac0LU/+P/iJc7fZFVhQSFHaUkssq8imVQF1TmpDBY8P+wyXzYWbZ+/oZ1lO0vcXicDY6EqkntTzIr52BcRSTWMMVckicLjMSVPKjvNJG/9HXNEa6oKKKjDniS9kWP/a1HTeA0KU/oS3hfgcy2EE3krioRXJaNw9lsUvMFkSqic36lz0BXGf7Bv7eqB7h8Kxojopy/7spqO4I0/7n2K2772vmfsz8M7RyvtHMZlLPaWFy7TbGPW21obKIioL+fo9N5oW7drJqBDgQ7l9yQW8/RgZvknbQQhskqT5lu0BEKeXbl7lcfwJ+aa7MGfaHS TBfEJUfR mLaJXvF5rd3xpwwTm707Cqkz1RCV6WAnrW16xM6K4bEBsmnpBLl4v6keI7E151DoP+/E6spAb5uhpDCGCwlC86VFgB1DDvdNXDHYAbv9UXGn20G2DJH0s/29nhyiJBIJt7yElSEbS18uEl4nkcFxAPdh3l5wczUBn7+VNq+AQgrXC8/imT89aMqZnsV6LTMITyFd88w6bu6DDTRnWC57kDePSOrg+t/P2ncFfdK3QwqOTSeOhFO1B7oMFCPEvAbi4b8r5ab0DGqLhVbQ21HCaf/4JjHip1mUMQnInfT3LYkE7mAbIAUKUPsc/puP+7YNcaK9G X-Bogosity: Ham, tests=bogofilter, spamicity=0.000025, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: KMSAN warns about check_canary() accessing the canary. The reason is that, even though set_canary() is properly instrumented and sets shadow, slub explicitly poisons the canary's address range afterwards. Unpoisoning the canary is not the right thing to do: only check_canary() is supposed to ever touch it. Instead, disable KMSAN checks around canary read accesses. Reviewed-by: Alexander Potapenko Tested-by: Alexander Potapenko Signed-off-by: Ilya Leoshkevich --- mm/kfence/core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 964b8482275b..83f8e78827c0 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -305,8 +305,14 @@ metadata_update_state(struct kfence_metadata *meta, enum kfence_object_state nex WRITE_ONCE(meta->state, next); } +#ifdef CONFIG_KMSAN +#define check_canary_attributes noinline __no_kmsan_checks +#else +#define check_canary_attributes inline +#endif + /* Check canary byte at @addr. */ -static inline bool check_canary_byte(u8 *addr) +static check_canary_attributes bool check_canary_byte(u8 *addr) { struct kfence_metadata *meta; unsigned long flags; @@ -341,7 +347,8 @@ static inline void set_canary(const struct kfence_metadata *meta) *((u64 *)addr) = KFENCE_CANARY_PATTERN_U64; } -static inline void check_canary(const struct kfence_metadata *meta) +static check_canary_attributes void +check_canary(const struct kfence_metadata *meta) { const unsigned long pageaddr = ALIGN_DOWN(meta->addr, PAGE_SIZE); unsigned long addr = pageaddr;