Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp607803rdb; Thu, 30 Nov 2023 13:13:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGncepK68qA+uaVFj8kkLEaoIJtYtJtddMTw5BvffbE3WZkKwJt/vENw7FM8FpmV706gzqD X-Received: by 2002:a05:6a20:1aaa:b0:18a:e0de:dd51 with SMTP id ci42-20020a056a201aaa00b0018ae0dedd51mr20939396pzb.26.1701378826517; Thu, 30 Nov 2023 13:13:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701378826; cv=none; d=google.com; s=arc-20160816; b=N3602Ahy7jACfur72csAwXKj62ulkABrlXnM9YTijaolv3BspgAWVwqWKmArSwp/eq a4sc2UYk1M2VSRjxF5BNbWNYIidXP5YX6gg1Q8gnhjRmlCXBsrnqx8SjeVn+A9sn6OtW evQiQOfBl0yE5cRRj1vuyqVliIEeKHrhzqddd0gDqoDpZj5tEu8bVXUZYhSyoXmEl/PW ehM7GnftSYUWMARSwMbutDz/fnhLurib4bjt0KY7XkGlpT2pyj8v0GaXYi09YVucZJI0 3GXW0UIbsrxO3K3VcISMHoV03PPwyub4fuBLSVg4M+XW5GK7BV8TOfrkQ5lnZR/DFGeB wv2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=fidcjtTW722GJ2IM4Au/VykloMhm7RTaqk1o/atYAEw=; fh=xCJeqJeMoFnHEkHK6CNL/rrIGzxgKOjqKfcpIXmGfAA=; b=RaVfjW08+q+wZVMYF8w0usynwKsXqRbDRow7VJu+/3MEqpCgTFymNHaNivEmAnbrEo ZOatu++1uBDtAJ+IcEI6ofJv7DvCDU2DgRadc3zgXNaqPIJYgbVPUDEGXjjeM+SbqrfS 4PrQjZINmDXZAWKuqawGLm4e2YMkxL5a2pJrrf5F++CEJzn5Ty6N5Qz5wlw8hNf2w/kx y8nnTuYbUVtCahzaCkAl0KytrtCGF8/sFXUVlIWyxJjRQMneQXVRJR2UZ6vKJ/MvCLxb 8QzmGQE2tnGfNho1g85rVxWkYcAoj8QiiaIpPZ3Xu4dGLRKeFUFj/C3j72jx7KOWpFwD Nh+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DDVdCf9N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id i17-20020a63d451000000b005c626072edfsi2073752pgj.773.2023.11.30.13.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 13:13:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DDVdCf9N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 013D3801B3D7; Thu, 30 Nov 2023 13:13:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376829AbjK3VN2 (ORCPT + 99 others); Thu, 30 Nov 2023 16:13:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376827AbjK3VN2 (ORCPT ); Thu, 30 Nov 2023 16:13:28 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 843E3133 for ; Thu, 30 Nov 2023 13:13:34 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2856437b584so1261275a91.3 for ; Thu, 30 Nov 2023 13:13:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701378814; x=1701983614; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=fidcjtTW722GJ2IM4Au/VykloMhm7RTaqk1o/atYAEw=; b=DDVdCf9NdUIkcLpOb1uCiufbtpeh1yATfi7M2x5fsKQ3TpKUMymd9+UK7MZsvW2PMt SmbZiB2YwKmbYSMt4ybSAE6aCvTj6SaK2/P1iFmPc4BdvZVajNqUqK8AD+UjsaJdRMt8 j1s2GuYw2ebHozsoahOJfdRiG7VgPikxAZ/4Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701378814; x=1701983614; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fidcjtTW722GJ2IM4Au/VykloMhm7RTaqk1o/atYAEw=; b=luauQkl1jXonJcRQ98LV+Zb5DHhGx08ihyw1iE56OhxW9/I9BS7PfjgM55+f0BByjY ywHFreZbLb9y9CsOHt0CnJJ028S14vuVRIw/2dK4pMslNUNJ8mfoYyDD82RkMEOtusSE xXiXceb4bi6WLGYjdMkyR835WB6Z/gcqieh/WipsgKqwmtghH3VVYUzNWLD96CjFvmif iZiALE5/xgcmqMh8m19VyVjW8HnlbuzsR2FnlUTLdFPgwj4yJhtvaa/R1vZlnwU/y0OA aDcqIDTuss2R3HP5zL1efo1KDmow2oFQlgG2Eed4L9mz0QwwbzxUTj4ya/8C9l83fQ6j nOXQ== X-Gm-Message-State: AOJu0Yy225O+dtSidXut9GRZVt9RU8zMMjtOS4I1W/73x/JAn9N4ycJS jC8XI5ccadQ4OKmQkduydkgWnA== X-Received: by 2002:a17:90b:4acf:b0:285:a160:df1b with SMTP id mh15-20020a17090b4acf00b00285a160df1bmr19079170pjb.7.1701378814029; Thu, 30 Nov 2023 13:13:34 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id gf18-20020a17090ac7d200b0028098225450sm3743947pjb.1.2023.11.30.13.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 13:13:33 -0800 (PST) Date: Thu, 30 Nov 2023 13:13:32 -0800 From: Kees Cook To: Justin Stitt Cc: Tyrel Datwyler , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] scsi: ibmvscsi: replace deprecated strncpy with strscpy Message-ID: <202311301313.6248EF5E@keescook> References: <20231030-strncpy-drivers-scsi-ibmvscsi-ibmvscsi-c-v1-1-f8b06ae9e3d5@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231030-strncpy-drivers-scsi-ibmvscsi-ibmvscsi-c-v1-1-f8b06ae9e3d5@google.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 30 Nov 2023 13:13:44 -0800 (PST) On Mon, Oct 30, 2023 at 08:40:48PM +0000, Justin Stitt wrote: > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > We expect partition_name to be NUL-terminated based on its usage with > format strings: > | dev_info(hostdata->dev, "host srp version: %s, " > | "host partition %s (%d), OS %d, max io %u\n", > | hostdata->madapter_info.srp_version, > | hostdata->madapter_info.partition_name, > | be32_to_cpu(hostdata->madapter_info.partition_number), > | be32_to_cpu(hostdata->madapter_info.os_type), > | be32_to_cpu(hostdata->madapter_info.port_max_txu[0])); > ... > | len = snprintf(buf, PAGE_SIZE, "%s\n", > | hostdata->madapter_info.partition_name); > > Moreover, NUL-padding is not required as madapter_info is explicitly > memset to 0: > | memset(&hostdata->madapter_info, 0x00, > | sizeof(hostdata->madapter_info)); > > Considering the above, a suitable replacement is `strscpy` [2] due to > the fact that it guarantees NUL-termination on the destination buffer > without unnecessarily NUL-padding. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt Agreed; this conversion looks correct to me too. Reviewed-by: Kees Cook -- Kees Cook