From patchwork Mon Dec 28 12:41:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 352707 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp9824172jai; Mon, 28 Dec 2020 07:19:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2onnYmPHvqS9v8iyaiwh+3NTKOC6dN0OB0PD+41jG13dQ/yJZG6dGrnd9kx4Cvjvs8nuZ X-Received: by 2002:a50:d4d9:: with SMTP id e25mr42856809edj.243.1609168781088; Mon, 28 Dec 2020 07:19:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609168781; cv=none; d=google.com; s=arc-20160816; b=ZJ4T6o1kaGk9aD+qaq9ZydPCmDstd58o+dbLhjaPsoW9QjxxJkZ4Idzg/zX0gtkBty G/4f0YJ2bo8ow+56dawGbpHiwmnJEjxwTjGmdrk76N+45KWw3fx2klQ4XVc3e08tN/if +qdHZQShvm26EQKXJ1F7M6nKqg3Pdy8Dgu3nSzDl9cIVhKcsdK2oYyVkk/L2+ysJGbpM IJQBWzIuv5mrW76F6h9osoGyGJkmRCvtCh43iYPJ67kAy5RLE/ZMesWjJ1ks/JOZTAt2 CJvbLCDSqHMRmaFH664mNmpb7M75/It29MGqn+EGoXVmZIdZnubtkjTHgmuYVMTUcvL5 Ea6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=W1p9u2MSX2J3Z80fZi2QvJcFgAVKY8OLo6TXXTdobOo=; b=MEvPsoMJsHB/dMdADkCA6jFun8S5rSZfzIiI/5g4cWl+E55FSafZEshchGRIUbbhsy jAc2GwETDGEVJXyZdJdkLGi8ORHBsH0hhxevp3+J7ft0bSg1jOctDFQWPtFHqMyucvUS a1dfUu2scOhm2ISdjtr5rPOdwg0Lq5NEkpL5+U/Y/FwBSNyalHX6YLIq5VpKE6OP1b2N wcXWAhkDfpYvQByiduGuFr+PdszpbgBLL6EzpXQRrH+2vUoMXA4awLx6srrpXcW5A/rF UGLJ/E8IkQexCOFaWmcLYlkDq0d7OXLg/J/Q2khKwyAhL0W2iHlr2ubDbv9RYRFALfkZ EXSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qfgg3QwA; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m12si18130037ejr.608.2020.12.28.07.19.40; Mon, 28 Dec 2020 07:19:41 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qfgg3QwA; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437085AbgL1ODK (ORCPT + 14 others); Mon, 28 Dec 2020 09:03:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:36052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437080AbgL1ODK (ORCPT ); Mon, 28 Dec 2020 09:03:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1AA2520731; Mon, 28 Dec 2020 14:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609164174; bh=2pvhYvUzwcybc2jQ10HmamX+/mZrNl18i/D1YMlQHWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qfgg3QwAjlCRdYTBki5QDVy/bLqFtrIn1tBzFd/Ec/LbkprWB2MZE5gkr3MPPjw9b Em99QBuNZWiHodi9BospNp4OITgBlHTRf05+fcoWoM8eV1zEGoPz2zzQdBl2MXI7iV H0iS52SjVJqMK05n+u6aFkuVxGCRVc1ZYGddO93M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Jon Hunter , Thierry Reding , Sasha Levin Subject: [PATCH 5.10 088/717] firmware: tegra: fix strncpy()/strncat() confusion Date: Mon, 28 Dec 2020 13:41:26 +0100 Message-Id: <20201228125025.195144057@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Arnd Bergmann [ Upstream commit 9294996f0be40e9da818ed891c82397ab63c00d0 ] The way that bpmp_populate_debugfs_inband() uses strncpy() and strncat() makes no sense since the size argument for the first is insufficient to contain the trailing '/' and the second passes the length of the input rather than the output, which triggers a warning: In function 'strncat', inlined from 'bpmp_populate_debugfs_inband' at ../drivers/firmware/tegra/bpmp-debugfs.c:422:4: include/linux/string.h:289:30: warning: '__builtin_strncat' specified bound depends on the length of the source argument [-Wstringop-overflow=] 289 | #define __underlying_strncat __builtin_strncat | ^ include/linux/string.h:367:10: note: in expansion of macro '__underlying_strncat' 367 | return __underlying_strncat(p, q, count); | ^~~~~~~~~~~~~~~~~~~~ drivers/firmware/tegra/bpmp-debugfs.c: In function 'bpmp_populate_debugfs_inband': include/linux/string.h:288:29: note: length computed here 288 | #define __underlying_strlen __builtin_strlen | ^ include/linux/string.h:321:10: note: in expansion of macro '__underlying_strlen' 321 | return __underlying_strlen(p); Simplify this to use an snprintf() instead. Fixes: 5e37b9c137ee ("firmware: tegra: Add support for in-band debug") Signed-off-by: Arnd Bergmann Acked-by: Jon Hunter Signed-off-by: Thierry Reding Signed-off-by: Sasha Levin --- drivers/firmware/tegra/bpmp-debugfs.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) -- 2.27.0 diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c index c1bbba9ee93a3..440d99c63638b 100644 --- a/drivers/firmware/tegra/bpmp-debugfs.c +++ b/drivers/firmware/tegra/bpmp-debugfs.c @@ -412,16 +412,12 @@ static int bpmp_populate_debugfs_inband(struct tegra_bpmp *bpmp, goto out; } - len = strlen(ppath) + strlen(name) + 1; + len = snprintf(pathbuf, pathlen, "%s%s/", ppath, name); if (len >= pathlen) { err = -EINVAL; goto out; } - strncpy(pathbuf, ppath, pathlen); - strncat(pathbuf, name, strlen(name)); - strcat(pathbuf, "/"); - err = bpmp_populate_debugfs_inband(bpmp, dentry, pathbuf); if (err < 0)