Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4924475ybi; Tue, 30 Jul 2019 10:31:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnIp28exXHWKLCFKXoLGsoFqUEvl4oql6sOZGaG34PRwtaABO/syZL/8hVZaKvWZePlXNL X-Received: by 2002:a63:9249:: with SMTP id s9mr106475592pgn.356.1564507911517; Tue, 30 Jul 2019 10:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564507911; cv=none; d=google.com; s=arc-20160816; b=dr56YGJWaEN30iOc+SIA0CD9NoBNfy3xA9w9BVSN1C5HJoxs+Z9nocss+3ag+VLaOm tHiuj/R2Z/0kb7Os0ftkXaJipkKVl3oy2DaUAGuaB2mHIEzeX17/iXbBa81cCWpzS96N zkSzApI5qh3ctkcRWvJFbIitAzal+XLZ6pNyRHtYfYOw2tz4rjQioThnDNnIK4mq9nU5 7+vhhBg1XhJ1EROOUL2mrgdaqEzWLfeDv4XNan3FVmhn0E01r7WRlymmW+aiNTpjyroG QI31zZV9t3M6plK8SH1yEtT1Ik0EDe2+Fl28HNTAAOq6dwuaIwXme2P8vGVv+dkKNsae IerQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject; bh=79tPpax+I+tdUQmvlJWufjRNrO08d28oGWyvdFmHjnc=; b=vh/x8jgMUkOIG/kZgSeZ/MOFlfR5BLy4bJGzYpfQOGa/u1bVXFpUv3xifwsH2BYozw qITCDhKy+7HOJIkpoKzyG6oBOEX+w3zJmGThN76vUUNzUdiXUSDdVdx5l1I/6YqRynkq JBee2is/uGjIsmiyL8NkjzIbmY3TJU90fy4kcwNCZuhCRoe7QyxqYG6rCsLH+s3bn9UA Y+n/7E69vEyGRb/qd4Pl//n7UhPJ96Fbzw0msHZq8ypvwxeEcy8qfi94k47JGULGKVHq 03DjY1055nJojYPpiqbCPRKmjtAaS08bcauzHHN9DFApxRwofo6o2KAUfLWBfundIYCH hoaw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d19si28009292pgl.53.2019.07.30.10.31.36; Tue, 30 Jul 2019 10:31:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730884AbfG3O4q (ORCPT + 99 others); Tue, 30 Jul 2019 10:56:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:65220 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727129AbfG3O4p (ORCPT ); Tue, 30 Jul 2019 10:56:45 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x6UErli7110338 for ; Tue, 30 Jul 2019 10:56:44 -0400 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0a-001b2d01.pphosted.com with ESMTP id 2u2nnt79ar-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 30 Jul 2019 10:56:44 -0400 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 30 Jul 2019 15:56:41 +0100 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 30 Jul 2019 15:56:39 +0100 Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x6UEuci351446036 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Jul 2019 14:56:38 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 906EF2805E; Tue, 30 Jul 2019 14:56:38 +0000 (GMT) Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CCA2E28059; Tue, 30 Jul 2019 14:56:37 +0000 (GMT) Received: from jarvis.ext.hansenpartnership.com (unknown [9.85.131.103]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 30 Jul 2019 14:56:37 +0000 (GMT) Subject: Re: [PATCH] scsi: 3w-sas: Fix unterminated strncpy From: James Bottomley To: Chuhong Yuan Cc: Adam Radford , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 30 Jul 2019 07:56:37 -0700 In-Reply-To: <20190730084047.26482-1-hslester96@gmail.com> References: <20190730084047.26482-1-hslester96@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 19073014-0064-0000-0000-000004047A97 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011523; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000287; SDB=6.01239635; UDB=6.00653626; IPR=6.01021048; MB=3.00027958; MTD=3.00000008; XFM=3.00000015; UTC=2019-07-30 14:56:41 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19073014-0065-0000-0000-00003E79B900 Message-Id: <1564498597.4300.10.camel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-07-30_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=728 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1907300154 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2019-07-30 at 16:40 +0800, Chuhong Yuan wrote: > strncpy(dest, src, strlen(src)) leads to unterminated > dest, which is dangerous. I don't buy that. The structure is only used for the TW_IOCTL_GET_COMPATIBILITY_INFO ioctl and all the fields for that are fixed width and are copied over as such. > Here driver_version's len is 32 and TW_DRIVER_VERSION > is shorter than 32. > Therefore strcpy is OK. The best practice for copying a string to a fixed width destination that does get printed within the kernel would be what the 3w-9xxx.c does strlcpy(tw_dev->tw_compat_info.driver_version, TW_DRIVER_VERSION, sizeof(tw_dev->tw_compat_info.driver_version)); But as I said, it doesn't really matter for a fixed width field that's never printed within the kernel. James