Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2694135rdh; Wed, 27 Sep 2023 09:51:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBKPOHNVghMebLTYofm76bqpg7BlFDmz3xWc6Frk79TEdsK9ERUSdpU2QQ416b6AccdSQx X-Received: by 2002:a05:6830:1089:b0:6b9:8357:6150 with SMTP id y9-20020a056830108900b006b983576150mr2732138oto.35.1695833472451; Wed, 27 Sep 2023 09:51:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695833472; cv=none; d=google.com; s=arc-20160816; b=FIekTkJrOwQUmzWtvLOG2+dc1z/XXX71DyJP3JCA8Z7U7iyR830zTodK6CifXxQ3oj L19SRwZGR/Ffly6zZNvuu4WplZZ5TL+Gggv83Y8vhy4sPsrFni0y0xJ6KYpFImbVJ0eK HGFUXd1UKYc7Efn6S2lV88ZFZT+uAWIhibaqUmQQcr830iXV/+NvZ2jkIAeUuYcyUtPh 19tzfm//dvU9deSYznJ0w9BrC5oD2sWhG5XQrRYS9t3upS2yMuVjP/kF+Dj3bzQDkBNH 8i10AKUkP8m0Q8b/jroWm8Mat0gBADhE8NzzqlYhvZ/TY8cdsWvBHe1uELVk0DjUPokb p/vw== 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=3IdjZrPwiGzFr5iXwebO1sIVd+FSmTVZlXYqn9eNO/o=; fh=cJI/+0BUhef/5QIIweDWRKH3RfXQG3bzIdy0ZDtFDCg=; b=uNHOzf76ywDpyHKU0ZPRRVQY3v0fRbEXq3F7yhe3fZDrO/1KFT2Gw0QFc6g4FJt3Dz d/e7uhWCr/MFaeiXC72lQTUkHorSyStwVQcpNXiZGjDDiGvh0a2aY/EwS6+kjbxIcZmc 827z7cb1zgXTcwDqkQtN8Tv5bGUWASL2B37+ZgCFjslvco/KdFubaqzsAb88gPw43B/T 4etg4Kjpif5j0NpD+phL54nBZgrMpPBCX+sGIoL8BnkexR3IQk0Ru+PGI/WGQrYOzAfj BNZNCuFQQNDiZarHwYtpmFfVYgBa8ZXf6skAhwGSM+yQ7hVTo9qVujjx2dQrXHoU2JQF sNig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=l15XFjKs; 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 b22-20020a056a000cd600b0068a68d71b68si1103341pfv.216.2023.09.27.09.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 09:51:12 -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=l15XFjKs; 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 C814B80CCD0E; Tue, 26 Sep 2023 23:17:53 -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 S229582AbjI0GRr (ORCPT + 99 others); Wed, 27 Sep 2023 02:17:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbjI0GRo (ORCPT ); Wed, 27 Sep 2023 02:17:44 -0400 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 465319C for ; Tue, 26 Sep 2023 23:17:43 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59c2ca3bcf9so200748597b3.3 for ; Tue, 26 Sep 2023 23:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695795462; x=1696400262; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=3IdjZrPwiGzFr5iXwebO1sIVd+FSmTVZlXYqn9eNO/o=; b=l15XFjKsNujV3q/caKPiU7k3hXqgT7DUJMHPKQj2jKr2lUzdffwxQVTQ8FEkl7bcZ3 Ed9MTxwTm7CrImaO0BsmYzC0sTv1I/3e/jSWYefNvxA5k3GbtLVVFzV5HO5ytAdfWVW0 KTbiqW4PRA1fdRMcETNdSvCAfBOWzdPR6F3zzLfOANGGSRdP1jGw4sJ+7x3vvrLM+UV3 s7DlkqMp+/kYQIds9LxqQNyxOIWZtepvb7GyAtGzs66N8+B+EIPBRpuQCePUDVSBs2SE qo3UreaEKAXEzive7cVcQrPzF9p3J5MnJq3sP4yvVn+A1k+TwHhDbLhmyyxOQLulGL1D vF+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695795462; x=1696400262; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3IdjZrPwiGzFr5iXwebO1sIVd+FSmTVZlXYqn9eNO/o=; b=OkPNz2foi23xL3XpSxDasZ9l2MmFCIZJnG+hJCb7nL/U3GTmF3GQKJzQnRIMT90Vze yxiqqRNrB2DtMujqEAVzodKXIlLP1uK3m+yCVc9M58cEnCKXOyUE/ygUQKJIJRucuYTh XI21ETCRlX+n/NPVKaPbi2AHJ3n7OMGqWh7CPi+l+VAOyHw5iTXv2NCZlNc9pvgd+qN2 SrXjpTHY2hMWmCWZJbjEF3bU3oQ6LsVEQO5o1fm1pf7AuBc/px2tsiD7neBbae85Kaa8 bHhI7UgRKn8Vr7ssaTnXUnuwJjVcf+AkK09EVGKAB+jWMJNd7z64N87zkJK3Zul/umBG Mkgw== X-Gm-Message-State: AOJu0YwKtoyjBtOX1Glz8f/Pg0gpBiBH5mAMIU5oEdrffo7GoNWsBN32 1NtWtDHRqgzxtflU1xR56UvKH89t6D1D5sw15A== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:d7:0:b0:d89:b072:d06f with SMTP id 206-20020a2500d7000000b00d89b072d06fmr11121yba.7.1695795462505; Tue, 26 Sep 2023 23:17:42 -0700 (PDT) Date: Wed, 27 Sep 2023 06:17:34 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAP3IE2UC/x2N0QrCQAwEf6Xk2cDdFSr6KyJypFEX6VmSUpTSf zcI8zLzsLuRq0Gdzt1Gpisc7xaSDx3Js7aHMsZwKqn06VSO7Is1mb88GlY15wkuvCB6cHthYmH Nw9DXknNNQrE0m97x+b9crvv+A01lss51AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1695795461; l=2199; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=yf2mZJ5UhZfCEhl12Sbw0YsexAnc1bDuCOjAYvjiTjo=; b=UoLwMaEMOF3kZXOjT/dbWypJzNcwXQhW527o0bYN72xF4yynGwkJKo3oZgu+MURWCOzlkYLxA no/nZypsDidCOb7stUoIi4a3RXthyGGFPkxnLaWOT74StfAjtuk0kCX X-Mailer: b4 0.12.3 Message-ID: <20230927-strncpy-drivers-misc-ti-st-st_kim-c-v1-1-29bbdeed1a2c@google.com> Subject: [PATCH] drivers: misc: ti-st: replace deprecated strncpy with strscpy From: Justin Stitt To: Arnd Bergmann , Greg Kroah-Hartman Cc: 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]); Tue, 26 Sep 2023 23:17:54 -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 `kim_data->dev_name` and `kim_gdata->dev_name` to be NUL-terminated. `kim_data->dev_name` seems to not require NUL-padding. `kim_gdata` is already zero-allocated and as such does not require NUL-padding: | kim_gdata = kzalloc(sizeof(struct kim_data_s), GFP_KERNEL); Considering the 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 --- Note: build-tested only. --- drivers/misc/ti-st/st_kim.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c index fe682e0553b2..a034b5d8b585 100644 --- a/drivers/misc/ti-st/st_kim.c +++ b/drivers/misc/ti-st/st_kim.c @@ -590,7 +590,7 @@ static ssize_t store_dev_name(struct device *dev, { struct kim_data_s *kim_data = dev_get_drvdata(dev); pr_debug("storing dev name >%s<", buf); - strncpy(kim_data->dev_name, buf, count); + strscpy(kim_data->dev_name, buf, count); pr_debug("stored dev name >%s<", kim_data->dev_name); return count; } @@ -751,7 +751,8 @@ static int kim_probe(struct platform_device *pdev) } /* copying platform data */ - strncpy(kim_gdata->dev_name, pdata->dev_name, UART_DEV_NAME_LEN); + strscpy(kim_gdata->dev_name, pdata->dev_name, + sizeof(kim_gdata->dev_name)); kim_gdata->flow_cntrl = pdata->flow_cntrl; kim_gdata->baud_rate = pdata->baud_rate; pr_info("sysfs entries created\n"); --- base-commit: 6465e260f48790807eef06b583b38ca9789b6072 change-id: 20230927-strncpy-drivers-misc-ti-st-st_kim-c-e1663a211a0c Best regards, -- Justin Stitt