Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp362729lqd; Wed, 24 Apr 2024 05:01:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU+wJWnsZtT77EJvPQJMSZz2yoW6LcEJNBwePBi5CPC3es2T3Xv6fDETILeM3Xychzi9c7hukXjxUGnLMFNL8eQJcXrWfDtklTYjEKtIw== X-Google-Smtp-Source: AGHT+IHN8MStYFaUCZYixhEt6pDvyoaUe0q3HTvKCmRQKAeRMPq3hSxy3kuvUHL1Z4b0Lf2vkrvH X-Received: by 2002:a17:902:fd06:b0:1ea:691b:3692 with SMTP id mp6-20020a170902fd0600b001ea691b3692mr1669108plb.17.1713960106401; Wed, 24 Apr 2024 05:01:46 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id f31-20020a631f1f000000b005ce030a6460si11013660pgf.71.2024.04.24.05.01.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 05:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156825-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@ibm.com header.s=pp1 header.b=Id80e8du; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-156825-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156825-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 85F3BB21567 for ; Wed, 24 Apr 2024 11:56:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D859A15AAC6; Wed, 24 Apr 2024 11:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="Id80e8du" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8F2E158DDD; Wed, 24 Apr 2024 11:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713959789; cv=none; b=kJq7/AaAZ5GIua2sg+Z9f9FJCL6TsXcV6S9FHjdHD05b9sTVwhtyYcByyPX+fm6sVXG85G/+RrAzVE+nCeoNTnv3bWHEZjPRNHHylGsILVCbV5+VEu2wuaNmqEfEvRp7n20iZA1eF6vT2WVzmsdsLUJZC4xjdlEXMUYqrOQlQHs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713959789; c=relaxed/simple; bh=tAHa0uAP1XOIzwk0meIwhRRVXUzUhQWgzB2b6tqoVDI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qewSW49Oh/Xgjy+uoaVlZkhPNVvXo+YyDqdMLiPs42tDaDHiX2JZ3Eno8K9K+d88FCPjHuf6B18SfV+1zrvKatCz3dJrRjIMKFkasmNJ/UMkoKNjCSCBmkm8cczsibeIMpypfqCNa77d+9Lqoc5omhpxHO/JpZslACftPIanAbE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=Id80e8du; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com 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 43OBqf4c020542; Wed, 24 Apr 2024 11:56:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=XpH7mlduGY+teRfPIZDry1r3MxwXhD+lR2HCJ3M7h20=; b=Id80e8du9KRHgkzMQaMuQ9JzazbKiuyAGb974iHcfri4PgE4w2/QmgBfdkh/FLLn4LEq slJgP6wLd6NmCKlAWqINqRJ7aCEz+kr/wb8DiAmKvSDbm8Si8MDPkmIIHIdN5FlUK5CA Kndcr3Xd9hVkD6HFYLYiZZYwRlwXgnIeFrSHXdtKTLyH0fGGU0JfHZlVZkdyh2qzw8Jh yPDnqJHqHMrpMwnbAORuuLmHCGDnYYMl8TFBda3wNUm7Xd8kCwrfL+u52ZI/lMHblLRX 7LVpJyYvnSrdqPhzC2gnGDG3oZ5gxAnGHcWrRhDGv1wU3TXdIbmQDbjusoaqGgNMTUHX 6A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xq0sag3k9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Apr 2024 11:56:08 +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 43OBu7rI027504; Wed, 24 Apr 2024 11:56:07 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3xq0sag3k4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Apr 2024 11:56:07 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 43O9AlZS005355; Wed, 24 Apr 2024 11:56:06 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3xmx3cj5ym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Apr 2024 11:56:06 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 43OBu1o138732126 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Apr 2024 11:56:03 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 078132004F; Wed, 24 Apr 2024 11:56:01 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 492CE2004D; Wed, 24 Apr 2024 11:55:59 +0000 (GMT) Received: from osiris (unknown [9.171.4.217]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTPS; Wed, 24 Apr 2024 11:55:59 +0000 (GMT) Date: Wed, 24 Apr 2024 13:55:57 +0200 From: Heiko Carstens To: Bui Quang Minh Cc: Jesse Brandeburg , Tony Nguyen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Paul M Stillwell Jr , Rasesh Mody , Sudarsana Kalluru , GR-Linux-NIC-Dev@marvell.com, Krishna Gudipati , Anil Gurumurthy , Sudarsana Kalluru , "James E.J. Bottomley" , "Martin K. Petersen" , Fabian Frederick , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Arun Easi , Manish Rangankar , Vineeth Vijayan , Peter Oberparleiter , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Saurav Kashyap , linux-s390@vger.kernel.org, Jens Axboe Subject: Re: [PATCH 5/5] drivers/s390/cio: ensure the copied buf is NULL terminated Message-ID: <20240424115557.26193-A-hca@linux.ibm.com> References: <20240422-fix-oob-read-v1-0-e02854c30174@gmail.com> <20240422-fix-oob-read-v1-5-e02854c30174@gmail.com> <20240423065052.10211-C-hca@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-TM-AS-GCONF: 00 X-Proofpoint-GUID: uhfqRBb54eWKPef2hDdJnIwSrSgU2j72 X-Proofpoint-ORIG-GUID: gLWakaQraUUUlMZLADf4xlA10NLu8ZwJ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-24_08,2024-04-23_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=767 lowpriorityscore=0 malwarescore=0 mlxscore=0 suspectscore=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 phishscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404240046 On Tue, Apr 23, 2024 at 09:46:35PM +0700, Bui Quang Minh wrote: > > > - buffer = vmemdup_user(buf, lbuf); > > > + buffer = vmemdup_user(buf, lbuf + 1); > > > if (IS_ERR(buffer)) > > > return -ENOMEM; > > > + buffer[lbuf] = '\0'; > > > > This would read one byte too much from user space, and could potentially > > fault. > > > > Why isn't this simply memdup_user_nul() like all others, which would do the > > right thing? .. > For this case, as the original code uses vmemdup_user, which internally uses > kvmalloc not kmalloc, so I try to keep the original behavior. And > vmemdup_user does not have the counterpart vmemdup_user_nul. I can > kvmalloc(lbuf + 1), then copy_to_user(lbuf) and set buffer[lbuf] = '\0' or > do you think I should create vmemdup_user_nul? There is no need for vmalloc() instead of kmalloc() for this particular case. The input string is supposed to be rather short (see the sscanf() call). So converting to memdup_user_nul() is sufficient and solves the potential problem.