From patchwork Fri Jun 21 11:35:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13707426 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 6DCD2C27C4F for ; Fri, 21 Jun 2024 11:54:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC4788D0168; Fri, 21 Jun 2024 07:54:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E758E8D0164; Fri, 21 Jun 2024 07:54:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC69B8D0168; Fri, 21 Jun 2024 07:54:44 -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 AD7FB8D0164 for ; Fri, 21 Jun 2024 07:54:44 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 527EB80D86 for ; Fri, 21 Jun 2024 11:54:44 +0000 (UTC) X-FDA: 82254738888.23.68AE58F Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf07.hostedemail.com (Postfix) with ESMTP id 1A47F40007 for ; Fri, 21 Jun 2024 11:54:41 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=KK5KFmUq; spf=pass (imf07.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 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=1718970877; 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=pcK1rMwKAY+PK8Ytyz/2vRX/RRHh9XTkiYTIv46ktrM=; b=z5SSiqAxiOrDeKuaXbPB3U3YAHHI4GwXXe8cdAVKE5K4bYpXXLqgKYk/rl3SMi/VRad44Y PLasFd4btpaVzG4ClYEuQsvADWX5Boom4h8rKJd0sUJe7tPIOdGGLs6eXGqh2BmkZaKSTr 98xDeFoloPlNzZ9+H8DuEwDc9EZlLBE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=KK5KFmUq; spf=pass (imf07.hostedemail.com: domain of iii@linux.ibm.com designates 148.163.158.5 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=1718970877; a=rsa-sha256; cv=none; b=z/TX3iAsNRFIio5A2Vc67B8FfmytJNWZmxjRPzxppH5+CgZxwmb3Xw6r+flhZAubl64y4j T0XgWSJUAzy7vprJMiDRaNdCdSP8k1OMGtFNaHlgQCHQ/Gfch/EmRGFw8KhbxHQFwx6P5Y gT6yVLV3AWAEroOzK3S4joA7HvjJkv4= Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45LBQuHE001093; Fri, 21 Jun 2024 11:37:28 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 :content-transfer-encoding:mime-version; s=pp1; bh=pcK1rMwKAY+PK 8Ytyz/2vRX/RRHh9XTkiYTIv46ktrM=; b=KK5KFmUqFy+pAtK8dSlZyJeirzy+D vjgdsTAcMBMHfKZlEn+Q2I32LnTP1xKT+UjtKrTPGj/LxxIr8u4RqtsxNVD0CASx 5Ab2N4AqTZwsfnraG1oxqRJ8FfDHT10hFT2pVjEZT1vxBvXHy385Ok6RAa3r9uz1 sCmMt2FQAvxECLfUZwAiotv/hmcXX/gUjE27WfarwXeOsJjtOyFaia9zkTn3kWg3 5KVEwTWe83Is/+9SmczThu9FnFTj5FCQEk0RZx4d69rxGpbqVIIr7DW2VEtOvF8k C4FSh9yI7xIz3pOnWnnvkit4IG98OuefsYFmkYUSnH5/NMJKAIcZFpo2g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yw5krgf2e-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 m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45LBbRMl016963; Fri, 21 Jun 2024 11:37:27 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 3yw5krgf2a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 11:37:27 +0000 (GMT) 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 45L9FnW9032319; Fri, 21 Jun 2024 11:37:27 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3yvrsppv5q-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 smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 45LBbLhN37814576 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2024 11:37:23 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D8762004F; Fri, 21 Jun 2024 11:37:21 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C90AE20067; 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 20/38] lib/zlib: Unpoison DFLTCC output buffers Date: Fri, 21 Jun 2024 13:35:04 +0200 Message-ID: <20240621113706.315500-21-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> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: wJtOQ7TAKKf4TPkcI736NUE9Ic4mpwZq X-Proofpoint-ORIG-GUID: GqZyPigDgr7xcJiQq6qOfnvPbViWBKhq X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 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 impostorscore=0 clxscore=1015 bulkscore=0 spamscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 suspectscore=0 adultscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210084 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1A47F40007 X-Stat-Signature: ihe6a3ffiyp6npfa1ufrofts5e6xmaer X-HE-Tag: 1718970881-791551 X-HE-Meta: U2FsdGVkX18dTPrajwYl10nGfAl4XHR1f5AH/6k5aXmPjYsgTXfaREn+bwRkSIeQFrCgxPSSGuf3KGS7M1FSfdtwcHKiXMXzwa/ebW9k6zrjVMdIY0h2Xi7lgKT7M0P3aEwHPzXbChkSmN2BWQC71rNiPYc1wzTreFL3qelBrAhE1veTO+xGPoJwDjD0YQ9b4oqy8+97kp1vrPmf28uWrZWwvu1bP9BGec9pbr63f1Vk9s1UZsNY2UbZeizDN7iFbun3wyTOhsRg5KBerP5/DDB6v4V7OMlv5FNUB6V4UenrkOIomjfJRqqHFw2sd9rhuqupbqn/8Ld+xqZxLrduOhCrhRAN1nYnW916KdwgBrFzQcAOAbDsmaxQyXaTBdaHun9h71tpNryEltRJiNoPTECXr085KVm357DsG7ZuL09vQjwFlpq0agSYd2ydlwQLufL5KVBBeHTeEDQDS8RJQaVdpoDGtmi++mUrb0o6eHDFygsssp5bgx3aZDPdeFWHKFJ0Cty/O1GJeWx2Fkvib9TPsCiFle3XuAK3s+mu6lIOQClO6sSgT422zhR5dDRMWupm0BsHVmFxsLVJNSOhLpqLjgpAOGfEVf+VdEgCyylIexsXp+KH8KhUgBFH1J88LzW/SMKB25DfqwxiE/TUxakuVSHthUUq7hxPXY7a+inpSJ0Prca3qSnVP744fCCSwz3yJD/UMTmwGwpjamQQrdNLNlBD1h6dgHar0YLe9qTWc64OtMSQ42J03tXUVH54hSATw5n3tC6XLQ8Vzgrg+CLT5Usalg0iTPv3YsMN0P7dVBXSV2z5jLV69YSLGzgRwd5x24oR4Ps44rRFp2yPjR1VbQhQqrcaYgbETGF/ATx6WnrfIV0/RDKkzFrHu/y8tYgMaz0r6CA5qFueaR+ZjUDU/Zgg7BBbqJ0YJ1AHYFN8cCI0DrY+NrcWH7EidnWpecvUN5qc7q9nS+vW/LJ Z8AD2mgz yAtOb0FuG44zTpOklfEETR21RcgmH+o4Haacg1yl3PgoX6kcIdOjyxd+36GW7gQ+2X/GaKj1TsKnNXdE0b1O3rpmJMOhV1l/YfLufd1ct7xwsc6bOZvP1mGjhN74uhoMaKV9Zoy9U5qU9UZ/MdtSSPzkD0ti6+yKbnGsmIamnrPbKe5jd/QCajNIGsCSQq2A2Ob890knUXx1b8WhGWbvApZaXtBUg7XXQEW0LDIgFmgsI5i+qMSPl8x7xdDddMC01w3xP+JyrQd7k7bSAfEdvLsNSoV5QJU5QZbw2JTmvzE8urBbpFFh0EF2W7Yqb5sjYmYTMfXqtVlbtNAqdHM3+I1tgRUDoZFDSYiBXqzVx0VKzWO6bvHHZ8BP2J6l1s3hd/Z3uOQGZkne7XrESgWB3ZSs8N8mKahYWPfF2TE2olJ8BIBqdx3TrUIl/LhSmL/KF1jU1L+bzi5YZJOCKPoZPZe5Z0Q== 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: List-Subscribe: List-Unsubscribe: The constraints of the DFLTCC inline assembly are not precise: they do not communicate the size of the output buffers to the compiler, so it cannot automatically instrument it. Add the manual kmsan_unpoison_memory() calls for the output buffers. The logic is the same as in [1]. [1] https://github.com/zlib-ng/zlib-ng/commit/1f5ddcc009ac3511e99fc88736a9e1a6381168c5 Reported-by: Alexander Gordeev Reviewed-by: Alexander Potapenko Signed-off-by: Ilya Leoshkevich --- lib/zlib_dfltcc/dfltcc.h | 1 + lib/zlib_dfltcc/dfltcc_util.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/zlib_dfltcc/dfltcc.h b/lib/zlib_dfltcc/dfltcc.h index b96232bdd44d..0f2a16d7a48a 100644 --- a/lib/zlib_dfltcc/dfltcc.h +++ b/lib/zlib_dfltcc/dfltcc.h @@ -80,6 +80,7 @@ struct dfltcc_param_v0 { uint8_t csb[1152]; }; +static_assert(offsetof(struct dfltcc_param_v0, csb) == 384); static_assert(sizeof(struct dfltcc_param_v0) == 1536); #define CVT_CRC32 0 diff --git a/lib/zlib_dfltcc/dfltcc_util.h b/lib/zlib_dfltcc/dfltcc_util.h index 4a46b5009f0d..10509270d822 100644 --- a/lib/zlib_dfltcc/dfltcc_util.h +++ b/lib/zlib_dfltcc/dfltcc_util.h @@ -2,6 +2,8 @@ #ifndef DFLTCC_UTIL_H #define DFLTCC_UTIL_H +#include "dfltcc.h" +#include #include /* @@ -20,6 +22,7 @@ typedef enum { #define DFLTCC_CMPR 2 #define DFLTCC_XPND 4 #define HBT_CIRCULAR (1 << 7) +#define DFLTCC_FN_MASK ((1 << 7) - 1) #define HB_BITS 15 #define HB_SIZE (1 << HB_BITS) @@ -34,6 +37,7 @@ static inline dfltcc_cc dfltcc( ) { Byte *t2 = op1 ? *op1 : NULL; + unsigned char *orig_t2 = t2; size_t t3 = len1 ? *len1 : 0; const Byte *t4 = op2 ? *op2 : NULL; size_t t5 = len2 ? *len2 : 0; @@ -59,6 +63,30 @@ static inline dfltcc_cc dfltcc( : "cc", "memory"); t2 = r2; t3 = r3; t4 = r4; t5 = r5; + /* + * Unpoison the parameter block and the output buffer. + * This is a no-op in non-KMSAN builds. + */ + switch (fn & DFLTCC_FN_MASK) { + case DFLTCC_QAF: + kmsan_unpoison_memory(param, sizeof(struct dfltcc_qaf_param)); + break; + case DFLTCC_GDHT: + kmsan_unpoison_memory(param, offsetof(struct dfltcc_param_v0, csb)); + break; + case DFLTCC_CMPR: + kmsan_unpoison_memory(param, sizeof(struct dfltcc_param_v0)); + kmsan_unpoison_memory( + orig_t2, + t2 - orig_t2 + + (((struct dfltcc_param_v0 *)param)->sbb == 0 ? 0 : 1)); + break; + case DFLTCC_XPND: + kmsan_unpoison_memory(param, sizeof(struct dfltcc_param_v0)); + kmsan_unpoison_memory(orig_t2, t2 - orig_t2); + break; + } + if (op1) *op1 = t2; if (len1)