Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8986396ybi; Tue, 23 Jul 2019 19:30:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFe9Xd4uXx6vZlEpSfg0uz661sD5FCXMtxxEEZBjwCIrskJ2FEEKpsWV4HSKQve4fyXKRk X-Received: by 2002:a17:90a:8c06:: with SMTP id a6mr86884647pjo.45.1563935452726; Tue, 23 Jul 2019 19:30:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563935452; cv=none; d=google.com; s=arc-20160816; b=RfXW5QdWmBXZJX6YtHMF16BR/LmI77P7qtyqhZlyLZU/r6tjlKbKaJ4arSX2jhN0Dy 2g/kFm3lN8JttIIkn0YBK8lbXQVjFsUvJ9NotCD969dC5J/Q26EFH8pEv1cEP3v2pu2+ Gy8LWnlnMWbyTRavLf6VwgdD/2cbOfeE5muejjc7CNCUN5NARSmh+y6xerX7+kbXPWZq mC0b68RYVd69hKFPMZnxzaEoxvnYlU2j48uh34N/HcVL/AD6XeND+jhDnxGoLq8miLK2 kSm9jYK1PABYBvs3RMOSRY0egg+j8YVFKYEyHyJqyACiXE62ZzlBoNE5ZerOZ1YQkBIP ndmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:date:from:dkim-signature; bh=HSqeERIVrrWNRJGBPRu/DavE1UKkc6TVYy1oqy1qzFk=; b=TtIFJuWgw9BRaqjbmzZBekRYssgvompgmbbrdnthk5loGiMVdh2wDZgEOrBCHImuYN LhLK0Vee3wueoSrfaKl147xMPXetXwPpoeB7fPNDdaZyy5EI/7aCqO1nFD7aJAWpt/hP 9FH3jvZHE7/hrOyYfvA/0wojOHBhkEEaLPIy/7Fa7s2VUvfHxvD4t8BuBgKjrxoe0Fgv FprAxu32u0qeLp8oOx028pqfkjdgaJtHECRU7LWSJ5IcYU8bCLL5MeBcV3wf7v7VBE6/ weDoiNJfm/MWsYyrQwTyNOXckP6GSxbVmwh1iOB8LPr9gzhUpOLHUwRC11W9OCd7JW0N kv6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@maine.edu header.s=google header.b=Q5a8LDnL; 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 k32si12678977pjb.11.2019.07.23.19.30.37; Tue, 23 Jul 2019 19:30:52 -0700 (PDT) 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; dkim=pass header.i=@maine.edu header.s=google header.b=Q5a8LDnL; 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 S2391837AbfGWUme (ORCPT + 99 others); Tue, 23 Jul 2019 16:42:34 -0400 Received: from mail-qk1-f182.google.com ([209.85.222.182]:43110 "EHLO mail-qk1-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726920AbfGWUme (ORCPT ); Tue, 23 Jul 2019 16:42:34 -0400 Received: by mail-qk1-f182.google.com with SMTP id m14so6445941qka.10 for ; Tue, 23 Jul 2019 13:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maine.edu; s=google; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=HSqeERIVrrWNRJGBPRu/DavE1UKkc6TVYy1oqy1qzFk=; b=Q5a8LDnLnxwPPp1uXvPjDmqYEATc1C0TF9Bnd9Qtmm/8/RjCNFVbH1WlKCtMhq9n5+ 1HdHN0OakFy5sKHnxj1HbG+Ut+ztkWKC0wFIO3XP9Imfckix3FbpHfKTY2sAMAfj1LJz fHGV6NWaSINJSyq4sJ28QRsi9rW/yltdVDkLk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=HSqeERIVrrWNRJGBPRu/DavE1UKkc6TVYy1oqy1qzFk=; b=X9JTw53xYvZCpnkB0l1xUUQmzgD1yuhrVmMcbJnLUmESzJtIG2+5WNFWKX/ogcSSNA GuV2asev/EJbRjiK/1IeVXqZmX0OTub9GfyzxL62Yy5TyZNuaMqj/43rvfV6csp6URTj mMN34zwRHYjwC6ICpSZNxRwP+S054OP/YL/X/usD3bSXLZx9oLV/OFj/+okw8oMhptXv xXEwehH4Gx3xxFIaycdhoJ5VtrVfJKTfRN1JExFjE5lYfboP23pId0EPeofMjXgRTzaA Q2OzOZW28iu0koNYtdNuTnG75ZZC+Aws0uAOVTxa5UygFwvtn4wbw9QFITjFub1dYGGD xXpw== X-Gm-Message-State: APjAAAWQWwm/Gs6ZKCCiVZBgatVOluzrOXD+ey2y5tuwbIs2VrxYsKlX SWtLDWQ6c1vGTcQf1xnS1tqmcUbFMKY= X-Received: by 2002:a05:620a:142e:: with SMTP id k14mr51238951qkj.336.1563914552595; Tue, 23 Jul 2019 13:42:32 -0700 (PDT) Received: from macbook-air (weaver.eece.maine.edu. [130.111.218.23]) by smtp.gmail.com with ESMTPSA id f25sm23360508qta.81.2019.07.23.13.42.31 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 23 Jul 2019 13:42:31 -0700 (PDT) From: Vince Weaver X-Google-Original-From: Vince Weaver Date: Tue, 23 Jul 2019 16:42:30 -0400 (EDT) X-X-Sender: vince@macbook-air To: linux-kernel@vger.kernel.org cc: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim Subject: [patch] perf tool buffer overflow in perf_header__read_build_ids In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello my perf_tool_fuzzer has found another issue, this one a buffer overflow in perf_header__read_build_ids. The build id filename is read in with a filename length read from the perf.data file, but this can be longer than PATH_MAX which will smash the stack. This might not be the right fix, not sure if filename should be NUL terminated or not. Signed-off-by: Vince Weaver diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index c24db7f4909c..9a893a26e678 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2001,6 +2001,9 @@ static int perf_header__read_build_ids(struct perf_header *header, perf_event_header__bswap(&bev.header); len = bev.header.size - sizeof(bev); + + if (len>PATH_MAX) len=PATH_MAX; + if (readn(input, filename, len) != len) goto out; /*