Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp877746pxk; Thu, 17 Sep 2020 20:05:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnPT5kC8hjlMUg9MoLL5Qcj5lWhf3wHZRss40M5q86wi58otjhp/Hxz8fVB8200O9ZIxzQ X-Received: by 2002:a17:906:b146:: with SMTP id bt6mr33329965ejb.287.1600398358278; Thu, 17 Sep 2020 20:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398358; cv=none; d=google.com; s=arc-20160816; b=QkEZ7O7KKiU5GtQxG0Pkmi7Pb7k/LqZ8crNco38Vfero0rrHjnPDQrywJwGVb+6iZR ftyvWynQyDD80LDIB2TConkh/J/t4FH/wJw7V9eFFg4JyFhh1CSkSuQ8S9aBffJDO7K2 fm9KoLDsUsAjFD1rqINUWbiek/bc0A9qcnHEMfawjzlsqxizlAm9XixmF033uzL8bwhO YtP3lRwaBlGpQFKAMKdlGTvsxOLusPbRtvxX32tQRauL/4qWvGxFspU7itICIlqo6h/g qUd17M+yOoaZgn973zCmprquCE7ORxWq422bjwsc9i7/9ZH7T/B7y7sd/Zzv1nTVLB+l JocA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A1ht/pfp8XH+MLS+tKpcukG55Q+NKP1g/jkBfDZP8sk=; b=S1wOYahVarPmr+/DbgdW0k6FriXTOsVMN95dD0nP1Ggx3BIornqDd+D7P3Q94ZVLkF Mz9boILNPGA9HdoP9ueERylcvRiR9jfOWXihqzSFhC31mDRmoilrvlXUkLwU/VRkUYHy zIi5oavmMouSkvC43ECU6X2aG9oQLSSozw2lY+pqAkahAhtKijGEwDwrGGo4s6aJnG01 Yz/u5Oz9QJmIQ2D7eeSNURQMPU4iloqCTTfciCOy76efM7DS2+5aoO00udZ7uor76ND/ 6OHwAJKlZQX+cLh4ESUEOTJYOeWkP7mSpqDV9Kfp3DV6ERWxjFcbe411nT0jCpjnwVED lTnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=csgEDa0y; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si1098628edi.512.2020.09.17.20.05.34; Thu, 17 Sep 2020 20:05:58 -0700 (PDT) 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=@kernel.org header.s=default header.b=csgEDa0y; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728536AbgIRDDP (ORCPT + 99 others); Thu, 17 Sep 2020 23:03:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:53148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727412AbgIRCFI (ORCPT ); Thu, 17 Sep 2020 22:05:08 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C4B352344C; Fri, 18 Sep 2020 02:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394708; bh=rWMufWl3bYjWXmiA1ctYATk98OZ2gdOzkhxi01F/kE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=csgEDa0yLxCN5YbX3oaf43jbxgru9SIeF4K6tCSrXlV4d2PY00TbNk1x2TsmmnUhz WkZES0Pd0O5He1KEwYQQjxUTVj6L64eoboyrwOZ685+lORewIgvOZAhmsnDF3rl+t9 AfN30WOYTgfbCHYIvaHa9AqRsiuv0dcDsU6Eg+BM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Christophe JAILLET , David Laight , Alexander Shishkin , Don Zickus , He Zhe , Jan Stancek , Jiri Olsa , Kan Liang , Mark Rutland , Namhyung Kim , Peter Zijlstra , kernel-janitors@vger.kernel.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 5.4 193/330] perf cpumap: Fix snprintf overflow check Date: Thu, 17 Sep 2020 21:58:53 -0400 Message-Id: <20200918020110.2063155-193-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET [ Upstream commit d74b181a028bb5a468f0c609553eff6a8fdf4887 ] 'snprintf' returns the number of characters which would be generated for the given input. If the returned value is *greater than* or equal to the buffer size, it means that the output has been truncated. Fix the overflow test accordingly. Fixes: 7780c25bae59f ("perf tools: Allow ability to map cpus to nodes easily") Fixes: 92a7e1278005b ("perf cpumap: Add cpu__max_present_cpu()") Signed-off-by: Christophe JAILLET Suggested-by: David Laight Cc: Alexander Shishkin Cc: Don Zickus Cc: He Zhe Cc: Jan Stancek Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: kernel-janitors@vger.kernel.org Link: http://lore.kernel.org/lkml/20200324070319.10901-1-christophe.jaillet@wanadoo.fr Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/cpumap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index a22c1114e880d..324ec0456c83f 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -299,7 +299,7 @@ static void set_max_cpu_num(void) /* get the highest possible cpu number for a sparse allocation */ ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/possible", mnt); - if (ret == PATH_MAX) { + if (ret >= PATH_MAX) { pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); goto out; } @@ -310,7 +310,7 @@ static void set_max_cpu_num(void) /* get the highest present cpu number for a sparse allocation */ ret = snprintf(path, PATH_MAX, "%s/devices/system/cpu/present", mnt); - if (ret == PATH_MAX) { + if (ret >= PATH_MAX) { pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); goto out; } @@ -338,7 +338,7 @@ static void set_max_node_num(void) /* get the highest possible cpu number for a sparse allocation */ ret = snprintf(path, PATH_MAX, "%s/devices/system/node/possible", mnt); - if (ret == PATH_MAX) { + if (ret >= PATH_MAX) { pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); goto out; } @@ -423,7 +423,7 @@ int cpu__setup_cpunode_map(void) return 0; n = snprintf(path, PATH_MAX, "%s/devices/system/node", mnt); - if (n == PATH_MAX) { + if (n >= PATH_MAX) { pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); return -1; } @@ -438,7 +438,7 @@ int cpu__setup_cpunode_map(void) continue; n = snprintf(buf, PATH_MAX, "%s/%s", path, dent1->d_name); - if (n == PATH_MAX) { + if (n >= PATH_MAX) { pr_err("sysfs path crossed PATH_MAX(%d) size\n", PATH_MAX); continue; } -- 2.25.1