Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3331884imu; Sun, 11 Nov 2018 12:33:14 -0800 (PST) X-Google-Smtp-Source: AJdET5fjpcvwZ+jKHL05Den6nVRNuG4wvw8JHDjldS8JY0ldDfTqA8pzk6olcuCrkOT2eZ7bY4xf X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr17168536plb.239.1541968393922; Sun, 11 Nov 2018 12:33:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968393; cv=none; d=google.com; s=arc-20160816; b=f7v85T3OmOAYA0uXCXABYfAPjCZpJA8ymAXGLgXmhtS71yD5mILjagqSs/uOm7n2My AYrBOkMUb7k6oyJ4trPypYMDYV1wn+9tC3PX0EC+gPvMCCv1YHQPhzDb9vxePM8tdpDS 8p8LOzJtIRNO9oFThr+xQwFyyFwJewl9SOx5kvV4l8UuhEH8XEd4unF1dx5UTZEZCuyB nAh+6vphx7TGBvVUDUVDag60N1iOHUpAAxcaveg/C62TqHN1CmIU0r5nE1MoRZ7UfQa7 CgDhrGP9F3tEBfiGosxX4wJaWvjKuyypPdOYLTwSYwxQq1NJgN28D7KbAY/+IX7ST8Hx zpQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=5iYiU6EZpf7eLxXRx6OKmTK59wk20EKoXzkVwim8KlA=; b=D6ZCF+qncGFAmb1XDGvhYrtClD9xOK3qo27Dzh4NBuBCd8RkU5uAhkmbkaJUnq6UNl 7vellwp4CKpb92EPzxJzI2tPfda693k4XlrhZ8qss17K2BAAvb6EOn8HRrD5aJwIh6Fg hKKBESvqPx7pvAdU4VJ5XKb7zNXvpGY9/Suoi3kNI3dxDrt6NlmMU/oEG4xn4ot1x1fP V0UrogEGZ0us+rsSL6RlDBTSPv9AnjCsGEISJDaz/MGk4r8cmjxZwMjD83nudA9u8T64 MjiqGeJCzjA+HsGuXgLEm4SafqM2EP+qRc9RhbTedaO4wH0/hM0ENWlfUcV2skLH26Mb 1GbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si14552452pgi.387.2018.11.11.12.32.59; Sun, 11 Nov 2018 12:33:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730526AbeKLGWH (ORCPT + 99 others); Mon, 12 Nov 2018 01:22:07 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50202 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730293AbeKLFsR (ORCPT ); Mon, 12 Nov 2018 00:48:17 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsd-0000tu-U9; Sun, 11 Nov 2018 19:58:47 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsb-0001tt-0o; Sun, 11 Nov 2018 19:58:45 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Wang Nan" , "Adrian Hunter" , "David Ahern" , "Arnaldo Carvalho de Melo" , "Jiri Olsa" , "Namhyung Kim" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 365/366] perf thread_map: Correctly size buffer used with dirent->dt_name In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Arnaldo Carvalho de Melo commit bdf23a9a190d7ecea092fd5c4aabb7d4bd0a9980 upstream. The size of dirent->dt_name is NAME_MAX + 1, but the size for the 'path' buffer is hard coded at 256, which may truncate it because we also prepend "/proc/", so that all that into account and thank gcc 7 for this warning: /git/linux/tools/perf/util/thread_map.c: In function 'thread_map__new_by_uid': /git/linux/tools/perf/util/thread_map.c:119:39: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 250 [-Werror=format-truncation=] snprintf(path, sizeof(path), "/proc/%s", dirent->d_name); ^~ In file included from /usr/include/stdio.h:939:0, from /git/linux/tools/perf/util/thread_map.c:5: /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 7 and 262 bytes into a destination of size 256 return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-csy0r8zrvz5efccgd4k12c82@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Ben Hutchings --- tools/perf/util/thread_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/tools/perf/util/thread_map.c +++ b/tools/perf/util/thread_map.c @@ -63,7 +63,7 @@ struct thread_map *thread_map__new_by_ui { DIR *proc; int max_threads = 32, items, i; - char path[256]; + char path[NAME_MAX + 1 + 6]; struct dirent *dirent, **namelist = NULL; struct thread_map *threads = malloc(sizeof(*threads) + max_threads * sizeof(pid_t));