Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5654400rdb; Wed, 13 Dec 2023 15:38:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IHg0KbDIY7v3TpFvvXyqr9aM2HkadkmMH8A4rHwsTrr16Ql7PPmYbb4FkoudRyM3OBAwoU6 X-Received: by 2002:a17:902:ce86:b0:1d3:67a9:d2e with SMTP id f6-20020a170902ce8600b001d367a90d2emr100918plg.77.1702510686149; Wed, 13 Dec 2023 15:38:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702510686; cv=none; d=google.com; s=arc-20160816; b=gTBwfIoCAnUYFgGD80h0OP5fzmy+reSLf59QxJ9NUt5/48+x8nzeC1kWlMY57+MP0V e7LYTaUTUP5WkSTtcTJkry5ZSpK+18oSjGvlikimBagpcEy/o/HcDu+DyXYG0RleOqvD ond1c5mFnnExwKwhMtyStGXLt6KbidnxYP/UsBHdaBr/29WQ1K32PQttf+KKFCF1bqyV ZSsWZIRin9FjZKucPfd4bWb25F1RCZcIuFkLrZncAMAJB5WpXmyLAu8NTvJSy2QL4Zc7 vCBg5rs3MGh/o5958LgErvF5un3xZcUl+sHGNSPVp+enTE3KJTUFW2OAlWu5raZHbx/S AYlw== 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=VOrBlHsfakvcZe1XK7OFH4H3N77vpLrrwB2MGspTrGw=; fh=TQATEbdDZNcnk8L2eDP6eFL9HlexFaHIexhR1TH2IlY=; b=uYwpijEVuDD3K7FLT8pbo6qOxoYGcSawJAae0a6hVqbxKS/9aU9AMr90IuoEpHJt5P j74U2u/r09n1IpWY/I0ZXQzJsSyduU+W1HMEYwvzOmloogU3hJ335sna4EN4rydTFsQE SQlpOJLoZ5jvxtaSiN/I4es+b/jItvEn3uoYmHhDvnhgU4wHBde58WXhm1Kg5qVWGPGQ TgArtpUV5CQvHV/3h3UK0lI1+Qf/r41RdfXymLKGKjgTroKec8TqjQIRWkjbbfHqA2hM 9C3nDoSIAB9opTR9gSwSCjh+ZbQ4RsLxWB45JkWcKf5noj/AG7uVMkthOwzxmFc4cRW7 oDiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=rQjQFy0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id 19-20020a170902c21300b001cfc0272b48si10058368pll.103.2023.12.13.15.38.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 15:38:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=rQjQFy0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id ABB2B802853D; Wed, 13 Dec 2023 15:37:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442842AbjLMXhD (ORCPT + 99 others); Wed, 13 Dec 2023 18:37:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442704AbjLMXgv (ORCPT ); Wed, 13 Dec 2023 18:36:51 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 003B910B; Wed, 13 Dec 2023 15:36:56 -0800 (PST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BDKrAPv021496; Wed, 13 Dec 2023 23:36:39 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=VOrBlHsfakvcZe1XK7OFH4H3N77vpLrrwB2MGspTrGw=; b=rQjQFy0wPuUwau2ppdq++EV6noT4UNw7RODVhrwnRKuOTNNPcaYXY8qDYRLsiPxvzvwr YADUDpoNYoPEn1KoAjxGiJ1L/mjeBJACAh20x9PXS4BfwEgpxhX1HTl/Sf+jv40NvuBk PQ540BjKBkBgIdxYHuDztQYjf/H1avsFfP+RnpSResmI+H4q3oXKic9uXpYq8QXheP/+ 6mVD+S+SCOUU+viTuR/NcNKmuw6ZnD4PDyfdwaBhN/2NwYUiKup05BnlhfD362I8yz/M cu8ZGCW/OnXVRbQdvqI2X9/bflvGaWIfI1zDp0UsCsvekt3R7tKUXpM+qvsQgVQB8WqH qw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3uym1sbn7n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Dec 2023 23:36:39 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3BDNQea8021795; Wed, 13 Dec 2023 23:36:38 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3uym1sbn7b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Dec 2023 23:36:38 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3BDMk9JC005049; Wed, 13 Dec 2023 23:36:37 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3uw4skm9wh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Dec 2023 23:36:37 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3BDNaYD814156344 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 Dec 2023 23:36:35 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D0AF520043; Wed, 13 Dec 2023 23:36:34 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 693A220040; Wed, 13 Dec 2023 23:36:33 +0000 (GMT) Received: from heavy.boeblingen.de.ibm.com (unknown [9.171.70.156]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 13 Dec 2023 23:36:33 +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 v3 16/34] mm: kfence: Disable KMSAN when checking the canary Date: Thu, 14 Dec 2023 00:24:36 +0100 Message-ID: <20231213233605.661251-17-iii@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213233605.661251-1-iii@linux.ibm.com> References: <20231213233605.661251-1-iii@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: doTRKEg5slH34q2wsmPW_bB7RNQCjFCQ X-Proofpoint-GUID: qah957R2REyygwz3vVTu7gxw-sNw3M3- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-13_14,2023-12-13_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 suspectscore=0 adultscore=0 malwarescore=0 impostorscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312130167 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Wed, 13 Dec 2023 15:37:58 -0800 (PST) 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 3872528d0963..96138e704c5a 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; -- 2.43.0