Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1290813rdb; Wed, 20 Sep 2023 05:24:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyGGFM5v/txVrW9lGAnonEqhnarHUqsFGpsyYtjPBr7UE+QCJF5xzw0Mls7TACnt3CSoi6 X-Received: by 2002:a05:6a21:7887:b0:13d:b318:5c70 with SMTP id bf7-20020a056a21788700b0013db3185c70mr2694793pzc.19.1695212677923; Wed, 20 Sep 2023 05:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695212677; cv=none; d=google.com; s=arc-20160816; b=KBZyM40DXbcltpp6CJXFaKZuzJXehfKPsfs4pOxcBnSuOMsl04YQmr1uQRgXDyNRig oaRgaml2Nr/FJUo7qQIhF2qtCir1Wsr8A0dSbJNg8HyYUXL46B57DrtiZe02sRqAS463 yddLb7Dolh4XWso4pUANNLt6hHLb0xErKROziGSJbU/RoMl4gnUFWWvTJ9kNKdt0KMOV JQIN5IW22O49UqM2pZD+9GtDFWanJMwq0HJJRqJAZdJdhrgGePUtYJqt1g/uBuFSeCnh 3BK/pHSk46dCPN8CO/EqdII8J476u0H+ob10kIQ0gOqGiKsc7mbVpo5Q2rDmbDj2GPn0 cgAQ== 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=u02BBGPGfX0yPbijfRs1PCNnIlPGBgpzZObvNQnBP78=; fh=7FzmvCGH4/KLkdfA1IQSMLlbD/a/cBxVqzxeX+UMLC8=; b=wvf9/0W4ExKAHLZivfK+S+yfDOhmqbhiDLCIMUBVTKmXmeu17rp77ao7m/BcnuwJ6E yGoEWfyaJQaDUCt3fcQ3Z1tPU4ZmASELRzsJtEnfXvAn+JPQWe597bcL9WA23Y8XTs3n prZjOEa6P15ExUCdwTFWyB7WsQbqq7X+C7XRUjdoJSXbUGSfdNfNUihe69Lhb/aBMuHM VBfX+/Qv22TKx5FTdNzyi2dSeDQx+qa3z32rWt5eKGZRIIkc/a4bSUSr9w9avnUTgVXC fi4m3sXbEYkTqjAjc0ZkE6B0bjQrkVyF4lOyJSdi8awL7evTObq36Fo2K5fJvnUjf7Hn 6deA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RagfjL06; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id cp16-20020a056a00349000b0068ffd96e1d4si11677691pfb.165.2023.09.20.05.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 05:24:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RagfjL06; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id F171A80F66B9; Wed, 20 Sep 2023 04:07:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234437AbjITLHo (ORCPT + 99 others); Wed, 20 Sep 2023 07:07:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234346AbjITLHn (ORCPT ); Wed, 20 Sep 2023 07:07:43 -0400 Received: from mail-oi1-x24a.google.com (mail-oi1-x24a.google.com [IPv6:2607:f8b0:4864:20::24a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2241D3 for ; Wed, 20 Sep 2023 04:07:36 -0700 (PDT) Received: by mail-oi1-x24a.google.com with SMTP id 5614622812f47-3aa17bcf2bcso10430256b6e.0 for ; Wed, 20 Sep 2023 04:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695208056; x=1695812856; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=u02BBGPGfX0yPbijfRs1PCNnIlPGBgpzZObvNQnBP78=; b=RagfjL065TwaUxB9dZe+bGjXa6J93nA+UGkrkn86LVHZ/VXYUm9+UdT0Fqt+xTjCLK 7ASs3TDnYc4r87Sbsa5/vX7PcH6brxFrleTUloyOnaFTYeW17oXQqjtKFBfrbkCKH4vb DWiv5m25KppF71ndrg48hy/9+2sqVuseLovaXqw2l246du178d9hz38PhlGy0HnlqdDG HCFlcAQ+0MkXoecyURbvIYjvq6UE2xrN+MYYsrMHraQqOo+9GfHBNBBoNRVxCrZt0Fc9 dZNWKKsuTkXJMONmCnxQmMiA1Tdd2Ma4KTMbMBqHj0twv39bN8mihKUInDQYQVYCL4/a VTdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695208056; x=1695812856; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=u02BBGPGfX0yPbijfRs1PCNnIlPGBgpzZObvNQnBP78=; b=iAzp8q86CFhENxKN9sGJhsLS/D6cD8/0cD+599MqWXzUwcYArU6q2xSz220l5VVjOW Ur62Q3pDWAoVloXHgIHqUGCZ7A6BZrxYA4ukwH3utBftPBM3BVbL5RyyIsV9YSVvGE1+ yvITONUSzxo38xy+VMk7ojhOPWclouPgy3Acqosr3yZc2EZwewEvSVEIhurUwY2d7EJK NkAEI7fYCXSZrgvYpKkeg3oXT0pZU7GNtmjZVcTH9ELFK0LbhXkyXA90n/Eb1Aem9KJO JUJ28WWepnyZeoejfqaXctdHV52ty8o3fLom494AMukdNXWcxzg00TESaLhJs9nHWMxn yc8Q== X-Gm-Message-State: AOJu0YyYxwXM5bv3mbVdUHp4DsXyhRK9jn3UsroSPczykKvQy5SavrsH TWc8xTyLAdSwjYHw5uJm3+cG28vnAv8fRmWQCA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6808:19a8:b0:3a7:7e66:2197 with SMTP id bj40-20020a05680819a800b003a77e662197mr1072227oib.2.1695208055987; Wed, 20 Sep 2023 04:07:35 -0700 (PDT) Date: Wed, 20 Sep 2023 11:07:35 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAHbSCmUC/yWNuw7CMAwAf6XyjKUkCKrwK4ghdQ310DSy6QNV/ Xci2O6Wux2MVdjg1uygvIjJlKv4UwM0pPxilL46BBfOLgaH9tZM5YO9ysJqKIGwm834j2VaWcd ESJjixfm2u8bWe6i9ovyU7fe6P47jC9mtn657AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1695208054; l=1809; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=43KHe364FJHinbfAf5b51PqpKyrOTl6pEsGjXdoYGGk=; b=eHtC0NjEj+DC+VenI5onyQtBNvqXdaXL9USn7KK2KyrqhUYYw7P14M/xRG/+v1dI6/SLaffNx BstvDQQ+GdLAUG418aw8Fsrorxtz2WZN/2c296ApqokqUhaW/aQjr8p X-Mailer: b4 0.12.3 Message-ID: <20230920-strncpy-drivers-i2c-busses-i2c-powermac-c-v1-1-0a3e9a107f8a@google.com> Subject: [PATCH] i2c: replace deprecated strncpy From: Justin Stitt To: Andi Shyti , Michael Ellerman , Nicholas Piggin , Christophe Leroy Cc: linux-i2c@vger.kernel.org, linuxppc-dev@lists.ozlabs.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 agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 20 Sep 2023 04:07:49 -0700 (PDT) `strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. `info.type` is expected to be NUL-terminated judging by its use in `i2c_new_client_device()` wherein it is used to populate `client->name`: | strscpy(client->name, info->type, sizeof(client->name)); NUL-padding is not required and even if it was, `client` is already zero-initialized. Considering the two points from 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 --- drivers/i2c/busses/i2c-powermac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c index 4996a628fdae..8e57ebe595be 100644 --- a/drivers/i2c/busses/i2c-powermac.c +++ b/drivers/i2c/busses/i2c-powermac.c @@ -231,7 +231,7 @@ static void i2c_powermac_create_one(struct i2c_adapter *adap, struct i2c_board_info info = {}; struct i2c_client *newdev; - strncpy(info.type, type, sizeof(info.type)); + strscpy(info.type, type, sizeof(info.type)); info.addr = addr; newdev = i2c_new_client_device(adap, &info); if (IS_ERR(newdev)) --- base-commit: 2cf0f715623872823a72e451243bbf555d10d032 change-id: 20230920-strncpy-drivers-i2c-busses-i2c-powermac-c-a95017b69711 Best regards, -- Justin Stitt