Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3342647rdb; Thu, 16 Nov 2023 07:10:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvQ9fVRQdVvdkjL2cQx1lpcpi3ZbnrknBus9+LzPJxEKQ3V0kfv75oKdKPj7iluv27B6hp X-Received: by 2002:a17:903:32c5:b0:1ca:72f9:253a with SMTP id i5-20020a17090332c500b001ca72f9253amr9628308plr.23.1700147409405; Thu, 16 Nov 2023 07:10:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700147409; cv=none; d=google.com; s=arc-20160816; b=aSyGvUP8GV9e63zMOrufvX0KJpVn+TWxg6V1uAlZtEwfa2X+Es5/Vdj4VKUJL9SMK+ aOYmTD2cBS2VE1XBAFclxLDmQkktqnoMM950ahf1TknhkMdZnowG9q9J3SIyAchMM1t7 5LhOCuJ0HdnxRZPeI3UAniUmlCFJomY6dChgRI6qqLH5xWinvD4fGlANX4KZlQjNNzpy r0Ahk6vRJSZIjTSQ/mZLDnz8WG+2SsOOzCgdHthU3zn5zP+Fx15+KhhQAnb0Juveu2G3 Lmj9U1q8Qk+Y5/2TsYa36/MRYY0tOhjgYNGWCAd2AMHoSlo7iJAFtR9s5eh6w9TJPPh2 kToA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=fbR/4LYIfiQo0P1zqKZIOJ71Sdj1oOT4JYZNUwb072M=; fh=DRu6qs0R2xKQX+9GuRjR62JGLrpnTaOE1wQSzv/gHhk=; b=T/vgFE1CICPP1Wa8mOTH+EoiDruG2cXCus9zpEhtAPhlsfgeQu4nDLOLAHnEohGUjv ZZWz6bbTo6nLxZwc8ppvUCQDAg4/FwZLR7WAU3DD5P1+s9qVzFEa/5xPXuW3d+zA3gCD WJcP1Fj5Szxx6dZKYPwOEnohdDUKXeGQo3Rt1gHfkb0TFrlQ3PW+m4WTWhWuekkeojbo asGY+drNXNNABEV23X8cdYS+G284h5Qggqj/WD2TFt4n52QRYqIUHAykKCc3aGnkMmQG BLW9PcofYH40hkYCYaPpiitK2O88CSwPFryfSjwtqoxMhpexEaeJBL31Dz7nXLkjXQ+o fa7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=iC82ZytX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id u11-20020a170903124b00b001ce2fc160f9si7718664plh.424.2023.11.16.07.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 07:10:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=iC82ZytX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 21B54807C752; Thu, 16 Nov 2023 07:09:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345400AbjKPPJr (ORCPT + 99 others); Thu, 16 Nov 2023 10:09:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345330AbjKPPJq (ORCPT ); Thu, 16 Nov 2023 10:09:46 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B29193; Thu, 16 Nov 2023 07:09:41 -0800 (PST) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AGF2wT2000665; Thu, 16 Nov 2023 15:09:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=pp1; bh=fbR/4LYIfiQo0P1zqKZIOJ71Sdj1oOT4JYZNUwb072M=; b=iC82ZytXIrHyHQGQyplNNWwqzIsTcdT1zPbaIX4NuowOuM5y9z/66cBho7CBRzC9o35B U364uRSYVgu4KvKeuNI20OXoKDLlkHm6QZRYGFrahiaInSr8CPmSGYw/wkW6m9c+kz98 RL3emxkJNvUZu56xeHqp4w1dgbk9qnUGgUBeeuxtsJ9qzo/0VaQAq6rCEQkGa5RNH1Lc kQZSCIZxnSzTBu4HqWGk3kbmvHhfhaLWoyz2bifcDs9BTVnNTceZOlSHNZyx0EUWBoIV Ib21JhCVClH1/0Vt6obIWjAtIts+9NGksw7/cZkjU2dZ9xwhCGzo7WoeVVgth5XPKuIQ LQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3udncagdg8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Nov 2023 15:09:09 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3AGF2uF1000499; Thu, 16 Nov 2023 15:09:06 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3udncag9q9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Nov 2023 15:09:05 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3AGERv2d007963; Thu, 16 Nov 2023 15:08:19 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3uapn1xx9m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Nov 2023 15:08:19 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3AGF8G1815729200 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Nov 2023 15:08:16 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 426CD20043; Thu, 16 Nov 2023 15:08:16 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8FE9120040; Thu, 16 Nov 2023 15:08:15 +0000 (GMT) Received: from [9.155.200.166] (unknown [9.155.200.166]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 16 Nov 2023 15:08:15 +0000 (GMT) Message-ID: <50846951de5c3c246c2c6263605a349a04a6ae45.camel@linux.ibm.com> Subject: Re: [PATCH 13/32] kmsan: Support SLAB_POISON From: Ilya Leoshkevich To: Alexander Potapenko Cc: Alexander Gordeev , Andrew Morton , Christoph Lameter , David Rientjes , Joonsoo Kim , Marco Elver , Masami Hiramatsu , Pekka Enberg , Steven Rostedt , Vasily Gorbik , Vlastimil Babka , 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 Date: Thu, 16 Nov 2023 16:08:15 +0100 In-Reply-To: References: <20231115203401.2495875-1-iii@linux.ibm.com> <20231115203401.2495875-14-iii@linux.ibm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ytVHJmlpUSeyjqKkMO8KNbDnnh0SJfQg X-Proofpoint-ORIG-GUID: GoQTG6AsG7rXNy-iKNMNk95yhUTNkZSq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-16_15,2023-11-16_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 phishscore=0 mlxscore=0 spamscore=0 clxscore=1015 malwarescore=0 impostorscore=0 adultscore=0 mlxlogscore=953 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311160118 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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 16 Nov 2023 07:09:57 -0800 (PST) On Thu, 2023-11-16 at 15:55 +0100, Alexander Potapenko wrote: > On Wed, Nov 15, 2023 at 9:34=E2=80=AFPM Ilya Leoshkevich > wrote: > >=20 > > Avoid false KMSAN negatives with SLUB_DEBUG by allowing > > kmsan_slab_free() to poison the freed memory, and by preventing > > init_object() from unpoisoning new allocations. > >=20 > > Signed-off-by: Ilya Leoshkevich > > --- > > =C2=A0mm/kmsan/hooks.c | 2 +- > > =C2=A0mm/slub.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 3 ++- > > =C2=A02 files changed, 3 insertions(+), 2 deletions(-) > >=20 > > diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c > > index 7b5814412e9f..7a30274b893c 100644 > > --- a/mm/kmsan/hooks.c > > +++ b/mm/kmsan/hooks.c > > @@ -76,7 +76,7 @@ void kmsan_slab_free(struct kmem_cache *s, void > > *object) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 return; > >=20 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* RCU slabs could be legall= y used after free within the > > RCU period */ > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (unlikely(s->flags & (SLAB_TYP= ESAFE_BY_RCU | > > SLAB_POISON))) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (unlikely(s->flags & SLAB_TYPE= SAFE_BY_RCU)) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 return; > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * If there's a constru= ctor, freed memory must remain in > > the same state > > diff --git a/mm/slub.c b/mm/slub.c > > index 63d281dfacdb..8d9aa4d7cb7e 100644 > > --- a/mm/slub.c > > +++ b/mm/slub.c > > @@ -1024,7 +1024,8 @@ static __printf(3, 4) void slab_err(struct > > kmem_cache *s, struct slab *slab, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 add_taint(TAINT_BAD_PAGE, LO= CKDEP_NOW_UNRELIABLE); > > =C2=A0} > >=20 > > -static void init_object(struct kmem_cache *s, void *object, u8 > > val) > > +__no_sanitize_memory static void >=20 > __no_sanitize_memory should be used with great care, because it drops > all instrumentation from the function, and any shadow writes will be > lost. > Won't it be better to add kmsan_poison() to init_object() if you want > it to stay uninitialized? I wanted to avoid a ping-pong here, in which we already have properly poisoned memory, then memset() incorrectly unpoisons it, and then we undo the damage. My first attempt involved using __memset() instead, but this resulted in worse assembly code. I wish there were something like memset_noinstr(). Right now init_object() doesn't seem to be doing anything besides these memset()s, but this can of course change in the future. So I don't mind using kmsan_poison() instead of __no_sanitize_memory here too much, since it results in better maintainability.