From patchwork Fri Jun 21 00:24:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Leoshkevich X-Patchwork-Id: 13706574 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 C3EE1C2BA18 for ; Fri, 21 Jun 2024 00:27:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 833C68D00FC; Thu, 20 Jun 2024 20:27:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76EE38D00EC; Thu, 20 Jun 2024 20:27:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AE698D00FC; Thu, 20 Jun 2024 20:27:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1A6408D00EC for ; Thu, 20 Jun 2024 20:27:01 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8BB221A071F for ; Fri, 21 Jun 2024 00:27:00 +0000 (UTC) X-FDA: 82253005800.10.4873451 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf08.hostedemail.com (Postfix) with ESMTP id 36C8A160005 for ; Fri, 21 Jun 2024 00:26:58 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=nZazUTOT; spf=pass (imf08.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=1718929609; 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=2ufWUYjrkekS6AUVieBXi57z+2PJzJpUCeCRkZb6FY5MJeTgyRMJjeklXMCJ3znCSvgTE4 j8o5hPu/TeHh+9vp1auccXody6EoiqmEUYBi7BxtIkKbJs3V4buZPc4f/XUZumDvd1UovP WYFg/L3AMIP6nGvMq8IJEawIUvTnsik= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718929609; a=rsa-sha256; cv=none; b=XwlTTmHecPgqvgeMnCdHR0kqV2QRvj2EYQ0kpedywkSJgv5WLIQUhGzILKNrc9d3wPIhgq yBPgakT5iLPxgCsHTFNXrS4pJ6qZMnbqyLj643cIoKejWiprTV1s2eUq66Bf9/tuSzrYjY gJ0pEOjra/FNGcl5x+uvDh1LLKAR8rg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=nZazUTOT; spf=pass (imf08.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 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45KNoABD032764; Fri, 21 Jun 2024 00:26:52 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=nZazUTOT4MWjA5SIo7bqlbXkVPqxd lPc5kdjhBklD9w5sBhgGhoMzPqsv/6+9xi2YkEhWPxf9YPLt250idRxUj1Bai5vP t8Zm1/QI2qd9x4OCMtva2WQkVxRmC819CV1Jn6F4q7BiqtI5p2zMRqGzyvylMoe4 NHFA8hw48lSHyLYJEjX3vGX4IEVPJ/Ezd607cF3e1s9f7NT/eHCKLqQymmfTUqN9 0G7sBPMI1Ris+bAlk/0Hjg6iGdURYUu/4z/lE/W60GLG1j6r2n80vwIuou+JL6/t 2Xwnqh2BLNT4NlpmrxUbWvVoVKPXE3rAUFSz/xr1O7Y72zz6/npwhQ2oQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yvw8c070w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:26:51 +0000 (GMT) Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45L0QpEX022765; Fri, 21 Jun 2024 00:26:51 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 3yvw8c070r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:26:50 +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 45L0P27B031899; Fri, 21 Jun 2024 00:26:49 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3yvrspjmyx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 00:26:49 +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 45L0QioE56164652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Jun 2024 00:26:46 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7056D20040; Fri, 21 Jun 2024 00:26:44 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4EFBC20043; Fri, 21 Jun 2024 00:26:43 +0000 (GMT) Received: from heavy.ibm.com (unknown [9.171.10.44]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Jun 2024 00:26:43 +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 v6 20/39] lib/zlib: Unpoison DFLTCC output buffers Date: Fri, 21 Jun 2024 02:24:54 +0200 Message-ID: <20240621002616.40684-21-iii@linux.ibm.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240621002616.40684-1-iii@linux.ibm.com> References: <20240621002616.40684-1-iii@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: lBkuMSrPy1rZLOJYYHrXW-DlaDRQ8Mht X-Proofpoint-GUID: AsxR3HdOanE4AiybmDh67tCIRsC6_PQH 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-20_11,2024-06-20_04,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 adultscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210001 X-Rspamd-Queue-Id: 36C8A160005 X-Stat-Signature: h1u865d61icz8teiuo4wuzpuq64cjo6n X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718929618-269022 X-HE-Meta: U2FsdGVkX1/npJaUKw6Bfh6MXV8mx5cD3UBXXPJHdODjNB0abIi+tVeR3kjBTLQhzpwSmQD43aIvi56N54kamkopZvoUomD+ohllEdKAppGNnxs6MF1xh5YJcldvpL5iFnHcskTybt7B2ZE2ctxngHjvfYzBt5RhHzNfjTfZD3d+AxqrOX8Egu9jImp/1o1kKFVxJ95FUMJLECf9DbyVTwm3lXGX2zUC5HmwCq8RJ6gh2dZKBGp2NiwI8iNSVIo166qe7ZxotI/0ia4pVp5HDkWDjyKcFV56sA2BgD7pWRTUgQ8HOiKWFfm9bzQqlMIW/Tl1kABsVyJQk0CB0Nv7zsltpNQH72SRUdbiZo2FfMnx5FDo2sIakRERUs5D9nxzsl2nJFDW8Dk9qTs2RusOgJEVjT+AT3UwUaIkbT1SPI5KWIJG3dvZMK3JHe1nVT/PUcL4k/rfbcpxyVClXSTUap761J082GpgLafwRMGgfUy9gAt/OPVmX1QwWwZb0cjdu98gD7wPQgD7JVHsYd3p4rX3hzPWKyzXWapYEJlzT7betCywvOi2w9uWCXBCyJq1H5pVI2J70uDHTWMDyQyCCOeOJT5eK41eLI2P+6Dppzxbv8xqtrNtpanen6xgxm8PDMrbcnOt6lex+Ae0ct9+FyakXAERWvYf9TkTpeoozxEFb2Isn7PhD5/arz/DcQ9FCLajPb1m+p7L10JTljOx3Thb7fX1H87WoWNbigbGBeLYv9T1ZFe9zkyLe3V7CtYWvASnU/LEA8y6oVT2L5MpCZugbN1yInkJMDxh36h+CY9IbUEAULcnTMBYo7MbKDSsXOkI/2Qyh97TrO4wRvk4WKa46EadurXcXLKpquo9WHywJq2N9I7XJW48tARyyVTtcW4gkJzjLOt/FoPCmOi2Pg7XmnSFLxrQjS6Rrbiygs+g38FjZB1xgOD06V7HPP5RrUYm9WFraItIXnlGgen 4R0jFr2d YBB5UkVdKNAlFukKbG3iciqlpFqOgcOP01XJJo2taWsKO8HqBh8ooNaDYXDCjQXF5fH5uv5IGf2CmBTeMFRrN45L9BrUL4MZuwac3e7+oj2QP0DRDZBaJkCkr89xRVA/1sQ8H8gyo+T5ZsMPseSvriJ4ddGC0Nb048GiDSNTwzuUiOy4sBueWWIwoDDK93Z6MTXf8vICr+aVnKBxsXcUYnctdFNJIPuZdbtQ4676JWk0CWxS7V4SDDsFvo4BY0VW4ahlyZeYMooFxUtQfkGUTDCca3+F5x1Wp9teVxY1fdm/fzHLA2AGhsP4b8QwNAz21WPnX0Uf7+avSu9TJDikHO9VtfU2+8/sWRHqX5GeO7pvFSMbM2oUAPnePBO99w+CiP7ST5Niff7TK3HM= 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)