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 4453BCD13D1 for ; Mon, 18 Sep 2023 07:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239315AbjIRHEm (ORCPT ); Mon, 18 Sep 2023 03:04:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240033AbjIRHEU (ORCPT ); Mon, 18 Sep 2023 03:04:20 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F5A5100 for ; Mon, 18 Sep 2023 00:04:12 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-530ab2d9e89so2516792a12.2 for ; Mon, 18 Sep 2023 00:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695020650; x=1695625450; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mxanxzBzBYAY+nwMQabQhY93f4nqr/QEo3/ykSA6yhc=; b=txTzqw05xgM4j5/K/Sxp4qY+OpBZrKBE/DLmTuPbkxbZmyRqiyzF1eDl6CqxVHmLel ic+TBlqfy1Rd4LDqHuJJEsmEo27O/FFpjCI8l83zOsWBEmQfvdHxbm9OD8QV2lf/ABO4 EjB1icaqdYX+dLgUMjxbGPNoE2at0c41UPQkSF3+TXVlrHAd3r/nB6dfz99/cRyJMsSr hn15RoVSpHmYh1hhahA9WU7CtbJtzp9qRl6k6iE1vd+CWXTyWnddOQI3Wt7ejqs/nhR6 DQyTW4hfmIWg8Rm4AAUpSRWnerWOTELLeRpSm+g8ZZ1Nn9xJ4lnuDL293hvkh+b54960 ycEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695020650; x=1695625450; 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=mxanxzBzBYAY+nwMQabQhY93f4nqr/QEo3/ykSA6yhc=; b=kRJB4u6ly13KibkS98FwWcdvk3SruxKWyBZdP1fZMLONSxaSnCjO5y+AqlQNBjkXuB QnnRpsZvpB4foL2nFP34t3wgy5E8372ll+aEdOJ4qDMPRq+PpAwU/4wPonIhvk2jxM3s V2xvHcVtm9XMbx5FHVvsnfa84oi8XDnRu967EocxtZFtiETzZSmuzrleOcqVugmopTgd g/MxxWrWj2Df3U25sb5Dm0DoWe58dJuO1wyLHz5Oig4PvZzQWkAuKBGXFcv8quAILn4o Mo5Lotp5LmZubYEHz3gHdoo/vAbtoUo18FosApyUZwZQlnI5ZoUcInL0A72ZQcgjfJzG xr4w== X-Gm-Message-State: AOJu0YwYl2ITeoDPfoOqXdl/fgXPHyM+/UMmgaa/RJsXbvIQ1FEmN6G5 a1/bgLkA+Crtohx56RlDnxO6+sXVKvbh3J2TQGX/Dg== X-Google-Smtp-Source: AGHT+IHqikerTXA3+6J11m6jsjTlogmeIfrd2oscuOGRKrp9MkDG9Hp5jziyJnV6mEtXOrlAXSe7OBc2GyeiW4QrMsg= X-Received: by 2002:a05:6402:3207:b0:530:c3ac:b684 with SMTP id g7-20020a056402320700b00530c3acb684mr6094984eda.23.1695020650534; Mon, 18 Sep 2023 00:04:10 -0700 (PDT) MIME-Version: 1.0 References: <20230911-strncpy-drivers-block-aoe-aoenet-c-v1-1-9643d6137ff9@google.com> <202309142019.23A7D80A@keescook> <6338fbac-0177-43eb-be4f-7c586956953f@kernel.dk> In-Reply-To: <6338fbac-0177-43eb-be4f-7c586956953f@kernel.dk> From: Justin Stitt Date: Mon, 18 Sep 2023 00:03:56 -0700 Message-ID: Subject: Re: [PATCH] aoe: refactor deprecated strncpy To: Jens Axboe Cc: Kees Cook , Justin Sanders , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Xu Panda , Yang Yang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org On Fri, Sep 15, 2023 at 6:36=E2=80=AFAM Jens Axboe wrote: > > On 9/14/23 9:21 PM, Kees Cook wrote: > > On Mon, Sep 11, 2023 at 09:09:07PM +0000, Justin Stitt wrote: > >> `strncpy` is deprecated for use on NUL-terminated destination strings = [1]. > >> > >> `aoe_iflist` is expected to be NUL-terminated which is evident by its > >> use with string apis later on like `strspn`: > >> | p =3D aoe_iflist + strspn(aoe_iflist, WHITESPACE); > >> > >> It also seems `aoe_iflist` does not need to be NUL-padded which means > >> `strscpy` [2] is a suitable replacement due to the fact that it > >> guarantees NUL-termination on the destination buffer while not > >> unnecessarily NUL-padding. > >> > >> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#s= trncpy-on-nul-terminated-strings [1] > >> Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.e= n.html [2] > >> Link: https://github.com/KSPP/linux/issues/90 > >> Cc: linux-hardening@vger.kernel.org > >> Cc: Kees Cook > >> Cc: Xu Panda > >> Cc: Yang Yang > >> Signed-off-by: Justin Stitt > > > > Agreed, truncation is the current behavior, and padding isn't needed. > > (Or more precisely, it's already zeroed and this function is called > > once.) > > > > Reviewed-by: Kees Cook > > Change looks fine to me too, but for the love of $deity, please use > a proper subject line for these kinds of patches. It's not refactoring > anything. > Fair. Perhaps "xyz: replace strncpy with strscpy"? > -- > Jens Axboe >