From patchwork Wed Jun 19 15:43: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: 13704224 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 BF415C27C53 for ; Wed, 19 Jun 2024 16:19:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D3466B0182; Wed, 19 Jun 2024 12:19:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 570D76B03A5; Wed, 19 Jun 2024 12:19:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28CAE6B03A6; Wed, 19 Jun 2024 12:19:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 054866B03A4 for ; Wed, 19 Jun 2024 12:19:14 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A086F1C086B for ; Wed, 19 Jun 2024 16:19:14 +0000 (UTC) X-FDA: 82248147828.14.F3F85AD Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf08.hostedemail.com (Postfix) with ESMTP id 4686C160024 for ; Wed, 19 Jun 2024 16:19:12 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=UdmUX2rS; 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=1718813944; 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=6VbhKW4/JlLlDUdh+z2VD+4xUKXf06nTck1w/gjoiArFXQGzoWn46rSPTwfqZhYwNOERmY 8Yl2jUHHKpCfRTBLckG6SUBixfr4qgDKEnTwoiZAI4vfvhFRKUS5D4t6ubS27T3BJFGayj VOOeKjXBjGyOCavfEwgV0E022RIppQ0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718813944; a=rsa-sha256; cv=none; b=46+kp7LFJoXvizpYnJ9iGglc8nbNzv+QuMxYocLQN5oOtFG9DEYw6+S78zhsWOe5VBIPYG 6ofQ8f+qJ5vDKYXhvm6dFd3YAgtJ04ohOKoeaHgFDlfI06JWumiDk3qkjcDLhGv6HT6/Cx DSGhgll15FGRbYKoAAS8QB4O33PPTW8= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=UdmUX2rS; 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 (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45JFSHmo028054; 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 :content-transfer-encoding:mime-version; s=pp1; bh=pcK1rMwKAY+PK 8Ytyz/2vRX/RRHh9XTkiYTIv46ktrM=; b=UdmUX2rSpKmHMqb23d3wqtyA4QhXm tzewLx/jNvZc4YOljvmcEKgMsDjI746+/DBYF2f+7qQ5dnSKydMAN+omjAUzBkoT B+UUTonE/Ay+8NaWALbBUbJLgjxVSwaQ5yr5Y11761JyDlPeoEg0AaFFDphzKFfK FcDJvO9N1Bc91Zk7SNcJ3kuCgPgkzLmqNGUfTjrvVNuVAuhbGo3KDnYd05x0F4Gi SoV4+Z/R2TyNm9N/aofoRRBVfW1fw5/Z7MsLAQ7rUSYWt0IBO7Y85/eKl/zGLvJo nmxkSWTwZBwRrckRvDuRVknN/BnATEgPwyhtuDZj3g1RyAHlaOK2eGMcA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yv20g81kg-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 m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 45JFjl9B023058; Wed, 19 Jun 2024 15:45:47 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yv20g81k9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:46 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 45JF4DXW006227; Wed, 19 Jun 2024 15:45:46 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3ysn9ux8mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 15:45:45 +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 45JFjeaP54788530 (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 7B54C2004D; 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 2C0B320065; Wed, 19 Jun 2024 15:45:40 +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:40 +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 19/37] lib/zlib: Unpoison DFLTCC output buffers Date: Wed, 19 Jun 2024 17:43:54 +0200 Message-ID: <20240619154530.163232-20-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> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: fNSA7rxQcjUO_BxsfnhTGdmZOWmRr0mq X-Proofpoint-ORIG-GUID: 7QNT392Ow3-clchJoP3ZfMKSmByGf6eo 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-19_02,2024-06-19_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 malwarescore=0 spamscore=0 impostorscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 priorityscore=1501 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406190115 X-Stat-Signature: war7gu1r896554j5kwafizn8s4upus57 X-Rspamd-Queue-Id: 4686C160024 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718813952-547406 X-HE-Meta: U2FsdGVkX1+MMlRWkFVjMeIECIxh/5BTUmOOYf1n+wxtvE6DFZr7s+UDs91yS0LH2PPw4u52Ip85xuADM4tjWZa4NvgXwpxc7h4vev/JM3V4tuubhGbQxZnWEj4H+G2I1nuiYNpztT9drbZXEB0/PLYlldwCuOE3wF5+QT2abhrhysmUX1FKLQAdpieB3qQDnJFOoud0JTa3SCDJeIVo5HeKK/GD9TvcmewZG/7RTPhn6hMvWN82lCZG8EK3GjucPk9b0/NJpujYBzbshjhNg1BSUtAklz3qmhI0SxeA67cDTFccXtk6OHOSdMqizi3rCbPy23Q4B91kb4vVBfyJ7l+mG9LJQiZZB2o5voYP/tbLANhJyORGqYr7u+gxQX+Yl5Yeu/KCqtJ5Dcg36Oe05rZEopXBlrVGTDQ85zSAemv4MXEM7mWwoaIDLHd4MWGysykUwKS6j1NPdEU8Twg1Aih0L4AqUhogGdZAX6bhGwuSELzycPDGjTz9NqNbqwsMLKWzNphXymPHgOxIF92lo0jd+WnOYmcrt746PxP2HEC40qNV2R0Vehz/kG17VsIqqNC/hG/4KFn1VaCnL4l1TIvxEoMdIk1RUntJc8G+rvL6eVcUXOFmy51RHt8x17c0ZW26TOWXtfU+pfiSLU6dRTh51QCwgbNCi6DCMnLGrMoV5LZt4R3BdnlvNfBuI//wpzpfZEx5LRbxkeeS/HIXkt25KhaW7KGicwUm0Ns9mB+JsXFrT+pp0zmxuWGs8Wjms0rWs+Bzsyj7PMUONOOedXahphtFwyjhAnMUS5FUhA3FhHsfESjbm8OVRgK7BbQtA/iyoCi79NXhWdlDHOC8dQv+HukvU+3P5Q1TcRY4htbUEE7VomUc7hU0lU8p0njgYdPo4pAjZXFgIp4KWw9C7l0XrsKlAYT7mlKvk/hH7ad2DEiYNXHAMWH4YdjpRwzgFuVzZeX/gLa84t33M6S HXGucLO3 UuNyRNocTxm15GS0dEd6lcU++cr9hxB5umAXfifdj1V6/u+MpnsKgfDfZojSPCDLwWFpotgziMdc73oUyLI4sgxR3C7Hp6YWdi7ThPg0GS4naZPTBxIsyP3tg2qkLXy08KpEXfv/3FB3Bi5l/eSopFOq6kkrr1ODowi+w8UF9fwq99rELxhwhspqMfzUp1Hk2fjKD5Y7+uxW4fBow1lNsUfXflua4xFeOr6Fe7lfPZk3/ESblzknb0xtDz8FbDPuicFp7WiVv2L5ijA4OgYELIDQDwKXMU7fImcxXa6hwoisq7z6GlRVm6xt6Rze7w9RYQrDDEAw/mX3YndLn6sQIC/KNhNOrbVsomAzBbI6voUbalOBsnS1YFXKENC4tsHMdmDzP 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)