Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1189829rdb; Fri, 20 Oct 2023 10:50:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH9IMS449Pb2fSzCLORYgmBYhFlevWzefSdqgcp7kb6Z3qhVCRVGCcfnOUU22KmcVU1UWkX X-Received: by 2002:a17:90a:f691:b0:27d:153a:8894 with SMTP id cl17-20020a17090af69100b0027d153a8894mr2488829pjb.45.1697824203852; Fri, 20 Oct 2023 10:50:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697824203; cv=none; d=google.com; s=arc-20160816; b=j9e5+4yAd7HWXcvnhlMqKHWjTGC30wkS6gYg/jsmna1SDITSKSXEQEPXGOsKSp0chd WlyXtgrX7hgVq10HNx/fzNs0wM7OUMCmntp9JGtlJXY3XKWaysP9BCA6RfJOQo2Erl96 wLtQsN1EqVptddKhkspuk2zjScGWevptrBk86oBPhbDglpBDfiH3tAtA+Ozo1bHodjLF q79p7ow9Y2bi+xYYVY7wDBg1s64szBn1frfKNNB4piOnYTWxwefleWoGDJFisEySIhxl 7htPh1jM4d/2GX0ytAwJFTsn9w9xloyiBLky37374z4f0/DhDIBCQs9rZVdfqhl9J+R9 Jp0Q== 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; bh=6022LTmUsw31aRpnEsgzFNb96RLfVadyJ/D6/Aimd9s=; fh=oFTHWg7xOPf1yZ/ZX7N3HA/q2mguTPqQlYR6xeKzchA=; b=fOsI4lY66iABqoFn8Oco4M94PaNtJ7tSuKTu4sP7NrqRCE82lGrNBnhmfg4EXJVMFc SlUp1jS03Ups69+T0sWkHqlglga9xdmwnI0a0iYoMG8EaPaF3GlGAV6ahdIrbvCFegrm faycnIsdocy6LEvVujpWjuiflRucHvshEWvpcgdaPFVpqzwAd8RhU2XlmS9xIVqI/rXD q2kpV05JfgL2dZfMeInfuxzty2Iy5LRYe0ygW6dG83kvAkRzkLKo42zAy83Q3Ar1YcGV UoShoyfxbjM0gcOT1tPxj/ULyMIkcig1I0SYUkqY3RaWAFw8fmxdH7hq+lV0qEg40T7r /SYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id s1-20020a17090aad8100b0027d0c3507eesi4940678pjq.32.2023.10.20.10.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:50:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 47C1383A2BCF; Fri, 20 Oct 2023 10:49:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377713AbjJTRth convert rfc822-to-8bit (ORCPT + 99 others); Fri, 20 Oct 2023 13:49:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbjJTRtg (ORCPT ); Fri, 20 Oct 2023 13:49:36 -0400 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E70A0D71; Fri, 20 Oct 2023 10:49:33 -0700 (PDT) Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-57de3096e25so98332eaf.1; Fri, 20 Oct 2023 10:49:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697824173; x=1698428973; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=djo7Gv3TAmGl0r7mxIaBCLdombc4a5LIQixNSwzrvLk=; b=F1kZc6JGYhYVxrh/IvSP4teU5mqTOu5dyn8P7QBx+RcY0Ydkt8M+ZjBoSupsF2lHvk 7yMa9csaKY3/d7oVCMTkqOCgC2JIyYRUGFoFgg9Ngn1Rewgkhga7Lv1sd84612X6NpuC kCzJWGzhVJDLsULjz77t/irLZx2QPl2/ruAIsilWZFEAWFbAJcui1F/C0Xc7yb3ew5YM uEq62Duh/rV1D/4TrJgFQKw3ORli4GjoCYCBnTNKBwaEPLQxAq101zurOm9fO2Gpyi5W XMmG7/Sx+eFR8P4oxwErqcdd1Fru0qQGK1YNWIv3VHy5LoNAH+wJCOMvGR1HelFH9sGq Nv7A== X-Gm-Message-State: AOJu0YwL9MtAkQphXtlEAuvSZwVkr2c2XQX6EjjBsnR1VnLsgM//0I98 uefIAbey6I0FKjgfu4XAh1gW5UrlfC2m8AqFpyU= X-Received: by 2002:a4a:bd18:0:b0:581:e7b8:dd77 with SMTP id n24-20020a4abd18000000b00581e7b8dd77mr2986747oop.1.1697824173256; Fri, 20 Oct 2023 10:49:33 -0700 (PDT) MIME-Version: 1.0 References: <20231019-strncpy-drivers-pnp-pnpacpi-core-c-v1-1-4c634a73bcf3@google.com> <202310191606.93920741B@keescook> In-Reply-To: <202310191606.93920741B@keescook> From: "Rafael J. Wysocki" Date: Fri, 20 Oct 2023 19:49:22 +0200 Message-ID: Subject: Re: [PATCH] ACPI: replace deprecated strncpy with strscpy To: Kees Cook , Justin Stitt Cc: "Rafael J. Wysocki" , Len Brown , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Fri, 20 Oct 2023 10:49:59 -0700 (PDT) On Fri, Oct 20, 2023 at 1:06 AM Kees Cook wrote: > > On Thu, Oct 19, 2023 at 10:47:58PM +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 know dev->name should be NUL-terminated based on the presence of a > > manual NUL-byte assignment. > > > > NUL-padding is not required as dev is already zero-allocated which > > renders any further NUL-byte assignments redundant: > > dev = pnp_alloc_dev(&pnpacpi_protocol, num, pnpid); ---> > > dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); > > > > 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. This simplifies the code and makes > > the intent/behavior more obvious. > > > > 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 > > Looks clean to me! > > Reviewed-by: Kees Cook Applied as 6.7 material, thanks!