From patchwork Wed May 12 14:50:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 435611 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp5061830jao; Wed, 12 May 2021 11:07:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytQjgmNjcfOZdmH4cvfU0UqhJ9Qwtsut+VZkNiSFFZZxhxv3rJV2jk5hjWeU4N/KYL6bWJ X-Received: by 2002:a05:6e02:144f:: with SMTP id p15mr31667628ilo.143.1620842825273; Wed, 12 May 2021 11:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620842825; cv=none; d=google.com; s=arc-20160816; b=pdGvhCZ1gkGqpl7VSDneHgQHMw7P4dhAjwdg0mJCOmzqCE66RkoCHfNKxklayN38go w+pw+scZj2WXDM+ppHsGfsbxprrqhkFfrZK+xIr/uRTs6nx2u/G2HJonRDWGZ2jTpXAd 6mAbEJvdYsOo6H6wA4M98ZEfjHQNfIyPGfyqsJIYUUoUzbechhR2xy8LrEgoTvQIisHE csl1Qv+U2yy3DDk2brX/B4peGz3cLaznn5SZpvB5Hc9ww68e/KCXfLc//LDWp48gChVI 850JwTVqFMcxWZs0GgrV4P/WmBqiU5bU3nG8bNP9giQJ5PN2BIB4ZMy3J++X4ZKPmRGG bS5w== 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=MFbQm8trvtxgq720BINEyX68+1P2Ok0E87Qm9wJDIpc=; b=HfVLkv6woJFBtjRXHsTSsK5RhE6Js45VeYtL+naBKl2xFHecBwFbb899MFzSBR4PE6 YmYJNi0IW5b2/D//2nr0rGZp04x6HqVBkc23cCvKvvC7LQ1No8UoUm6E0FAd+BkMzbdl Lo3Sk6glAGPAzZle3PvCt9WTdQZzTOjelVLX8rnCJsxmpkceanA8gWOUeqairGHS1PYX Vto3SGa9fthFXILKHeAg0i2BemG6DaGbEZc9qPd/FSiSI5H9TvqULLuExODO04gCkcma hv2S71TDkruOHBgjisHfo5ttRqQtzG0ZHO7cfVMWzsvqeohu9Bhu/j+qUGbr9daXiFEt vcag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=epTBl9az; 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 q8si330223ior.12.2021.05.12.11.07.04; Wed, 12 May 2021 11:07:05 -0700 (PDT) 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=epTBl9az; 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 S241744AbhELQaq (ORCPT + 12 others); Wed, 12 May 2021 12:30:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:35964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237745AbhELQYh (ORCPT ); Wed, 12 May 2021 12:24:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9BAD4619B1; Wed, 12 May 2021 15:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620834476; bh=SHgL87Fqqus74sID+k6cGRA9Yz8SA8JOMh1QVIuAZc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=epTBl9azULha7G0lA1m3JvZxmXYE8kAusJiUjIQf3dEqjvkgMe13xZNQ6d9AO/+x3 0zor2JBnAi18ZweGqVe/aZUpR6FldTlrV/v3007yX363aKy9AvQSi/zoXbSyIWmrGz /1ZSzL0NZHYLOakx0Vw+lqD0FlImVO91X+kX0K3g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Kalle Valo , Sasha Levin Subject: [PATCH 5.11 524/601] wlcore: fix overlapping snprintf arguments in debugfs Date: Wed, 12 May 2021 16:50:01 +0200 Message-Id: <20210512144845.112361052@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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 7b0e2c4f6be3ec68bf807c84e985e81c21404cd1 ] gcc complains about undefined behavior in calling snprintf() with the same buffer as input and output: drivers/net/wireless/ti/wl18xx/debugfs.c: In function 'diversity_num_of_packets_per_ant_read': drivers/net/wireless/ti/wl18xx/../wlcore/debugfs.h:86:3: error: 'snprintf' argument 4 overlaps destination object 'buf' [-Werror=restrict] 86 | snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 87 | buf, i, stats->sub.name[i]); \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/wireless/ti/wl18xx/debugfs.c:24:2: note: in expansion of macro 'DEBUGFS_FWSTATS_FILE_ARRAY' 24 | DEBUGFS_FWSTATS_FILE_ARRAY(a, b, c, wl18xx_acx_statistics) | ^~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/wireless/ti/wl18xx/debugfs.c:159:1: note: in expansion of macro 'WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY' 159 | WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(diversity, num_of_packets_per_ant, There are probably other ways of handling the debugfs file, without using on-stack buffers, but a simple workaround here is to remember the current position in the buffer and just keep printing in there. Fixes: bcca1bbdd412 ("wlcore: add debugfs macro to help print fw statistics arrays") Signed-off-by: Arnd Bergmann Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20210323125723.1961432-1-arnd@kernel.org Signed-off-by: Sasha Levin --- drivers/net/wireless/ti/wlcore/boot.c | 13 ++++++++----- drivers/net/wireless/ti/wlcore/debugfs.h | 7 ++++--- 2 files changed, 12 insertions(+), 8 deletions(-) -- 2.30.2 diff --git a/drivers/net/wireless/ti/wlcore/boot.c b/drivers/net/wireless/ti/wlcore/boot.c index e14d88e558f0..85abd0a2d1c9 100644 --- a/drivers/net/wireless/ti/wlcore/boot.c +++ b/drivers/net/wireless/ti/wlcore/boot.c @@ -72,6 +72,7 @@ static int wlcore_validate_fw_ver(struct wl1271 *wl) unsigned int *min_ver = (wl->fw_type == WL12XX_FW_TYPE_MULTI) ? wl->min_mr_fw_ver : wl->min_sr_fw_ver; char min_fw_str[32] = ""; + int off = 0; int i; /* the chip must be exactly equal */ @@ -105,13 +106,15 @@ static int wlcore_validate_fw_ver(struct wl1271 *wl) return 0; fail: - for (i = 0; i < NUM_FW_VER; i++) + for (i = 0; i < NUM_FW_VER && off < sizeof(min_fw_str); i++) if (min_ver[i] == WLCORE_FW_VER_IGNORE) - snprintf(min_fw_str, sizeof(min_fw_str), - "%s*.", min_fw_str); + off += snprintf(min_fw_str + off, + sizeof(min_fw_str) - off, + "*."); else - snprintf(min_fw_str, sizeof(min_fw_str), - "%s%u.", min_fw_str, min_ver[i]); + off += snprintf(min_fw_str + off, + sizeof(min_fw_str) - off, + "%u.", min_ver[i]); wl1271_error("Your WiFi FW version (%u.%u.%u.%u.%u) is invalid.\n" "Please use at least FW %s\n" diff --git a/drivers/net/wireless/ti/wlcore/debugfs.h b/drivers/net/wireless/ti/wlcore/debugfs.h index b143293e694f..715edfa5f89f 100644 --- a/drivers/net/wireless/ti/wlcore/debugfs.h +++ b/drivers/net/wireless/ti/wlcore/debugfs.h @@ -78,13 +78,14 @@ static ssize_t sub## _ ##name## _read(struct file *file, \ struct wl1271 *wl = file->private_data; \ struct struct_type *stats = wl->stats.fw_stats; \ char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = ""; \ + int pos = 0; \ int i; \ \ wl1271_debugfs_update_stats(wl); \ \ - for (i = 0; i < len; i++) \ - snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \ - buf, i, stats->sub.name[i]); \ + for (i = 0; i < len && pos < sizeof(buf); i++) \ + pos += snprintf(buf + pos, sizeof(buf), \ + "[%d] = %d\n", i, stats->sub.name[i]); \ \ return wl1271_format_buffer(userbuf, count, ppos, "%s", buf); \ } \