Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3009832ybi; Mon, 17 Jun 2019 14:36:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdqIIzDKCe/j39eDdPkQy4oNTKMdGoHh7VFgar3DWoaIxeseNXLQaATaQnKCDqlTujdQgj X-Received: by 2002:a62:2ccc:: with SMTP id s195mr52637391pfs.256.1560807388132; Mon, 17 Jun 2019 14:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807388; cv=none; d=google.com; s=arc-20160816; b=T6X7OJRMVsSvutoSAP14XGBI2n8bgBywIu//EStEk0afb/LbnQUrVm5IcEOKMx1s7h Q7/9rooPgUP7WgCSXUVeZXqGSkpHUxhNSGgy4pXy6u92Caj4IDvGQKcIrumnNJ2hdgFn j6QgD0zaGZIpc/BtMEQ5/iqQ8r7SGbjJjoG/E/uQAHQO32cMpmYqgvgP5ocCBzDUmDDc i74frDwjqJKGaUPzY5Wx0MRzgtPKF2ydvqQ+9uDTHnQGIqg73KUhyV3lC+8AhzcwsB+w y4M5H7wCFvwXlgW5X5kt7jYR120HlR8ZhbSR0uwxp8jJKp/VDfi4kGrhaxCsk+mrL5Wq Yvhw== 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=AuagKftXRFQMdNbOaT6frunlElxdq8qh7ge7PFzb6vA=; b=vT0yosoXMCwj4lW9UaePFei7WzfWhojz0EpVYgdqiYavScJdYZPE5J7w7HK/KRLsve CK1byRTwxYiu0rtSSTJIeWsscwbG3px4A1CfqpASnkkHEibRMt8X9WAmNLHSXdrPbmgS QScHVxZbkui7HdqSFIjtybL1GkOOhv95/tpM4ORDRyPDiqvIiyehK0vrt1180QokqXtM xbeth/CxQxRsP49sjVwc2Acfjf731ALOF9xmPPXBzLTOiPWf6ZWqKSx1N5OcC17bFsHl 6foU2cJw3fGG1bD9qcFNeX4lXbW9NjO+7Mv6D/UsKUKjbbssUrWzmEA3pAasiZ8vS/s/ 01KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D5FkdBUU; 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 y84si11884830pfc.33.2019.06.17.14.36.13; Mon, 17 Jun 2019 14:36:28 -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=D5FkdBUU; 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 S1729476AbfFQVWI (ORCPT + 99 others); Mon, 17 Jun 2019 17:22:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:46540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729446AbfFQVV7 (ORCPT ); Mon, 17 Jun 2019 17:21:59 -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 E1F5C20652; Mon, 17 Jun 2019 21:21:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806519; bh=oiaXuwdwqq/GHNRR2Kmron3M687TpMIX5+ylb2xkcXY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D5FkdBUUazlJ4ozwMyo9QjQ2lFvaLCEFWIeLT9fD8G6Vx+WunqK9gwiel6nyMJvug hbmZHwO0L3V+36xl9iHnCE14m/60mBvkeB3l9IKQifd0I+EjuqIno6mnDvXt593XZ2 CLt6+9hgxnu20/J6fE8EM54MsdoGVYpW5IV3IdMg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Bernat , Tom Zanussi , "Steven Rostedt (VMware)" , Sasha Levin Subject: [PATCH 5.1 079/115] tracing: Prevent hist_field_var_ref() from accessing NULL tracing_map_elts Date: Mon, 17 Jun 2019 23:09:39 +0200 Message-Id: <20190617210804.026342755@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@linuxfoundation.org> User-Agent: quilt/0.66 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 [ Upstream commit 55267c88c003a3648567beae7c90512d3e2ab15e ] hist_field_var_ref() is an implementation of hist_field_fn_t(), which can be called with a null tracing_map_elt elt param when assembling a key in event_hist_trigger(). In the case of hist_field_var_ref() this doesn't make sense, because a variable can only be resolved by looking it up using an already assembled key i.e. a variable can't be used to assemble a key since the key is required in order to access the variable. Upper layers should prevent the user from constructing a key using a variable in the first place, but in case one slips through, it shouldn't cause a NULL pointer dereference. Also if one does slip through, we want to know about it, so emit a one-time warning in that case. Link: http://lkml.kernel.org/r/64ec8dc15c14d305295b64cdfcc6b2b9dd14753f.1555597045.git.tom.zanussi@linux.intel.com Reported-by: Vincent Bernat Signed-off-by: Tom Zanussi Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Sasha Levin --- kernel/trace/trace_events_hist.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 0a200d42fa96..f50d57eac875 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -1815,6 +1815,9 @@ static u64 hist_field_var_ref(struct hist_field *hist_field, struct hist_elt_data *elt_data; u64 var_val = 0; + if (WARN_ON_ONCE(!elt)) + return var_val; + elt_data = elt->private_data; var_val = elt_data->var_ref_vals[hist_field->var_ref_idx]; -- 2.20.1