From patchwork Wed Jun 19 15:43:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13704133 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 490A6C27C53 for ; Wed, 19 Jun 2024 15:46:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B73D06B02D8; Wed, 19 Jun 2024 11:45:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AAFEC6B02DA; Wed, 19 Jun 2024 11:45:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88C066B02DE; Wed, 19 Jun 2024 11:45:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 596F96B02D8 for ; Wed, 19 Jun 2024 11:45:59 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D23AD81315 for ; Wed, 19 Jun 2024 15:45:58 +0000 (UTC) X-FDA: 82248063996.02.1F4A214 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf27.hostedemail.com (Postfix) with ESMTP id 836A340025 for ; Wed, 19 Jun 2024 15:45:56 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=H2rwcfpx; spf=pass (imf27.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=1718811952; a=rsa-sha256; cv=none; b=7y4sm39MU0tjFzSIHk+qPq0ULc3L6NhTfdAtXY1gJ9mTtF8u82SudQrFxac0HQunvjVmM2 LLjdO4Vkfu51jh4x+zbtRhV52gqiw9/KEoCWOSwuPW56xGRcQorDSFomD0Nopno6n+LPnQ g4087DT5fd4taPeW8pRITp9ttDZOBME= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=H2rwcfpx; spf=pass (imf27.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=1718811952; 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=B6ux6Duer+6hRb7jFBwKOfRCQ8w/RoXPktHRYzSdn47rpFdc/eIaCqeyxpvBFdzD1iHplc zBBqeWFBht3j4svGm1IZwLp8x2OM/2kNoJVulrowjIQk2Z5SPvvx0Eh5NdNNLSdKd4qP5R L6pWgPEtS+BICODK5CiRiL3wtOkOgvQ= 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 45JF032v027848; Wed, 19 Jun 2024 15:45:48 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=H2rwcfpxAjXz8AKG0XHn5V9sdNpG/ 16BQyY3fL/cc50vYDqVZdKMEBTo2UmzzahsvlY8JAiKCbNqJv4S/DReZnbLb3am4 K/Nh3TJp3JdvVZ2/CMV4M10lWBMXe4RhCOSv6e1ud/8bZlQ68F6Lrheg2axOIEDa QoQbyKGdI4fV1AX5TQSAyOFleJYhJnUM8bCHaiQ/rUgUTVKYnX0YAo0Mws32sEGB NtCL1f6XpmStp3EFCMPt10Z4UfRtUGHORhntuEJtbW0bYJ6Y0nASHnz8AFoIBYn/ SjX36E6mqng9FafMvWvCgJy9n51Q3cBWl6h8emiXr35PRl0T4R0ReVrOA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yv1jfr5bp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:48 +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 45JFjlSu005782; Wed, 19 Jun 2024 15:45:47 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yv1jfr5bf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:47 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45JFhSXR023897; Wed, 19 Jun 2024 15:45:46 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3ysp9qdyqb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:46 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45JFjeu751904966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jun 2024 15:45:42 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2661D2004B; Wed, 19 Jun 2024 15:45:40 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CC37320067; Wed, 19 Jun 2024 15:45:39 +0000 (GMT) Received: from black.boeblingen.de.ibm.com (unknown [9.155.200.166]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 19 Jun 2024 15:45:39 +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 v5 18/37] mm: kfence: Disable KMSAN when checking the canary Date: Wed, 19 Jun 2024 17:43:53 +0200 Message-ID: <20240619154530.163232-19-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240619154530.163232-1-iii@linux.ibm.com> References: <20240619154530.163232-1-iii@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: avgexdB5NelKVCyWQvNp9eWkYSYTUZuK X-Proofpoint-ORIG-GUID: TdCHS1L2YRGuiuvHwsDX16Cd7IpCg-Qt 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-19_02,2024-06-19_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 bulkscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 priorityscore=1501 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406190115 X-Stat-Signature: y9wa4p3sg6bwysqejaokg7b49b68wef8 X-Rspamd-Queue-Id: 836A340025 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718811956-602694 X-HE-Meta: U2FsdGVkX19pFhHAvBihvs1N0QiLrFq8OlSDPfDC0SOyKpaACmpBzPtoI+QijBnybC9PzbTtaIxiee4Y3J+bYjJBqcSlw0I+t1nJNke7E8kDdBzOyn3Ws3QCvtzyBRqcuWLCpI+znMp4qsrUARUL0Qx94wDafXRtH7YZEvfYkktq53k/i6Ukd16Ji0272F6TV+KUrF8/C2mrsXRmEZ15KPDEr1Tp8pT/ivj3jA3WNrSMSsN500QXWg79lIBTpW2nSFQ/HYhbfqFmmIrti0FWOn6C1A0AYdKx0QxcC7oWuSWiXdgGPOg0qbGJH+lwLV+u070/g945kkF8NNtngTiKepO29mMpFvPdVA+m7F9afbzwi8i4VGCGmxu9ybcSnZx7JbjeFcV3v8CqWcmMOro8yNFSPrLaAmW/ZC0JE85dUDQnmn86M9zrv4VcdH8ImvMPtbQFat5BRWvW9TmBD+GH7Nm+efQ7kP49t3HI5XZY6lR5REljveSdO/v7/FZdRBOldN4RQYLLmtXgQyPiKeKflPTvHBnRRKbAd/MBBf9KBTIsZQJJyKAo042lo2UT31h/oSu6PY5mhZkBMP1gita+rIcyi3wamAcP38P1IlXeegfvb50YTalbNHrMwviwIdLzJBS8yepI1cd9Fcn3RWunxH1EWPs+G4aFr7diiuom5a6gmD6PufYv5Vy9BgWVkfLBxfz2eACOGyIOY84ojmCWaljRw884WqT6tBYdjzi7fWcqLJ0DvP0c7UuHihPxz9dyszVNUNeeO8i5hWQkPqiMjLj3QtOjgkAikQqRBi2/y9R3/OPULPNeAGvc4P1SOxbPsfOgnW6jkxvKjaLprSKK/VR2zm2Sy8YO7C6br3qwl/4CQzMVsFELLqnsZvrmnTH4TwwkSquyfZvd7zaVFq4vhw5UYlabL633SLiKHKsHdAnB5h6pBqHg5Azblwy+/viym1eArpCcj/rANMo4AEg /Z482ifw nzeeWTfddjSMvN9WP7ugzW8PHrx3z0bG6XmYaWG0wQeeVCxcLF0PS+Z8/2d8HBr7oQvlRnIpP2/ceQtKvmNkEWh8KuUYwgIS5jAMAP/fU99Kq9Xya8yL7VNKijqP3kCEqHUJmoVhxfW+x3+ig6lEtPmoQrQ7fMrd95u2/GkzdUgmqnS9W1HLiZcoz+74DNbowvpxOsL89ows5QcSgToOZa9ht5jrsF2+eFdYgFdXomCkZnN6aK+nWmz/vD7Tx2KG0WzSmrFUyyW9VK5lxP1mVdEr2Xg== 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;