From patchwork Wed Aug 9 01:06:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13347272 X-Patchwork-Delegate: kuba@kernel.org 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 9F8E1633 for ; Wed, 9 Aug 2023 01:07:41 +0000 (UTC) Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 859CC1BCF for ; Tue, 8 Aug 2023 18:07:40 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5840614b13cso8867977b3.0 for ; Tue, 08 Aug 2023 18:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691543260; x=1692148060; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Z+tC2OHCgG5XmqiAIey5dLzPjagreIQB12mmbHFSSNo=; b=5JRTgmSsbAoRmHzig2ooFuZzDECsMi9JEIoaVYPweJLMD0+XXzlzcJt8H9fsFmsAnJ EfCDpuZIUrACTWFeTO+popab/TH0zhMmxgdHI4aqx4VnIEK2ZhCooYIl4kN1hxgYWMC+ 9TX6rmB6YqfYm7DH+iukazZ2O6DXiOG8t2n7/TTdMW2Oa9DNustLZ9yg9+pn50Xahhia BbbZZ3Iq4rcAOk1eHuS0ec2RaoJ/1v/BBVcqa1F6TLNvETcA5Z8gJ0JjVwcuaDVBVdbP IQczCbssQ/4eAtUSD4VeHNVc1qBo6gUNo//DbTKx490J4SVtBHv+kn3Rw5kbhdebliTv 2sOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691543260; x=1692148060; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Z+tC2OHCgG5XmqiAIey5dLzPjagreIQB12mmbHFSSNo=; b=QfGTWxkzIfcx2+KxZJPDBy9E5v3S6q7SGBJp/xRsy+5p9BwC1Y/Nj9EIzHg1klhbOe yUsqdQ3eVSuGkOtUQTLIvFNyKfY+WmmR+zM1fdw61g9OfxWkH6muQXUanxmfvTdkTp6R 7eWYnCKgAp8pfDAtNk9pvleaaEAnVYPYrbnyqk8Vtkk1JrRjBwDfF9g7vLlvNp3Ulrym 3o7JbO0Sloohmhy/7+DmiQz+3eaPWBcavMtK6zhudwo/Y2KTenEbM7s5gIrv6WYRvNXN UucqUg0KMIMEe0OFsZQky+X7QsKZC/qv9uQFn8cljV042/ZS8urRSyIhXZ8OZhqVz6DB uA7w== X-Gm-Message-State: AOJu0YwrIECrha73PLsRIVp5HKu2VrFBImBPCk17tKjbuHJPuON0N8EM rFlLqmDuNAu8XPIcQE5S9LEJY8UkLVEecl1Cyg== X-Google-Smtp-Source: AGHT+IHAHKKVxRaQwri5bImA5eCYOor7HhEmOhhPwntu/m2m67iUQqef+GnQosGvVJ+pwZt7bjuL38qZzTJAEgCL9Q== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:690c:3512:b0:57a:6019:62aa with SMTP id fq18-20020a05690c351200b0057a601962aamr192719ywb.5.1691543259866; Tue, 08 Aug 2023 18:07:39 -0700 (PDT) Date: Wed, 09 Aug 2023 01:06:04 +0000 In-Reply-To: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1691543257; l=1642; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=9CkxZqRZItVdJRKZDRTDHxT2lccsnPMJcsOENM5+Qdc=; b=85tSDIm6bOF0lYA+JmVaeoX1tIRMiVSHTcgdhXNIXdzyciIDHIFVMzodOJMDLgH46wLpyVO/h DVLt9rM2ys1DroSaqJdpej95V5f3jE3hmrIH2ifRXpzmpU3fsAWCaNc X-Mailer: b4 0.12.3 Message-ID: <20230809-net-netfilter-v2-1-5847d707ec0a@google.com> Subject: [PATCH v2 1/7] netfilter: ipset: refactor deprecated strncpy From: Justin Stitt To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hardening@vger.kernel.org, Kees Cook , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Justin Stitt X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_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 X-Patchwork-Delegate: kuba@kernel.org Use `strscpy_pad` instead of `strncpy`. Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- net/netfilter/ipset/ip_set_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c index 0b68e2e2824e..e564b5174261 100644 --- a/net/netfilter/ipset/ip_set_core.c +++ b/net/netfilter/ipset/ip_set_core.c @@ -872,7 +872,7 @@ ip_set_name_byindex(struct net *net, ip_set_id_t index, char *name) BUG_ON(!set); read_lock_bh(&ip_set_ref_lock); - strncpy(name, set->name, IPSET_MAXNAMELEN); + strscpy_pad(name, set->name, IPSET_MAXNAMELEN); read_unlock_bh(&ip_set_ref_lock); } EXPORT_SYMBOL_GPL(ip_set_name_byindex); @@ -1326,7 +1326,7 @@ static int ip_set_rename(struct sk_buff *skb, const struct nfnl_info *info, goto out; } } - strncpy(set->name, name2, IPSET_MAXNAMELEN); + strscpy_pad(set->name, name2, IPSET_MAXNAMELEN); out: write_unlock_bh(&ip_set_ref_lock); @@ -1380,9 +1380,9 @@ static int ip_set_swap(struct sk_buff *skb, const struct nfnl_info *info, return -EBUSY; } - strncpy(from_name, from->name, IPSET_MAXNAMELEN); - strncpy(from->name, to->name, IPSET_MAXNAMELEN); - strncpy(to->name, from_name, IPSET_MAXNAMELEN); + strscpy_pad(from_name, from->name, IPSET_MAXNAMELEN); + strscpy_pad(from->name, to->name, IPSET_MAXNAMELEN); + strscpy_pad(to->name, from_name, IPSET_MAXNAMELEN); swap(from->ref, to->ref); ip_set(inst, from_id) = to; From patchwork Wed Aug 9 01:06:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13347273 X-Patchwork-Delegate: kuba@kernel.org 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 65BAC633 for ; Wed, 9 Aug 2023 01:07:42 +0000 (UTC) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87AE319AF for ; Tue, 8 Aug 2023 18:07:41 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-585fb08172bso75084917b3.2 for ; Tue, 08 Aug 2023 18:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691543261; x=1692148061; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8kynZ2eY0/O6E/bQJdWZNL+mmpUwUSkdwurja4abucs=; b=Ol0O7ydBLmDGDB+SZ9v11BQgV4K8njIy76TSgXpaauJtbgStqpW/RYu/DWTxMxv5ZB +9MacsQSpkAhtOY9LVIFSQQtbwXVuIBhhpzOiV/EdBvEkZB/SRk8+/hM3Av3riZbSVSG QtCWUqHY7ASjZgsslXjvn1A8l6P037btB4PjAGygJPGdrTpttKYWlOta5a139Ww0nVw2 4wZvofllE9KdG42dhpE4GXt+mC+sxQs7bOpHb0LRCj1twgqrLPVTJYEBe17+KyMG8QjB UtPRDLE2isjgjcvvsvJSfiJwpN73phog9iVfBbXoVUO8z8mhgWMyyQoeNpXAgTDKPl0/ qpJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691543261; x=1692148061; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8kynZ2eY0/O6E/bQJdWZNL+mmpUwUSkdwurja4abucs=; b=evGfGkOhp0rGoT80ExcPcdDbiJg2AH0a0MLzG1wp8GpXe5Qg5Xtx6/nOQAK/rH3lC2 Ge0SkPKuvqFlF4jqGN0goJFVXXY8j4gXTIbzpy9cP9790xPg8byVvwoGiuTWDExL/2aO TlzpSNIRZTJ/muqepRsrdLQqBGdrvlwR9SdeMbAFNjqVZEPreHl1W4KO4E3iBGiS22gX ZawytxBONGtGmTmXR2eUjHJ/HN48PWZEipk2LYxwL43blRko0iXEHmYHX7N2LhUO9Rob aYzUbZtB23sC9a77UiC/XllK2zbcRpr76UZKeJ3mclmrU0e7k480P7n5n0zYtQ0EvDOE 6xfA== X-Gm-Message-State: AOJu0YxuvVrwYmt5vRkGObAb3iu28FoAjjk+CrvkDsJg+mJ30GmSGs1Y ACo0+bsSfiNbWNWM2toB0jJvSZV7nytu23ykZA== X-Google-Smtp-Source: AGHT+IGWrBqKRyMPFFB9tEV4Q4dgsTSTg2iWnoP8DD7tIMTceBZqZZlfU6ptL0dqjEgU1ZHHFa6n34AN1ZEUPEROSA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a5b:181:0:b0:d4f:d7a5:ba3b with SMTP id r1-20020a5b0181000000b00d4fd7a5ba3bmr30722ybl.8.1691543260881; Tue, 08 Aug 2023 18:07:40 -0700 (PDT) Date: Wed, 09 Aug 2023 01:06:05 +0000 In-Reply-To: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1691543258; l=903; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=GfuXN5T5xhe6k6w3cRknlOVNIOtegqmz8uQBUV4/tcw=; b=GYSS0ZoTuERfJ/SVnofWzjum44puD5h0s+zSjx2gITL2EhREYqCQpVB9N07nRO0v9d+gxkHdQ SOb7icKznTnC9EnhPquUOW6p8PVJ2Ep9ughhPfdNGQsR/NcIvz+Wupm X-Mailer: b4 0.12.3 Message-ID: <20230809-net-netfilter-v2-2-5847d707ec0a@google.com> Subject: [PATCH v2 2/7] netfilter: nf_tables: refactor deprecated strncpy From: Justin Stitt To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hardening@vger.kernel.org, Kees Cook , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Justin Stitt X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_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 X-Patchwork-Delegate: kuba@kernel.org Prefer `strscpy_pad` over `strncpy`. Signed-off-by: Justin Stitt --- Note: Opt for `strscpy_pad` over `strscpy` since padding is wanted [1] Link: https://lore.kernel.org/all/20230808234001.GJ9741@breakpoint.cc/ [1] --- net/netfilter/nft_ct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c index 38958e067aa8..bbf11c4871b2 100644 --- a/net/netfilter/nft_ct.c +++ b/net/netfilter/nft_ct.c @@ -108,7 +108,7 @@ static void nft_ct_get_eval(const struct nft_expr *expr, helper = rcu_dereference(help->helper); if (helper == NULL) goto err; - strncpy((char *)dest, helper->name, NF_CT_HELPER_NAME_LEN); + strscpy_pad((char *)dest, helper->name, NF_CT_HELPER_NAME_LEN); return; #ifdef CONFIG_NF_CONNTRACK_LABELS case NFT_CT_LABELS: { From patchwork Wed Aug 9 01:06:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13347274 X-Patchwork-Delegate: kuba@kernel.org 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 F3450812 for ; Wed, 9 Aug 2023 01:07:43 +0000 (UTC) Received: from mail-oi1-x249.google.com (mail-oi1-x249.google.com [IPv6:2607:f8b0:4864:20::249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE31E19BC for ; Tue, 8 Aug 2023 18:07:42 -0700 (PDT) Received: by mail-oi1-x249.google.com with SMTP id 5614622812f47-3a5a7e981ddso11704486b6e.2 for ; Tue, 08 Aug 2023 18:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691543262; x=1692148062; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=CVz1ojRkhYeSRtVo9H/tM0do8XQLIQHE9IgccPkP+yI=; b=YM0EF08LMQ5WvMrXeAp8gjjtszwUk2pUWzHCMZ0zn+G2isYfsms0AEcAOJHR+FzqoJ 5gGzXyXgO1s6N6jbssTgI6zymokr1AXoo+FhWaVJg4ihaxML7ucWHHuIxbr5HzCvt2MG Tt3yOmk7P8lv4yKQX63qFntp01EHrSBjsYSJq/s2dMp7zCD1Je4SxOgsOQ9tGtmEzCoe SpySLAiirdXb9RHkLdoS1GVfBe+V+nm33FdHqqxIkhu9U007DhL2rTOQ0/2K+sDSPX6C uGWsZ8A2DtO3QHV8XEPMcKLOS6G2USuAt/czHn56zM0QWZ4AQUFXQcNZZzbRLXv8blyO iMnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691543262; x=1692148062; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CVz1ojRkhYeSRtVo9H/tM0do8XQLIQHE9IgccPkP+yI=; b=LzengGcVPf7dib6H7cbKUj+PJoWgUHf+C2CiDZW0Z36B5SLHvAHC6UrHXptM3v8+UP /zjou6yB+8AD5N6Ib9NYKiei1zHVKBkYxehLbKm0rVmmPcwnMX3TqbyFlE+AkTAoQCUh 7ifrMJHZx2YU2yRPtXFHHuN2u8ZPcRykrdX6Wp65v5FCuUzp8ipn4trMrE9zCFuNul18 derIGahsLNvrI3wJlXpPJugpPVP0nSxks3+gi4rt+vP7l+6MAfyav7DQJYokGyMdwl7t tR7asKCrT8oJj0wrW2+WR1TQNrjDWY+hN8t+dq295l8y9IYPoydVhnN7rwfPOMw0pReG UYJg== X-Gm-Message-State: AOJu0YyhP+LxnM00P5eJhAYbHp9KdpnsyfoVmCZXC9vUc3LZYZlzPDEi BzSpMnAFYAywG0u51wUPbtg5ESOy2hOoe1ZLmw== X-Google-Smtp-Source: AGHT+IEKxVs1OlcWwiqA53GB6oh49zRgHksKsF0BWd5xdJypQdb1s8ZOL6iCRc3UIvJ02CL7Fj3KY4dzDtnnYJ2MCA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6808:1594:b0:3a4:18d1:1686 with SMTP id t20-20020a056808159400b003a418d11686mr793268oiw.10.1691543262146; Tue, 08 Aug 2023 18:07:42 -0700 (PDT) Date: Wed, 09 Aug 2023 01:06:06 +0000 In-Reply-To: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1691543258; l=692; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=Rb7knhgVRoO1cFP5KZBOoghV8KJqLMcT0yWjrGm/ENU=; b=SGRqAQLRAvrm1QwRllI6+LYWlBGAQP3OWJJwRohe3cZ2RB+HyT7yASIlpFuvkLVwAhf0uTtpO XHh1FrAHIHoC+nIE6P/23cWFGuKLtpQSj4dwTByKp1fsGBUz1TyiFoX X-Mailer: b4 0.12.3 Message-ID: <20230809-net-netfilter-v2-3-5847d707ec0a@google.com> Subject: [PATCH v2 3/7] netfilter: nf_tables: refactor deprecated strncpy From: Justin Stitt To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hardening@vger.kernel.org, Kees Cook , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Justin Stitt X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Prefer `strscpy_pad` over `strncpy`. Signed-off-by: Justin Stitt --- net/netfilter/nft_fib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/nft_fib.c b/net/netfilter/nft_fib.c index 6e049fd48760..8c250a47a3b4 100644 --- a/net/netfilter/nft_fib.c +++ b/net/netfilter/nft_fib.c @@ -150,7 +150,7 @@ void nft_fib_store_result(void *reg, const struct nft_fib *priv, if (priv->flags & NFTA_FIB_F_PRESENT) *dreg = !!dev; else - strncpy(reg, dev ? dev->name : "", IFNAMSIZ); + strscpy_pad(reg, dev ? dev->name : "", IFNAMSIZ); break; default: WARN_ON_ONCE(1); From patchwork Wed Aug 9 01:06:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13347275 X-Patchwork-Delegate: kuba@kernel.org 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 3B964ECE for ; Wed, 9 Aug 2023 01:07:45 +0000 (UTC) Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ED811BCF for ; Tue, 8 Aug 2023 18:07:44 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-586c59cd582so48846877b3.3 for ; Tue, 08 Aug 2023 18:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691543263; x=1692148063; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ib6nqOI6OhZk9uVMuCMDveLdue/VtxmtzrsTXPIDYRI=; b=ZoQqX5UIeq1jO5/Y5J5W2a7PzzXsb8d0S2K9nNc0sxvuHfEUau2nSLFvWWx5TabJYG 9AjCKoQscaQ3FibFIL636z6Qkx9MWiHi+jZzcS09eay2ZGG8ou0eqWAgykq7xE935CdT Y/BBWwHMbzudYeSVdUcGcDGZAbpW2ULHrvSazCEcoWFyxdgAZRZLgJVtM3QvN5w995cD 4gKNjSaX2/YVLXjoYMhH6jmDrKOeTQd47uGISSSDdR/wLa+Fr8lRe9HTNHcg+y0+ZlpS kC53/iPBs+RI23nXLKLuKb3pyVovbV5P1iJTe8dt2Rr+HJB4qllUtIoJ/lAhndvVoFC4 KPSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691543263; x=1692148063; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ib6nqOI6OhZk9uVMuCMDveLdue/VtxmtzrsTXPIDYRI=; b=PD6rIOxVuU1uStTaEPRVt4MrPfk4SDWdxNFxhRfjKq68VAGbwkrsvP4yxJu+7aEIW4 BptvmwvW3NyfSZT/XdDumks/xN0rl92B0RbX3wZttprsBcj8j8fcmrQeMwL2hV7S9Uc2 t3i4gduKIUbQXs8FVAWyv6Hh5C7wIUNILIw37cAcEgT4n3dcjkkG/txGDGRBQM8fTRRY vZBzLZlpbWs3QmjaqTHhyP5PrBHGSYWJfJPUf1TZTwdeOAFnFQIC7UgehnpTSb7YKYH2 M+lci9kYNttRFmU2u9c7dnFvkhHUbmik5sw1fI14uZk6XBP8gFvnfe0RN+db+e0BaWAq epdA== X-Gm-Message-State: AOJu0Ywm3Heu+/QLFxcZT+m1b0/WiewvXuJyoQgjR0d0nUOtgqNBHjOF Dw8Q+5+Do/876OmVy7neEclJ7/g3bCeqhhjOIw== X-Google-Smtp-Source: AGHT+IH5kjZOtu7DJJU2kcy5MUvh/1RM5TDPejbuQtilClG6fsAJ6QcOKvf1F+QzpdoZcY4Uz8jB2YjF0tOQbZPbdQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:ab62:0:b0:d4c:f456:d54f with SMTP id u89-20020a25ab62000000b00d4cf456d54fmr22714ybi.8.1691543263329; Tue, 08 Aug 2023 18:07:43 -0700 (PDT) Date: Wed, 09 Aug 2023 01:06:07 +0000 In-Reply-To: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1691543258; l=1342; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=7ETYnKTeQUVzYvHKo3dCw3Fgg8Ju8JACIFGAct1WkOg=; b=vu0OZUT90qel7Bct4/ripVcEolXMpugmp7bRnKPUqOl8EyTjsFcrN5q5j/s4LBuhdPWIHYjOi wh7kSdYgds5BsJcyjEsLKuA3/gws5T6+wjRr5B/LR0IzcPd3PBc/Kf/ X-Mailer: b4 0.12.3 Message-ID: <20230809-net-netfilter-v2-4-5847d707ec0a@google.com> Subject: [PATCH v2 4/7] netfilter: nft_meta: refactor deprecated strncpy From: Justin Stitt To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hardening@vger.kernel.org, Kees Cook , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Justin Stitt X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Prefer `strscpy_pad` to `strncpy`. Signed-off-by: Justin Stitt --- net/netfilter/nft_meta.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c index 8fdc7318c03c..f7da7c43333b 100644 --- a/net/netfilter/nft_meta.c +++ b/net/netfilter/nft_meta.c @@ -185,12 +185,12 @@ static noinline bool nft_meta_get_eval_kind(enum nft_meta_keys key, case NFT_META_IIFKIND: if (!in || !in->rtnl_link_ops) return false; - strncpy((char *)dest, in->rtnl_link_ops->kind, IFNAMSIZ); + strscpy_pad((char *)dest, in->rtnl_link_ops->kind, IFNAMSIZ); break; case NFT_META_OIFKIND: if (!out || !out->rtnl_link_ops) return false; - strncpy((char *)dest, out->rtnl_link_ops->kind, IFNAMSIZ); + strscpy_pad((char *)dest, out->rtnl_link_ops->kind, IFNAMSIZ); break; default: return false; @@ -206,7 +206,7 @@ static void nft_meta_store_ifindex(u32 *dest, const struct net_device *dev) static void nft_meta_store_ifname(u32 *dest, const struct net_device *dev) { - strncpy((char *)dest, dev ? dev->name : "", IFNAMSIZ); + strscpy_pad((char *)dest, dev ? dev->name : "", IFNAMSIZ); } static bool nft_meta_store_iftype(u32 *dest, const struct net_device *dev) From patchwork Wed Aug 9 01:06:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13347276 X-Patchwork-Delegate: kuba@kernel.org 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 4E86A1FA6 for ; Wed, 9 Aug 2023 01:07:46 +0000 (UTC) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37FA519AF for ; Tue, 8 Aug 2023 18:07:45 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58440eb872aso82395527b3.3 for ; Tue, 08 Aug 2023 18:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691543264; x=1692148064; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1ONd/JWe6ZkZveFErN2MpT8R9y0a9lN9YX7PcEW+G4U=; b=uQLE6smTxRX1leyrpUsBgAjJ8PIzUdv4bviLmq+pneR9cFdSU81LNgBj+5zuPWMTxv ZM+VYE9mpr2gXAT1BU9K9ORDZWFt70DUua28vGnkl8D3+KaywwJSdYhS8lqshy7QqWwK G+2L0rkCIlBTkycm7qrfg7AfR+xtQjGOD7PUyy8qLs3XjElgbidIsCcvAH7scOt0SmIX 1oF6rcbfsf4gyeuw/xehVb+CLcLzD+5+XKYgaYVIf56BFnyjz9pG6/dECj4OImbuGJ2U 4Lto6ebxG3IOzK1sq10U3j3lMzewZz23wET6IRt9JzgFF5dwLLCVRgt4xKV9ypEvUIZm kPog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691543264; x=1692148064; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1ONd/JWe6ZkZveFErN2MpT8R9y0a9lN9YX7PcEW+G4U=; b=hpbiwliJvwOym2bAvqH5RQi3z2udTcCPJQIUlhUrmq0MH3LHa0Z4m+5N8IATgCJQIE T0aHA1e119jngi8LLqNJUyKn6d6N4emuOCAxpuviP6tWr5KDadPGZFeQg8xeeeOSR3OU wzMmuDLwFu4n/7MUeGVQXNvuNutiM1IL1BvcC4OEg5+c5utI7hiT2GJuPz8QLVv5VAWl zH6tz1Eodci9IcYiqqsQWlKI2nbK0tX9nDc6SrdjeUwm5rA3ACQCtBxEg7fk+qdukD1c Rw5IjbgEELil1D4SQWBunU0bJG17gCwmk9mBPk1/Kd3bklZOjuuVwqwwwgnAa6fdOysz m/OQ== X-Gm-Message-State: AOJu0YxoULCPkZZT9q+2okA33QhmCS8r277arvMfqngWoL/I4lp+m5vu 0BewtloTAhSnDOQhDUO/wZoUkbKYJR+IpjBsbw== X-Google-Smtp-Source: AGHT+IFSvuXNP2dx+Ff+aSebW/a9wiOdcrWvL+hMHmBzATR59BrjhU/mVsaG27/i1cWSY+NuqBRcVyRoRP6u8e0Ksg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:d383:0:b0:c72:2386:7d26 with SMTP id e125-20020a25d383000000b00c7223867d26mr29048ybf.0.1691543264480; Tue, 08 Aug 2023 18:07:44 -0700 (PDT) Date: Wed, 09 Aug 2023 01:06:08 +0000 In-Reply-To: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1691543258; l=1715; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=KAM/QyHZk/9K6ANTYuqL7ePIPoJfU95ZXORzcYBHKm0=; b=gTI5CntTcfznrG6dmuSsXnxc4n1o4o6Fr5coSwA9r4jnyrg5eABEjDeuoGl/WnYNTeR1qMjOq yEuh3uRaIV7AGuLgca9Dj1nGSHWHNDrgcOqsP8fNvz3sX6wu8Eifm2E X-Mailer: b4 0.12.3 Message-ID: <20230809-net-netfilter-v2-5-5847d707ec0a@google.com> Subject: [PATCH v2 5/7] netfilter: nft_osf: refactor deprecated strncpy From: Justin Stitt To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hardening@vger.kernel.org, Kees Cook , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Justin Stitt X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Use `strscpy_pad` over `strncpy` for NUL-terminated strings. We can also drop the + 1 from `NFT_OSF_MAXGENRELEN + 1` since `strscpy` will guarantee NUL-termination. Signed-off-by: Justin Stitt --- Note: Should this usage @8556bceb9c409 also be changed to `strscpy_pad` or is zero-padding not required here? --- net/netfilter/nft_osf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/netfilter/nft_osf.c b/net/netfilter/nft_osf.c index 70820c66b591..7f61506e5b44 100644 --- a/net/netfilter/nft_osf.c +++ b/net/netfilter/nft_osf.c @@ -23,7 +23,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, struct nft_osf *priv = nft_expr_priv(expr); u32 *dest = ®s->data[priv->dreg]; struct sk_buff *skb = pkt->skb; - char os_match[NFT_OSF_MAXGENRELEN + 1]; + char os_match[NFT_OSF_MAXGENRELEN]; const struct tcphdr *tcp; struct nf_osf_data data; struct tcphdr _tcph; @@ -45,7 +45,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, } if (!nf_osf_find(skb, nf_osf_fingers, priv->ttl, &data)) { - strncpy((char *)dest, "unknown", NFT_OSF_MAXGENRELEN); + strscpy_pad((char *)dest, "unknown", NFT_OSF_MAXGENRELEN); } else { if (priv->flags & NFT_OSF_F_VERSION) snprintf(os_match, NFT_OSF_MAXGENRELEN, "%s:%s", @@ -53,7 +53,7 @@ static void nft_osf_eval(const struct nft_expr *expr, struct nft_regs *regs, else strscpy(os_match, data.genre, NFT_OSF_MAXGENRELEN); - strncpy((char *)dest, os_match, NFT_OSF_MAXGENRELEN); + strscpy_pad((char *)dest, os_match, NFT_OSF_MAXGENRELEN); } } From patchwork Wed Aug 9 01:06:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13347277 X-Patchwork-Delegate: kuba@kernel.org 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 5B9A32591 for ; Wed, 9 Aug 2023 01:07:47 +0000 (UTC) Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AD9219AD for ; Tue, 8 Aug 2023 18:07:46 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d4db064e4e2so4356427276.3 for ; Tue, 08 Aug 2023 18:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691543265; x=1692148065; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=b9SxK9VuBhH23JZNfwlmHxFJB2H3YTPscUMoMvn8rbc=; b=APutyrGHq0YTWRW12pm4MFQuMqAXqr+kMsiQqH/8WklaM3Xjxt0HiR27YbGJXqvEjY 6eEjM3eABJspnPyTNt2jI/9l9gN7s6Apj1V2bXUTaQ9tTsvddYK9toOP4z76HqRLSZRt YGmlC9Xkgtbj7ra6sGK/3pWh9mFaoc2xFXx4337GwtDA5PKpGMb1+DX0ndI/f5JOPxAW HMPJIJzRPp5qesMCm+caWpzVA0W6/0vT9s9rwk6lxg1NsIvYmVYxdiqFK9rq1it2FYIe /pU54CocziwXtDHFJpS/JtamqtFWIYrqhcgDztGeQ4O9gGhnrH7m3upujJELrSf8X8L/ U8Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691543265; x=1692148065; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=b9SxK9VuBhH23JZNfwlmHxFJB2H3YTPscUMoMvn8rbc=; b=VC1DipguTmJydDPNpxdeNa0dm0PrEkNy603AEBaiwNLhzGp8cX1AfEXKyLcIKFlvkI WevWXJPTgCjScB9u/Hls2CTxqElYr2q63o0B1k38Ts6En4DDH2vMyGJMsJUdUXzNZUcM 106a1jQzbQwcxj0sZOa85H5vqpTOH/pFog1p7oWVCyaFLr3E5e3wTRvCQwYBBDPm4JTi UP8TGrHk6efoCkFDLEgSstRGNcHUqAgbgUz7fQuEy4k5WVGksFU2CbRAW8/fAzoofimi waf+suF8xrtFB5Jc1+HM7AgkPyIW6+IZbZVVk4Nhiu6MiY1+//9CTYxRXFcFG3P35TSm YN/w== X-Gm-Message-State: AOJu0YxFHnC/vETLgG/SDMR80nuMEdE95EybRy+TNYNK8b38gQSssvcG gJrmZEqNVUGzVHQ0kCJzLzJeidaPd493+WtOsw== X-Google-Smtp-Source: AGHT+IEY4ztdjT7PWj1HLsFFH4GzdFYJKZG/8yNdDtgyLo6Kn1SWa4ceZv423UysbgranQwQ/B7QY6TfJ/WFPP5Njg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:3288:0:b0:d44:585f:dfa8 with SMTP id y130-20020a253288000000b00d44585fdfa8mr25516yby.0.1691543265492; Tue, 08 Aug 2023 18:07:45 -0700 (PDT) Date: Wed, 09 Aug 2023 01:06:09 +0000 In-Reply-To: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1691543258; l=1226; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=MYwDvvyMzq/6Jbwjo4fUCw6xEkwFFEE6felLK1tQBvc=; b=WeXXNFVuxmL2/RZ5Dpc6W99h2eU2abWzCTXFBENisuaDRhmkxGJ3LkZOTBNdDDy6FyfR6PlS8 bEW3jArRu3JAcBUw2APr+XvWRQsMcU+uQodYXJbL14BITjI/xUBTb+t X-Mailer: b4 0.12.3 Message-ID: <20230809-net-netfilter-v2-6-5847d707ec0a@google.com> Subject: [PATCH v2 6/7] netfilter: x_tables: refactor deprecated strncpy From: Justin Stitt To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hardening@vger.kernel.org, Kees Cook , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Justin Stitt X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Prefer `strscpy_pad` to `strncpy`. Signed-off-by: Justin Stitt --- net/netfilter/x_tables.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c index 470282cf3fae..21624d68314f 100644 --- a/net/netfilter/x_tables.c +++ b/net/netfilter/x_tables.c @@ -768,7 +768,7 @@ void xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr, m->u.user.match_size = msize; strscpy(name, match->name, sizeof(name)); module_put(match->me); - strncpy(m->u.user.name, name, sizeof(m->u.user.name)); + strscpy_pad(m->u.user.name, name, sizeof(m->u.user.name)); *size += off; *dstptr += msize; @@ -1148,7 +1148,7 @@ void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr, t->u.user.target_size = tsize; strscpy(name, target->name, sizeof(name)); module_put(target->me); - strncpy(t->u.user.name, name, sizeof(t->u.user.name)); + strscpy_pad(t->u.user.name, name, sizeof(t->u.user.name)); *size += off; *dstptr += tsize; @@ -2014,4 +2014,3 @@ static void __exit xt_fini(void) module_init(xt_init); module_exit(xt_fini); - From patchwork Wed Aug 9 01:06:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13347278 X-Patchwork-Delegate: kuba@kernel.org 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 248F24437 for ; Wed, 9 Aug 2023 01:07:48 +0000 (UTC) Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CC1B1BF7 for ; Tue, 8 Aug 2023 18:07:47 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d47a02fc63fso4863729276.0 for ; Tue, 08 Aug 2023 18:07:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691543266; x=1692148066; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MG9K9YUhTMTzK19uCHNnSBLcKhcXx1YxnQhkeYxtQnQ=; b=FLufdnQLID7CLFxDuinWTCHCNOM0tHWDzh/Q+ezwYBHvUhcKrvNRwf2X/858fNR7wb d8vbxPP43ceY/pyaj0Uw5PQ59JrcnSpcF/a3LfcIMqUOkY5p5Iam1144VCB1Ons2vj81 BmLiwO5IZchhdKNB3Hp+SHWii5wcBQkoVNE1bp5inoSeur+njvbFP1qGHTgPtXq1kfjg BEkjKbj13r7baEfK+6B3OTRz0y7Eybl5D1FWifL02RvN4LssSj5E1eUpHkMefprJM5KT H0ueJcMX3S8gV9suDKG8GXE43UgliTiV3eYQCRxb8WAldQnhoOh0RconuamFRyja+cUu eP6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691543266; x=1692148066; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MG9K9YUhTMTzK19uCHNnSBLcKhcXx1YxnQhkeYxtQnQ=; b=ZFeHf9YTrREhZrdCnRl019GQTfc87Mao1zEFPQ7daPtad32fEpKUzPTm6B6T7WjGnw J1oAHMZuv9C1Z4595eOKHtpoQXvKzmhMbsgK2pozy+rMZ40Oj5Im+rs5bedX2u0Um/qG k83xz9IV01eWkEKd17EOqfyEkY89cccjtHEe88YdU5oP8x8s9c5GV7ZnOSLlLOtiwe8k bHwS25Yu/IrK8Z5Z1/PLbFNp1v2ohjVYoHm2gWpu/hAgXo6OJnf01iXkYefGQROcHRhD sZX16rB6eDCtdy2++JKvf2/0VHMmv4dy8UaeXPjF0CxyUi2DrBfBYeNCSVXgSBTVzdcM gC7A== X-Gm-Message-State: AOJu0Yx8cB49H0M5cZOK0VNAe6A//f2Aw9acDp4F5w5pXTc+4SZHZCBb 7kIQ08p3pWI5mE4XceNCTqaiIsEi6A2HKstwig== X-Google-Smtp-Source: AGHT+IHZpwGDo8C14lufhH346u2Bau1BUWvvndGq88fm59ryfmewZSsy7jAPCKUfUcYrjFtU1dpqY0m+aY5jSzBV5Q== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:ad26:0:b0:d58:6cea:84de with SMTP id y38-20020a25ad26000000b00d586cea84demr24517ybi.11.1691543266633; Tue, 08 Aug 2023 18:07:46 -0700 (PDT) Date: Wed, 09 Aug 2023 01:06:10 +0000 In-Reply-To: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230809-net-netfilter-v2-0-5847d707ec0a@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1691543258; l=1182; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=PvqWKqnPHt6FvPDmHzVp42icOwjac4OjqNFq/tqlT4Q=; b=sh9zj/YLC302K92KXYEsgv5KQ7slHtAn4AjmXQutkadONIDR1z3dS2tfhEUE1/fEjCLLxhXmz uQNQ/ErDWgqDBqL2ooZ4J+hnTeNjcylCNu2Z3wgVuRaaaBWLe9vWLDa X-Mailer: b4 0.12.3 Message-ID: <20230809-net-netfilter-v2-7-5847d707ec0a@google.com> Subject: [PATCH v2 7/7] netfilter: xtables: refactor deprecated strncpy From: Justin Stitt To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hardening@vger.kernel.org, Kees Cook , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Justin Stitt X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_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 X-Patchwork-Delegate: kuba@kernel.org Prefer `strscpy_pad` as it's a more robust interface whilst maintaing zero-padding behavior. There may have existed a bug here due to both `tbl->repl.name` and `info->name` having a size of 32 as defined below: | #define XT_TABLE_MAXNAMELEN 32 This may lead to buffer overreads in some situations -- `strscpy` solves this by guaranteeing NUL-termination of the dest buffer. Signed-off-by: Justin Stitt --- Note: build tested only --- net/netfilter/xt_repldata.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h index 68ccbe50bb1e..5d1fb7018dba 100644 --- a/net/netfilter/xt_repldata.h +++ b/net/netfilter/xt_repldata.h @@ -29,7 +29,7 @@ if (tbl == NULL) \ return NULL; \ term = (struct type##_error *)&(((char *)tbl)[term_offset]); \ - strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \ + strscpy_pad(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \ *term = (struct type##_error)typ2##_ERROR_INIT; \ tbl->repl.valid_hooks = hook_mask; \ tbl->repl.num_entries = nhooks + 1; \