From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 517E17E4 for ; Sun, 24 Sep 2023 03:37:04 +0000 (UTC) Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63D7310D for ; Sat, 23 Sep 2023 20:37:02 -0700 (PDT) Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-57b68556d6dso1982924eaf.1 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=odeo/qGYIOw40u1Y58Q1rNmIkmwODcoUJhvgYZ7OZJ/qcxwlKvFyl/TlglIW4ioDoZ c+BLhO2+lNdMJrNFUZyQVHTX/T0so8AQo2mg81DE0p1hAOnHiEwbq2XZIji8eivh6tU3 ncTvpaWtiGmyKF+jCgIwKRnQImj3GgTBfZ1vyy5tkQT7+BBBnViAwd27sAhtPRx7mAyE nP7FcWreef6gEnXF9Vq7faLrsfXRUFNxJX5KJy+/kZG1a52LrPI1oiAN6zAlxNXKjy1X e74V4ZRH5IPTuJcLXUDWX8WBD3P/fJOs18aSbKRDRWJQ06VH5uuB/zkGM6WgkKp6iQ3h k+kw== X-Gm-Message-State: AOJu0Yz+zEfHBxFuYbKB30fCtOAijvNWXnOBHF7w7R3dmtbcgDHgKdec q2zDdeyiA2OeIoi0UZIjYWw/IA== 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> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net 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