Received: by 2002:a05:7412:3210:b0:e2:908c:2ebd with SMTP id eu16csp293381rdb; Thu, 31 Aug 2023 09:29:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuX6q7PV02lDNBu8g/N6ZjwjKvjh/Ko16wz/8MBFCGYE0qSZvuyqNVyvhwwo+qhzDHO/Fy X-Received: by 2002:a17:902:d212:b0:1bf:5df2:8e97 with SMTP id t18-20020a170902d21200b001bf5df28e97mr184098ply.4.1693499384136; Thu, 31 Aug 2023 09:29:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693499384; cv=none; d=google.com; s=arc-20160816; b=czEH5O3PDRL362XLDfqrsGdtvEEBRJ+LOMiZ6MkFhT112io7J/UnEu6Za5+IgeVctI MPyuDG5pWoCnHToz3fUwmy9bWfWkACrtohbo5kmIbh7gZ7PA2tGUfTWqYteuF98XxFBv 7bvxxAcIyoB0R/MtBKQ22so565sJ7W1xGqVOs6uIz0374r+mDtI4xCMiNB7ltw8E+ycE HjsYfc7Bb2vuNguL3PIaKBiCp71LB5Ix3ALgDwAYeqPg/KvjyUBxxM8PuPIG3L6QxcTG Ez77LToAoFNYz9/YESTAx3332FtyRYLTm2BMvenyGs/i7LSbLD4SM2axNwBwkhve5PNP XEhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=gtuDTDUeRzmXZ9hOE+1xBNr+PQwADo/B01Tzo7u5k64=; fh=HQVCzKrxBZmC9az7hf18HdtUuD0IB3mr5Kpc7YxPj+I=; b=FEgfqUK2UUghZFfJi35QfbgHI1h031JY4qI7yjYhP+TjqHykqBrXfrfFeE5l6ek4tC mHoXvW/MkjzdP7idNO6hPnTpqYgPJqRBvQMPpqTq/cS2cPan4+yL2TMTcHX9wD70PtxG 9yniHO8fzLBA/Ians+2AwB5CjbkwJh7PHQUfJp0rRIg5wFoZ/LQ+TpHr2DBJJfHlDlqa MXbXdtuJVZEiW+Zz9p/w0WC7xS4E3uxALwsIh2vIYGAgpW9wgMoO0mFkoRTlIY6gvn/b lIfk4yYL566hyIpbF+gXSCnxbb0uGTqX7q2XMZnS+fdq3Yv4mw9PIyxO3IxS5gP+lijG xXFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iGIOjWFa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a9-20020a170902ecc900b001b841d54b7csi1477719plh.206.2023.08.31.09.29.25; Thu, 31 Aug 2023 09:29:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iGIOjWFa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345377AbjHaNKW (ORCPT + 99 others); Thu, 31 Aug 2023 09:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232913AbjHaNKU (ORCPT ); Thu, 31 Aug 2023 09:10:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A382BC; Thu, 31 Aug 2023 06:10:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1EC09B8229B; Thu, 31 Aug 2023 13:10:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE6DAC433CA; Thu, 31 Aug 2023 13:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1693487414; bh=Tx7w8FI/pLlA3uFq5GwLia/GR2hgOf2fgjsGhZzl+sk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=iGIOjWFaoc2o3+D9pAiu+tKS35mKl+S0jaHg8kypiV3yFq21+2GVITjISQhWfpAdv bCcRVTXC++Bq4bS/DAS9XrufWeAlZf2Z50hk/OFSA35ImHW9DBOmxOEwrl/m/BmpkM 9JveujHt2tgFXJjAiqLHHXP5lvXIKa+o6txV7VcCQN8qEnP6WAMnbiUlfU9KjpZ5tr YCKbxu71rqllAEenrYcz/5UKmN2n+DVJm0UHlFflCh5sIdP4j7KIOCfHFVJ+XdfFTD rDByGBAUoq+TwyJkqDDPbYuC+W2PsII4MlqFItMcYoshcRexmdKL+gG55NqyXn8W1X h9Ot5ry6gTl+w== Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6bcade59b24so692956a34.0; Thu, 31 Aug 2023 06:10:14 -0700 (PDT) X-Gm-Message-State: AOJu0YzeH3h4OxsxfGVO42ZgqsV7r0pqSmQjKzTUrghg0huT+GEbPXte KfcwZtgJhGpQpE9Anlvy3btH4foE/HGW53AUzwI= X-Received: by 2002:a05:6830:606:b0:6bd:bba9:2d63 with SMTP id w6-20020a056830060600b006bdbba92d63mr5298073oti.9.1693487413878; Thu, 31 Aug 2023 06:10:13 -0700 (PDT) MIME-Version: 1.0 References: <20230825-strncpy-habanalabs-combined-v1-1-daa05a89b7e3@google.com> <202308251513.0F6BF9FEE6@keescook> In-Reply-To: <202308251513.0F6BF9FEE6@keescook> From: Oded Gabbay Date: Thu, 31 Aug 2023 16:09:47 +0300 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] accel/habanalabs: refactor deprecated strncpy to strscpy_pad To: Kees Cook Cc: Justin Stitt , Jean Delvare , Guenter Roeck , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 26, 2023 at 1:13=E2=80=AFAM Kees Cook w= rote: > > On Fri, Aug 25, 2023 at 10:09:51PM +0000, Justin Stitt wrote: > > `strncpy` is deprecated for use on NUL-terminated destination strings [= 1]. > > > > We see that `prop->cpucp_info.card_name` is supposed to be > > NUL-terminated based on its usage within `__hwmon_device_register()` > > (wherein it's called "name"): > > | if (name && (!strlen(name) || strpbrk(name, "-* \t\n"))) > > | dev_warn(dev, > > | "hwmon: '%s' is not a valid name attribute, plea= se fix\n", > > | name); > > > > A suitable replacement is `strscpy_pad` [2] due to the fact that it > > guarantees both NUL-termination and NUL-padding on its destination > > buffer. > > > > NUL-padding on `prop->cpucp_info.card_name` is not strictly necessary a= s > > `hdev->prop` is explicitly zero-initialized but should be used > > regardless as it gets copied out to userspace directly -- as per Kees' = suggestion. > > > > Link: 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 > > Thanks for the consolidation and refresh. :) > > Reviewed-by: Kees Cook > > -- > Kees Cook Pushed to habanalabs-next-6.7 Thanks for the patch, Oded.