Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2978002pxf; Sun, 14 Mar 2021 19:56:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjjSKeYH5I+e/39D7JG600z9cLXIP1osFHYm1DPORhtEtnVnyOXqe6PyUMHSdRstWhYU0P X-Received: by 2002:aa7:c345:: with SMTP id j5mr26827264edr.338.1615777001943; Sun, 14 Mar 2021 19:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615777001; cv=none; d=google.com; s=arc-20160816; b=FJ6XSKTqnWuAIbTyb5p5L/2QKZb6qxUJDLqGDL2sEqC7rR6GjLuZoK0xK/M/V3S18l asp69m+L9c89STBTnue2+ZHXwU1IsUjGI1yht88KRwxwxPEGeMx/aSdWaeeGxlwnrn+E DMnC9M3Vt/z7E5qjoIjMuL4tk2eCcdl1st1i0vCREFudSTO6VBveOy3A+4REE2i8o66a Ut6V9cS9Z2lqJNdi6hDcym7BfNcoOnCrRcBl4/R84u7BatVqAK6jy8e+n+l+QWMxs6xE tPNM6CFtfa+KDoDGqrWDjK/zNFnpYDJsxVDr4apk6PQvrimyqgwp8A9N+oBWtBHpGEQk gI9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=TfwgIDtMspvL1SrXH4WOgpQyUnLw8JK846jcaSOMI+I=; b=optGmjsY2VCaAsvHKmqIZX7cv+ZDWfj82C7L22lXjtUKfLd9JVUAO6nFowT7vfovSY 4kAU0NAOpo4h9ZVPByTYg9J+s/sDrq6Tr6qInz3MgUeNMMYccZhn0BbDXPTGj/nua2nu 5p0OKF2a5LYVU6VCsqoGX9zph3pbaq2MGkZGSiKIwpxY5+38/EiHgmwlnemMZeAWBzUc AHaCgMlfqAHy/2fPAm0ADBxl/KyugIAPK7OmBq7kvsH/7C9I+SW0j07kvnq+kLQmB7kU oBhOOpV4gSsSTe5ICkZMRVm+iuoKOiwqFKmxSdH1FdVVnP0l+CS/YdFFaitk1FIlzTZb GFlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=jRtgMWjg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jl2si10059595ejc.488.2021.03.14.19.56.19; Sun, 14 Mar 2021 19:56:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=jRtgMWjg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229570AbhCOCwv (ORCPT + 99 others); Sun, 14 Mar 2021 22:52:51 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:32610 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbhCOCws (ORCPT ); Sun, 14 Mar 2021 22:52:48 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 12F2XlQp129569; Sun, 14 Mar 2021 22:52:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : in-reply-to : references : date : message-id : mime-version : content-type : content-transfer-encoding; s=pp1; bh=TfwgIDtMspvL1SrXH4WOgpQyUnLw8JK846jcaSOMI+I=; b=jRtgMWjgfnJLI7qeGsrxGDpLBx5KI9uKMN8koo+eqHQ7kAkh0gqKu2+2rBzLquwkejEZ r2ziZFH8dPJc7Y0XZOLOx/+DETtIvoaZ49oDnEdFhGZu8m2lFA/GJ3GJHEJEaBzUhPEb Zs6nVF0o7eZpsQ2SHDKBpIeuatf03Z+0gYYvoIf1CIrv8wh1Xy00QnM+Zcqep1Z+rznz E1iEotpH3yDnGSbC1kft9/6e8oyyw5Al5Pl3wBQIq6h2Xr2LgbpU0UBwD/7Uz6seRyrV ap0oo0lvuoAeuhVHi4ql0ReCY0KjPgD0M20tXPkqqgxyyCiEm3/Xt1M9rZq7Xs5e5hHr vw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 379ukebh0k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 14 Mar 2021 22:52:41 -0400 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 12F2nsB3026890; Sun, 14 Mar 2021 22:52:41 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 379ukebh05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 14 Mar 2021 22:52:41 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 12F2qdk9002570; Mon, 15 Mar 2021 02:52:39 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 378mnh1d9x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 15 Mar 2021 02:52:38 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 12F2qKvD17957140 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 15 Mar 2021 02:52:20 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA840A4054; Mon, 15 Mar 2021 02:52:36 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 52B07A405B; Mon, 15 Mar 2021 02:52:36 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 15 Mar 2021 02:52:36 +0000 (GMT) Received: from localhost (unknown [9.206.171.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 871BF601F4; Mon, 15 Mar 2021 13:52:34 +1100 (AEDT) From: Michael Ellerman To: Tyrel Datwyler , Michal =?utf-8?Q?Such=C3=A1nek?= Cc: bhelgaas@google.com, linux-pci@vger.kernel.org, mmc@linux.ibm.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rpadlpar: fix potential drc_name corruption in store functions In-Reply-To: References: <20210310223021.423155-1-tyreld@linux.ibm.com> <20210313091751.GM6564@kitsune.suse.cz> Date: Mon, 15 Mar 2021 13:52:31 +1100 Message-ID: <87o8fl3z80.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-03-14_16:2021-03-12,2021-03-14 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 adultscore=0 mlxscore=0 clxscore=1011 malwarescore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 suspectscore=0 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103150018 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tyrel Datwyler writes: > On 3/13/21 1:17 AM, Michal Such=C3=A1nek wrote: >> On Wed, Mar 10, 2021 at 04:30:21PM -0600, Tyrel Datwyler wrote: >>> Both add_slot_store() and remove_slot_store() try to fix up the drc_name >>> copied from the store buffer by placing a NULL terminator at nbyte + 1 >>> or in place of a '\n' if present. However, the static buffer that we >>> copy the drc_name data into is not zeored and can contain anything past >>> the n-th byte. This is problematic if a '\n' byte appears in that buffer >>> after nbytes and the string copied into the store buffer was not NULL >>> terminated to start with as the strchr() search for a '\n' byte will ma= rk >>> this incorrectly as the end of the drc_name string resulting in a drc_n= ame >>> string that contains garbage data after the n-th byte. The following >>> debugging shows an example of the drmgr utility writing "PHB 4543" to >>> the add_slot sysfs attribute, but add_slot_store logging a corrupted >>> string value. >>> >>> [135823.702864] drmgr: drmgr: -c phb -a -s PHB 4543 -d 1 >>> [135823.702879] add_slot_store: drc_name =3D PHB 4543=C2=B0|<82>!, rc = =3D -19 >>> >>> Fix this by NULL terminating the string when we copy it into our static >>> buffer by coping nbytes + 1 of data from the store buffer. The code has >> Why is it OK to copy nbytes + 1 and why is it expected that the buffer >> contains a nul after the content? > > It is my understanding that the store function buffer is allocated as a > zeroed-page which the kernel copies up to at most (PAGE_SIZE - 1) of user= data > into. Anything after nbytes would therefore be zeroed. I think that's true, but it would be nice if we didn't have to rely on that obscure detail in order for this code to be correct & understandable. >> Isn't it much saner to just nul terminate the string after copying? > > At the cost of an extra line of code, sure. Is there a reason we can't use strscpy()? That should deal with all the corner cases around the string copy, and then all you have to do is look for a newline and turn it into nul. cheers