Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1023048yba; Thu, 4 Apr 2019 02:38:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNI7Q8YryF/7Oqc+nIpsBli/xOPWGIALx2trEGO0VCjgdVw5pMef+bJGRwCZ/LruWThXX5 X-Received: by 2002:a17:902:7b96:: with SMTP id w22mr5418687pll.28.1554370738703; Thu, 04 Apr 2019 02:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554370738; cv=none; d=google.com; s=arc-20160816; b=AqUXV391ogpIoJf5qlkenmLB+onV8JLOsKjPDcmMUoQ1y0o0g0VX0XRxOZUojEDzhx IA92aUFV9HlYRQWBSiiCK3qVyjU7rLo8FxraBIhkgCOak52r+ULiW4gU68kNnF3aTIhn zsN9SIw9A2WpJ97OHEPWRx6a6+jSLh+LHfh+e0T4yu7n4sTymzaAIodmQdhI/D59QgAH Y7yW1AHNU0ZPObwy6Z+IC/Lt9QQpgh0I6kLmNIpuxpbNvsRdkU2eUZERlhprawRHrFoQ bOb9VPn+Lxxzhl6xuSx9QGt7d75bsicmFpTlaId/YmFZD6NrfKv+NJ8igVNCnW+LejKs of2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UeNmUe9G9bfx/Ila/rDwhBbPWg8QdWA6i4FqC//87yw=; b=u/dGjtOan8PGZJsfhf5mVtkPV93E7EBEItOa8wY6PWckYPOajANaj5ht41oKgghJO4 bDzy3csL8EuuMdOQv1XKte5fxEtWCH8BFXVkO0GsPSWelViekocgi9V/91qLiXKK9kJz 37vV0LAY8fk13/Nmg0tWHSwc9u1YWe+T5k6625E2NMe627LwCB9ion0G01COrP6w16jk tP6DXsC/jT73rmUA+7+83l6gHelg2DKq9Lh2rANgR8SQjMw/KX/JmF4l1TaR8EK6TLgb uoSdaHarvGbW9AUDEuDCjfgKr+c/VZaILAefh4z135Gg8rtIctrf/0pfn+WtDw2P/wQu /g/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b4uHAc69; 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 t24si3187892pgu.597.2019.04.04.02.38.43; Thu, 04 Apr 2019 02:38:58 -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=@kernel.org header.s=default header.b=b4uHAc69; 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 S1732005AbfDDJFu (ORCPT + 99 others); Thu, 4 Apr 2019 05:05:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:44024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731373AbfDDJFp (ORCPT ); Thu, 4 Apr 2019 05:05:45 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 31B6A21850; Thu, 4 Apr 2019 09:05:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368744; bh=VKKP3klsGyIXHOKXSBG+UyT4TGosyarabfCi4ih8aj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b4uHAc69hRpV9EK0hsaYdEXz1a1f0DBNiKgBX9RqJV9lBVBc3mNZlirQiufqby8kI H/+jF8obRkQ5lEOHRH/ywSa/aP5X2XERq8suZX3JrI3+TIjKpdrtp4kFjzObbGEpln q9MYvGPgzSCzA9Fdh7b5dDeKBAh4x95ATZY+K5o4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tony Jones , Jiri Olsa , Arnaldo Carvalho de Melo , =?UTF-8?q?Jaroslav=20=C5=A0karvada?= , Jonathan Corbet , Ravi Bangoria , Seeteena Thoufeek , Sasha Levin Subject: [PATCH 4.19 154/187] perf script python: Use PyBytes for attr in trace-event-python Date: Thu, 4 Apr 2019 10:48:11 +0200 Message-Id: <20190404084610.371259451@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 72e0b15cb24a497d7d0d4707cf51ff40c185ae8c ] With Python3. PyUnicode_FromStringAndSize is unsafe to call on attr and will return NULL. Use _PyBytes_FromStringAndSize (as with raw_buf). Below is the observed behavior without the fix. Note it is first necessary to apply the prior fix (Add trace_context extension module to sys,modules): # ldd /usr/bin/perf | grep -i python libpython3.6m.so.1.0 => /usr/lib64/libpython3.6m.so.1.0 (0x00007f8e1dfb2000) # perf record -e raw_syscalls:sys_enter /bin/false [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.018 MB perf.data (21 samples) ] # perf script -g python | cat generated Python script: perf-script.py # perf script -s ./perf-script.py in trace_begin Segmentation fault (core dumped) Signed-off-by: Tony Jones Acked-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Jaroslav Škarvada Cc: Jonathan Corbet Cc: Ravi Bangoria Cc: Seeteena Thoufeek Fixes: 66dfdff03d19 ("perf tools: Add Python 3 support") Link: http://lkml.kernel.org/r/20190124005229.16146-3-tonyj@suse.de Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/scripting-engines/trace-event-python.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 05d95de14e20..fb11396ec861 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -733,8 +733,7 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, Py_FatalError("couldn't create Python dictionary"); pydict_set_item_string_decref(dict, "ev_name", _PyUnicode_FromString(perf_evsel__name(evsel))); - pydict_set_item_string_decref(dict, "attr", _PyUnicode_FromStringAndSize( - (const char *)&evsel->attr, sizeof(evsel->attr))); + pydict_set_item_string_decref(dict, "attr", _PyBytes_FromStringAndSize((const char *)&evsel->attr, sizeof(evsel->attr))); pydict_set_item_string_decref(dict_sample, "pid", _PyLong_FromLong(sample->pid)); -- 2.19.1