Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9076721pxu; Mon, 28 Dec 2020 06:06:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwjDkBnn3uY5gLpzglep8xx0L5I/Jf1I+1tHnCtb8NaSrfYsuwnJ19ynNhBPPqp1WLyBL5 X-Received: by 2002:a7b:c770:: with SMTP id x16mr20872364wmk.139.1609164366376; Mon, 28 Dec 2020 06:06:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609164366; cv=none; d=google.com; s=arc-20160816; b=SDq4com4607ha58lIyKoymSTM0KJCEDkIpP2yXpEImiP/g+l71TU1LwegXzolJ0aQ8 UXr0aOzqzE0wOGzDRJu2tV/TnXAG7rvxP4H0sU2bWVMC3PI5S7x4FCFOUYb2yqNojZfQ H2kcKXr/YH5JeJIy/F7QnI+b16gJ3qZYgl5SuUjgXaHRQXB7YTAZOd5440ajafZ1W7te YaWjKsaV3+Le13e46oJaQAVuaBLZ6eH0EOG5syhXZp6/3oMTYBVN8pOWik0ScTrYNwmT Ee1Cud9+qUF6EDSKHQtjyMnv31yauQd6n2nofRKjo8UhRXRSD0ww4htNzh+KYFWmY/rG vtzw== 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=CNZH1W7NHbsn/y7HI/uHRLNP6aIlZ2a3Nt3lOKzPItv5veJjulQoevNrexJL8LMpRn YGt5icetkgiyZXSXoqsfhKvkU3B98mKzNpK5z/blzuCKXV1RrkPMUWSdRdT3p+kQ2Go0 xxVytr96zA+FltGm0aV60gprVsSkmJ22EM1fjlErddLwdiduto1HEktFb3C4wUmsEM+d RPS67vAj2msEbPS5BLT9owYkG5cTcTH1meCExiBFG/EE7pGiK/07/Fayem5Zv8o9kGx1 GzO3HS5OtY2aCbbxk6qit2kYIOz2WoTRrKpxliKoaYZkBXhwr5A94s4JgLk0KF76WwBv KDJQ== 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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 j22si19745616edh.496.2020.12.28.06.05.43; Mon, 28 Dec 2020 06:06:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S2437137AbgL1ODZ (ORCPT + 99 others); Mon, 28 Dec 2020 09:03:25 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(-) 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) -- 2.27.0