Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2690986rdg; Mon, 16 Oct 2023 11:42:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHWgvZA8axXSSCu+BvPMK8G9rRFzI4z5KgPlGDcxwZhl72OFsTDL2hdWU1yi+Cp42xVy5XX X-Received: by 2002:a05:6a00:2396:b0:6be:2649:8c6b with SMTP id f22-20020a056a00239600b006be26498c6bmr3718900pfc.32.1697481777941; Mon, 16 Oct 2023 11:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697481777; cv=none; d=google.com; s=arc-20160816; b=woJV4I/LOXDIW5Fz/ybm9KiHQXlcdRa4BQZuXIvse88gDZlvjkf6bnkXZgwDDHsJnB SMp3eFWR2i4CnWw24N3VhQOx27Aqun3qeaCCHBw35Yj/2saVjFS8+Va/Y4yX4WpBI0cH qgc6BSyep/T7LkPJNlQfSaJfOeV69olV17M+Vinp07DluI//9faDXlNfhObkyMAORauf /Bpf/ZxYJ5LJWDAyt6Xv6EDuAavygnlaIbpqNrbjbL07e8cLDKTsMRTswV4jzS/S0+ff /TiqgJ6x6rjO5X+06itmF6SLOr0sLIiPkmRHAqDrBUmd0lhWctEJSptwj8E1uuGfOvvg 6cAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=ivRw9UOALg3+ZFDXu75FoDqQWG1hBKv7UDpo12vH7Vg=; fh=lh8+h8Cub4sDTTYv7AU2zOgI9Rk3UB2OyzHhrOMnBQo=; b=l9kBqAVurz/amvFRmMKqF7tT2gLLDYcgArmRDMru3xhRGX8cbCIcLOPtYN/7Xvy5wD Fm+PE7dn/QzciH64vQV8MCGvGDGJwUkqRwyZwRkETS3vSafSfqDERmPn4gBJunovdxFQ 23gHlFRhJrebc0gG8AYsLh33jDkDNFWwMk8X92c+CRqN3Q39ScaoDeaGafaGocX1h7V/ PL2hW6zo8zdVl/BcWp/sm9uuKOGuzgrqbDFCBhlYiOcQaQLJOajRaA/1wYHBxCTJPZeL s4meqWqFUH8/xyfpxQQSa2L6XR2bJo89ay4Mj+CAHKKSAL5hc7TA6frUoTC2psycwTQt UUKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ovu4Ttrr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bw42-20020a056a0204aa00b005b3097b75c0si6384168pgb.56.2023.10.16.11.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 11:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ovu4Ttrr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 303B68049119; Mon, 16 Oct 2023 11:42:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233011AbjJPSmr (ORCPT + 99 others); Mon, 16 Oct 2023 14:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231569AbjJPSmq (ORCPT ); Mon, 16 Oct 2023 14:42:46 -0400 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 E534FAC for ; Mon, 16 Oct 2023 11:42:43 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7bbe0a453so75149967b3.0 for ; Mon, 16 Oct 2023 11:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697481763; x=1698086563; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ivRw9UOALg3+ZFDXu75FoDqQWG1hBKv7UDpo12vH7Vg=; b=ovu4Ttrro/dxJHYw/mxQXqmiihXMWQ6OfaBHGjRttDM3U678UNLkXb7g2gO0MVlwio llHQGR77CLZiYHkCxHq6nTyrICSbtL1zwNKbEO0Fd/OI2nVM3ibQaZb7lYSzdtrLzgks FxGCS/JqMzU6TuMn69rkjse0wwLPqv8QsZaV28+R/bUXQ0q+FAM8mGz532pLkTRpRlTN vt86DfwqSWqbU5EvvR4az+dirLcsJryhR3LC0++kd6wywNrORg83y5523ve+zXKdsuur VEBHPT5R6d3haOUeH0flDoR4HyYqVE1buvy+q+5CKyZyADUEON4SWWI5MP7tsPrI+6Ws Okvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697481763; x=1698086563; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ivRw9UOALg3+ZFDXu75FoDqQWG1hBKv7UDpo12vH7Vg=; b=CEsrSNXziFupAlgLDdiIkKbo2/GkkWMUZkbFb83XbIOx7VsueeSGT6EfeIm1S5gZNq ZF/4ZobhgovQgSVmtRFZqHIZLKnVm9kw48VrQCugoYzSrGX9YYMo9v4Q1jXnP5TlFG4J Yz9hdzggHRatbb6uzZ/k0A2zH5dI90QkxWZPrjX2Q7VinOQRzQRwXbglSfw+/UFsR7sS yPFqd4vT3DR1+jkMKDBkE6bfuJ0eaIs2kI1F3n6L7JL+t29/LLSeDQu+r/8XuoBwjggM U0EevWr6kr8aHxLw7ASAFEOUzGmBAZ6LtDWaiiHGn3XFW8b4qeXWNnakLB0drzIBzwj2 tzEA== X-Gm-Message-State: AOJu0Yxtc9gSkwAMcKkQXlYsUTywJ0oo8or67lYJj6plHNuaWTJXBHVY F+qU3KjIB7S7nQ5ubaNxzxsfJZK/q5WFxz6rPg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a0d:d8ce:0:b0:5a7:b15a:1a7d with SMTP id a197-20020a0dd8ce000000b005a7b15a1a7dmr165ywe.2.1697481763100; Mon, 16 Oct 2023 11:42:43 -0700 (PDT) Date: Mon, 16 Oct 2023 18:42:42 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIACGELWUC/52NQQ6CMBBFr0K6dgwtqODKexhiShlgEmmbKWkkp He3cgSX7+fnvV0EZMIg7sUuGCMFcjaDOhXCzNpOCDRkFqpUlSylgrCyNX6DgSkiB7C4wqwX1gM 56PVm3PJC78HAFaU0bd1UfTuK7POMI32O1rPLPFNYHW9HOsrf+k8lSpDQjHXZ3i5Vg1g/JuemN 57zRXQppS8DPjql4wAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697481762; l=2821; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=9OAsLt5xhpoq++LwUFSyGBM2eLJQZ3SSzZBtifp1JdY=; b=r2iDDmOZ06G4yQXq+rRj5nSlF16zH6RZUjIrABYMNgufZfNtz6QUD+vkxcP1bQip47HAJEkgd B9zyXnN4z0zCvXN0Y3xSGzg9yScCK9GWviqrj7moA4RtZvbBdZMP9WZ X-Mailer: b4 0.12.3 Message-ID: <20231016-strncpy-drivers-net-hamradio-baycom_epp-c-v2-1-39f72a72de30@google.com> Subject: [PATCH v2] hamradio: replace deprecated strncpy with strscpy_pad From: Justin Stitt To: Thomas Sailer , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-hams@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 howler.vger.email 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 (howler.vger.email [0.0.0.0]); Mon, 16 Oct 2023 11:42:55 -0700 (PDT) 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 both hi.data.modename and hi.data.drivername to be NUL-terminated based on its usage with sprintf: | sprintf(hi.data.modename, "%sclk,%smodem,fclk=%d,bps=%d%s", | bc->cfg.intclk ? "int" : "ext", | bc->cfg.extmodem ? "ext" : "int", bc->cfg.fclk, bc->cfg.bps, | bc->cfg.loopback ? ",loopback" : ""); Note that this data is copied out to userspace with: | if (copy_to_user(data, &hi, sizeof(hi))) ... however, the data was also copied FROM the user here: | if (copy_from_user(&hi, data, sizeof(hi))) Considering the above, a suitable replacement is strscpy_pad() as it guarantees NUL-termination on the destination buffer while also NUL-padding (which is good+wanted behavior when copying data to userspace). Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt --- Changes in v2: - use strscpy_pad (thanks Kees) - bytes arrays are now considered "buffets" :) (thanks Kees) - Link to v1: https://lore.kernel.org/r/20231012-strncpy-drivers-net-hamradio-baycom_epp-c-v1-1-8f4097538ee4@google.com --- Note: build-tested only. Also, there are 33 instances of trailing whitespace in this file alone. I've opted to not remove them in this patch. --- drivers/net/hamradio/baycom_epp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/hamradio/baycom_epp.c b/drivers/net/hamradio/baycom_epp.c index 83ff882f5d97..ccfc83857c26 100644 --- a/drivers/net/hamradio/baycom_epp.c +++ b/drivers/net/hamradio/baycom_epp.c @@ -1074,7 +1074,7 @@ static int baycom_siocdevprivate(struct net_device *dev, struct ifreq *ifr, return 0; case HDLCDRVCTL_DRIVERNAME: - strncpy(hi.data.drivername, "baycom_epp", sizeof(hi.data.drivername)); + strscpy_pad(hi.data.drivername, "baycom_epp", sizeof(hi.data.drivername)); break; case HDLCDRVCTL_GETMODE: @@ -1091,7 +1091,7 @@ static int baycom_siocdevprivate(struct net_device *dev, struct ifreq *ifr, return baycom_setmode(bc, hi.data.modename); case HDLCDRVCTL_MODELIST: - strncpy(hi.data.modename, "intclk,extclk,intmodem,extmodem,divider=x", + strscpy_pad(hi.data.modename, "intclk,extclk,intmodem,extmodem,divider=x", sizeof(hi.data.modename)); break; --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231012-strncpy-drivers-net-hamradio-baycom_epp-c-6e11c9483b9f Best regards, -- Justin Stitt