Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5642891img; Wed, 27 Mar 2019 12:17:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/p2GZ52YUlPqa33MheYEfjQVfXx6jfFm1suzHKoR3bFYVMofqB9BaDKjuiOgMNUm6uNru X-Received: by 2002:a63:594a:: with SMTP id j10mr36117762pgm.279.1553714253993; Wed, 27 Mar 2019 12:17:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714253; cv=none; d=google.com; s=arc-20160816; b=w46SNQ4zEN5jgvD6XTqjpN1ZsbjjoFdCc4Eiq0KaWRAc5Fn+Y79ADS2UPcDk/aJL+p pXAaYAUr/nwKZxDEIhe7y7cUH2CK6f2V26gTTNJadmzmGfqSegYl6dqlMQa50yB0jv3R qaaCXc/7SFqbemqXyGoLWuPPhvGeDnya69/rqTaq87O+CJAGbadbuGVXH1phmtP4iW47 kmHhUFTn1BOYuVQsRCvt3pD+6OcU1RFomaTt22vNT+VGFaeRjH6j2PmXEzWv1l+BagA7 iyVkSvdf29p8hBlBC42SrVIL7FanpkvLLgWryXYct6vH2DUn5vS7ACLfVnM39Ix3LoEi jIGw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cYuL/NhMlQ3rhpLbBhsa8tQv84Ex3g+RwmwYffeQS6I=; b=QolLt9JG6qqOkc4GIoUUfBcoDNUmaEY14xq649Tg1fTOl4hQC5puOlfDPJLDkmSVTg FtMY0WuLUJeVWR7l9ZB2uaOKD0fMmxQimfjObzatO2IvQFkthmJoI95gM4lZnpCs7Ri1 VLo0pst4yr3Hw7riRr18MIQELYTRazXNuyUQpAj8sVFPHe4oOkL5Yx/YUyB7nlqRSELS 2H/gGXEnI8QmY0Saatc8pwNIck+quKWeT2q00EIAWG41I5S+uTf4Pi81yiXvo1fP/bI8 EAy92qJVqpCoykGQY3eZW/KmhVESz495/KF0iPefVe2yk4G8QOAblqt5DPoygvfJxko1 zrGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bpEB5x3+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i18si18361708pfa.205.2019.03.27.12.17.17; Wed, 27 Mar 2019 12:17:33 -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=bpEB5x3+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387475AbfC0SJB (ORCPT + 99 others); Wed, 27 Mar 2019 14:09:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:50756 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731344AbfC0SI6 (ORCPT ); Wed, 27 Mar 2019 14:08:58 -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 5590321734; Wed, 27 Mar 2019 18:08:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710137; bh=g4LIPHHqvn7S6g33XK7Gxc4cLtQ4LoESKGrGQ+bYvdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bpEB5x3++/QM/ijKCZ05ftmIN8yYv0bWraT43rS2Bl4o8w3YgauJqIAWKcIJhhD9w +CzfkBjhK/M75PKXYkg3bL+shuVFJi32zs0gmQUaSmQXo+qs5qTpqNIQHys7GRGXu/ 9FzYgmGjTDrYdxhvr1HYybH7ig1ucJDOxDAvzhkU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tony Jones , =?UTF-8?q?Jaroslav=20=C5=A0karvada?= , Jonathan Corbet , Ravi Bangoria , Seeteena Thoufeek , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 5.0 213/262] perf script python: Use PyBytes for attr in trace-event-python Date: Wed, 27 Mar 2019 14:01:08 -0400 Message-Id: <20190327180158.10245-213-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tony Jones [ 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 87ef16a1b17e..2fe3cc43526f 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