Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp214952rdb; Sat, 30 Sep 2023 01:20:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHfiycBkK26YAxsmKweScoCORfb12ZLP4nlhRMDUL4PntyT2vqVu6VpfvmNMM7FyLZGQMRi X-Received: by 2002:a05:6358:4188:b0:135:73b0:cc6c with SMTP id w8-20020a056358418800b0013573b0cc6cmr7345862rwc.28.1696062031635; Sat, 30 Sep 2023 01:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696062031; cv=none; d=google.com; s=arc-20160816; b=gRihu8Fn925kXfb49PEsmBp86u8yHsl44rm63FFBjXia9rPelKnpyRmcDoJ2MV27uA ig5AJqz14pCIi+Ueni2ctcrPXFV81tJdbyNFDOJRKiuyfyK4sw+V6RYLPf6PWP/o8f4L ujfYOv8s070dad8HPya8uOEUlVgB6QEbMMBb7xlpeXMCfhLEv1SKCTAJiqFc8zI+CeuG L4HiS1Ytb60Zp8ptmQUA59qoaFlEVvjrzVRtnaZzGYp8td6NfwuIQKBbZ/0y9xsSbSCd ExlQrVcax6KIngD6nzDIfu7CmKFZFnjZdo+T+p2J9N/zQ5adM0HSyHO9dXy5nIHqXv5+ 1Geg== 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=wZup8TW2zGO5Dc5hYWwOfReZg/1sYcAfov7pXVHZroU=; fh=ZE20IZcc825xpXhKrTR39vCQZFR0qTrwp6mgCEEyTO8=; b=M74IrdbBilpX/PtaFSiNa4aDG+8JJMGsPTV/LskwWo+ehZo/Zf18nxEwkvsH7dOV5P zCoPZBvyE96QxKh8Cz950qFyZcomTHRb2/VvgR8rpv80FZGTVmxqJt+nOnxeFGQp61Ss 6S7VtGVCdvn9Bb9vNea5jupBN+W00vlDoOkolTHpVUKBFlYmoa3zG8vZc4KAamJnA5uy mT9yG338t2+P4S0etwYEdoTsyE8X3aq9sC8tF8qLRsAa1a8HDBWdG28upmiBc4arZGf4 sE47oABrK7vgd4SDxkkSaqNgPY0rAueym68YDVI/XEcnY1DJtIY27+uS1F8UQ9rQKeXq KBLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FQS4GMk4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id v10-20020a17090abb8a00b002743618d4bcsi3274789pjr.101.2023.09.30.01.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 01:20:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FQS4GMk4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B5BD282F05CB; Fri, 29 Sep 2023 18:08:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbjI3BIu (ORCPT + 99 others); Fri, 29 Sep 2023 21:08:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjI3BIt (ORCPT ); Fri, 29 Sep 2023 21:08:49 -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 815E2F3 for ; Fri, 29 Sep 2023 18:08:47 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-533edb5ac54so14252709a12.0 for ; Fri, 29 Sep 2023 18:08:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696036126; x=1696640926; 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=wZup8TW2zGO5Dc5hYWwOfReZg/1sYcAfov7pXVHZroU=; b=FQS4GMk45toqzJbDaef9/HiAidci7xJHo6c/WRM64Ey8Q0hx3RsTO1viIYganiiNox q5iAZG36KS6wCtzKxtoL+zBWhCw2z+p2R0cdxOARnR6EMNWaaRF96aDZ518NmUCr57dS b+7k+u83Z4mH/F0BthFQ4zLotfSzZ8EWltKMGXww8AlgO2oQ/20Imj2ladudMyAAqQG3 +hn3d9vAlCW8r2hXl2Py5zOGmjbpu7TIr/hWAwpGvAipItE+kfQCwjmOj8BUD86Y6atp hgYOsXOz+IH1HNgHnxSk5QEI2XhYstgRmWodHhTZxUf9l3dpClPRZ5lCPCBOoTQqcdZd Vk0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696036126; x=1696640926; 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=wZup8TW2zGO5Dc5hYWwOfReZg/1sYcAfov7pXVHZroU=; b=HmV19+RcFpyJoxBlGvh2eLDCwM++HQDUzqvSF/MebmHflj3aHOzTSMG5WuHqMVR72i X8wj8IbwUeTfDnv9Ttj0Ojz1WqOv9kLTefOvkjFu5v+LA4N2J31W2ceIsF+NktEm61xv mAx1kTPuL3JvMYLOXnNo2E9TWvkju2KvIj5KtqPHnU2Nl9i0wPF6nhBncXrWSKtnWxbv Iw6tfrS7Z24Tth1aFyIiKv+Pu65ati9nK6IFO/iM/j200TpxuN6OaPy5VRENwJZIEgS/ ehLky5/3CNunMvDHJ0pEvFe2L/pXm1VqEJmWpCDiYk8gk0+ZWE13JpVPqp9MP2SjmO0W eQzg== X-Gm-Message-State: AOJu0YwgLyctGSHxi4TN0dEPCGIoJQ3H/+jfnZKX+BMftCcMhN4pzPVi OIGzeevXF7UrKawJ4SLbl5CrYVZPRgXEkS23W89KBQ== X-Received: by 2002:aa7:d489:0:b0:534:8bdf:a256 with SMTP id b9-20020aa7d489000000b005348bdfa256mr5227701edr.31.1696036125906; Fri, 29 Sep 2023 18:08:45 -0700 (PDT) MIME-Version: 1.0 References: <202309280610.sLGSPkOG-lkp@intel.com> <202309291040.F201590997@keescook> In-Reply-To: <202309291040.F201590997@keescook> From: Justin Stitt Date: Sat, 30 Sep 2023 10:08:34 +0900 Message-ID: Subject: Re: drivers/md/dm-cache-metadata.c:1705:9: warning: 'strncpy' specified bound 16 equals destination size To: Kees Cook Cc: Miguel Ojeda , kernel test robot , Alasdair Kergon , Mike Snitzer , oe-kbuild-all@lists.linux.dev, linux-kernel@vger.kernel.org, Nick Desaulniers , Luc Van Oostenryck Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 29 Sep 2023 18:08:55 -0700 (PDT) On Sat, Sep 30, 2023 at 2:49=E2=80=AFAM Kees Cook w= rote: > > On Thu, Sep 28, 2023 at 11:36:46AM +0200, Miguel Ojeda wrote: > > On Thu, Sep 28, 2023 at 12:24=E2=80=AFAM kernel test robot wrote: > > > > > > In function 'write_hints', > > > inlined from 'dm_cache_write_hints' at drivers/md/dm-cache-met= adata.c:1729:6: > > > >> drivers/md/dm-cache-metadata.c:1705:9: warning: 'strncpy' specifie= d bound 16 equals destination size [-Wstringop-truncation] > > > 1705 | strncpy(cmd->policy_name, policy_name, sizeof(cmd-= >policy_name)); > > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~~~~~~~~~~~ > > > > This looks fine given the check above it. In any case, since it > > appears the code wants to terminate the string, this should use > > `strscpy*()`, right? > > I agree. I can't tell if _pad is needed though. I think struct > dm_cache_metadata is only used internally? And I see at least the > initial allocation is zeroed: > > cmd =3D kzalloc(sizeof(*cmd), GFP_KERNEL); > > Regardless, for background, > > struct has: > char policy_name[CACHE_POLICY_NAME_SIZE]; > > code does: > const char *policy_name =3D dm_cache_policy_get_name(policy); > > if (!policy_name[0] || > (strlen(policy_name) > sizeof(cmd->policy_name) - 1)) > return -EINVAL; > > strncpy(cmd->policy_name, policy_name, sizeof(cmd->policy_name)); > > > Justin, can you add this to your queue (if it's not already there)? I sent a patch out earlier this week [1]. The line # on the diff v.s the warning is off though. I suspect I may need a rebase if it doesn't apply clean. > > -Kees > > -- > Kees Cook [1]: https://lore.kernel.org/all/20230925-strncpy-drivers-md-dm-cache-metad= ata-c-v1-1-4b75c7db0cfe@google.com/