From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A3D0CE7A88 for ; Sun, 24 Sep 2023 03:38:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229902AbjIXDhK (ORCPT ); Sat, 23 Sep 2023 23:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjIXDhI (ORCPT ); Sat, 23 Sep 2023 23:37:08 -0400 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 632FB10A for ; Sat, 23 Sep 2023 20:37:02 -0700 (PDT) Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6c4e30a3604so188076a34.2 for ; Sat, 23 Sep 2023 20:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695526621; x=1696131421; 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=+YGwlZ8VYRbph25A8ZUwhbUOkgjuB1L7dZb4bEWDxTM=; b=fZSt2AkkJ+oF2xyOjmzFxg4Wcvw1EgKwVZqbJ3ER5PDmzvq4MFmiMZfxvhknpfWPJ/ 9rEVo4a7x9O2gakRVXLoL7XRAodeqGrRL9tcJwJ976z4GYNbPcQGJac+V6h54CN1eq/Q 7QU+GJnyoqNzHvDwzSB3OPvqkXGRYE4hqK5fc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695526621; x=1696131421; 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=+YGwlZ8VYRbph25A8ZUwhbUOkgjuB1L7dZb4bEWDxTM=; b=QlCQtZcYlKSeUG6ENmjvZZKWfgwgOJGHb5Tz7RS77OB9TMVcmsOCEsYHv3nkOFZ+o6 HCIKZeAYki1tBORHzNQYK+OQBFd7Pe+0kT9A4g8T96GmoxywfQxPaYL9pk7X0vBwOL0B cXn3Ajv2/7zh1SKWBDP9FXvDXSx5NR7XCDzkN2gGRWkzmNy1c9ATBblbHUqY2fnSDWPe z2vWqgREYNtAwL/Zg8151h8sZoJxFwgV4JoJy03LlKLd24XE0JVWUQmTIZwehSiormvg CRGEI7zacv+t0rVdH6gMgb4sV2DP0JmlWMI7zXKfgTm3NS/1LG+0ztIq7quABYvVl1kk 3wDQ== X-Gm-Message-State: AOJu0Yy2ORHbfgtYuv1KDcW9dem/S+UfLJIlX7EGItFmvknktuDdqAza q5i6K5/EaP1uFWw19+brenyRNMP4Gj+OYkrmEZY= X-Google-Smtp-Source: AGHT+IHGvXtZMAzyJXO8XVi5BpOg1ItWln8tC/mFF0KbOa2hwtha80KVkI6q/MoCj1OIZSeFEffF3A== X-Received: by 2002:a05:6358:341a:b0:134:c859:d32a with SMTP id h26-20020a056358341a00b00134c859d32amr4772563rwd.25.1695526621603; Sat, 23 Sep 2023 20:37:01 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id oa10-20020a17090b1bca00b0026b46ad94c9sm5684837pjb.24.2023.09.23.20.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 20:37:01 -0700 (PDT) Date: Sat, 23 Sep 2023 20:37:00 -0700 From: Kees Cook To: Justin Stitt Cc: Karsten Keil , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] isdn: replace deprecated strncpy with strscpy Message-ID: <202309232036.32C3C37@keescook> References: <20230922-strncpy-drivers-isdn-misdn-clock-c-v1-1-3ba2a5ae627a@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230922-strncpy-drivers-isdn-misdn-clock-c-v1-1-3ba2a5ae627a@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 22, 2023 at 11:58:06AM +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 `iclock->name` to be NUL-terminated based on its use within > printk: > | printk(KERN_DEBUG "%s: %s %d\n", __func__, iclock->name, > | iclock->pri); > > `iclock` is zero-initialized and as such is already NUL-padded which > means strncpy is doing extra work here by eagerly NUL-padding the > destination buffer. > > 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 Yup, looks like a clean replacement. Reviewed-by: Kees Cook -- Kees Cook