Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp360728imu; Thu, 3 Jan 2019 22:09:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN4QJ63yMFL1/Vzu3+PpuxiAxZ305sW0fqEtzJvhuyhwqKWnKWGWyV0rvxxWFzXJ558fzuT4 X-Received: by 2002:a17:902:be0e:: with SMTP id r14mr46751420pls.124.1546582187427; Thu, 03 Jan 2019 22:09:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546582187; cv=none; d=google.com; s=arc-20160816; b=NIQjJO7Xtm4CVu/x9CvKp9o6nb6AAxJ1wBo0W+WshOi4MOiTi0Zkk5w0QINSh90JdI j/MMqvLPcQGDyVfiBXFTSHkSnNvLFZt2qk/AF/zmpswRt+p1vcL2Xv1gHdEUJ//REf3C ZLdC5Vq8UjbSGYB5sMPgINFt9/eF85ENXo72QG/YDlLbhmo00UPlaVLAkxUB4XB535Vg 6izBkQ5iUx2P/CKO5xGDNXskyBhFDj+0ZbIXxG13teK5Wtj10lLZFCV2iCzt1NCtmn3y MUzmrXbDW444hmwAI0uZQUlXIzRNt4kpv2CDyGgX4kXvOwC6Qpy1OCTeoCx9TxiwvTBH tcdA== 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:subject:cc:to:from:date; bh=TgyvZk+73dLhDXY4ZedGPhM01vMaTz7SPihIq3HRFF8=; b=IztQpLxcpSbX7IWaMQdt6mhrmhg5SnqGyVd5qE1ObvCAj277AsO4dbtrJt6G4goIrI 1L6Ydmb7b1zX1D2FWM6zzhLbseg7XaVksc4gyRzNzhj4tXsCkZh9/gaMapX7MqO3Fj/y aBYji8FGmy2Mub/pnjbSJTK5KFtjOilMnX5WSASk/NdKrTofeZuXPi5f3U1sOx/6Q1XS 3iYT+vE6QXXEX1AlTOB0G+OlU7gljHvEbGKxCbs9VuyXJ/AmrwPT3sEEvHOXB6zs1PJ0 uVaapNKth45pJaGSxieCNzSjgsnmmmy46OBJz2mp5KxgXGA5+QEkD0lt9AJQmCRuyCBz c3Dw== 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 q66si54029898pfb.231.2019.01.03.22.09.32; Thu, 03 Jan 2019 22:09:47 -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 S1726298AbfADCtb (ORCPT + 99 others); Thu, 3 Jan 2019 21:49:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:49794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbfADCta (ORCPT ); Thu, 3 Jan 2019 21:49:30 -0500 Received: from vmware.local.home (cpe-66-24-56-78.stny.res.rr.com [66.24.56.78]) (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 C36BB20815; Fri, 4 Jan 2019 02:49:29 +0000 (UTC) Date: Thu, 3 Jan 2019 21:49:27 -0500 From: Steven Rostedt To: John Sperbeck Cc: Wolfram Sang , Ingo Molnar , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] i2c: core-smbus: don't trace smbus_reply data on errors Message-ID: <20190103214927.2bf947ca@vmware.local.home> In-Reply-To: <20190104004203.116155-1-jsperbeck@google.com> References: <20190104004203.116155-1-jsperbeck@google.com> X-Mailer: Claws Mail 3.15.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 3 Jan 2019 16:42:03 -0800 John Sperbeck wrote: > If an smbus transfer fails, there's no guarantee that the output > buffer was written. So, avoid copying from the output buffer when > tracing after an error. This was 'mostly harmless', but would trip > up kasan checking if left-over cruft in byte 0 is a large length, > causing us to read from unwritten memory. > > Signed-off-by: John Sperbeck > --- > drivers/i2c/i2c-core-smbus.c | 2 +- > include/trace/events/smbus.h | 10 +++++----- > 2 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c > index 9cd66cabb84f..132119112596 100644 > --- a/drivers/i2c/i2c-core-smbus.c > +++ b/drivers/i2c/i2c-core-smbus.c > @@ -585,7 +585,7 @@ s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, > trace: > /* If enabled, the reply tracepoint is conditional on read_write. */ > trace_smbus_reply(adapter, addr, flags, read_write, > - command, protocol, data); > + command, protocol, data, res); > trace_smbus_result(adapter, addr, flags, read_write, > command, protocol, res); > > diff --git a/include/trace/events/smbus.h b/include/trace/events/smbus.h > index d2fb6e1d3e10..b6376a7c7e74 100644 > --- a/include/trace/events/smbus.h > +++ b/include/trace/events/smbus.h > @@ -138,8 +138,8 @@ TRACE_EVENT_CONDITION(smbus_reply, > TP_PROTO(const struct i2c_adapter *adap, > u16 addr, unsigned short flags, > char read_write, u8 command, int protocol, > - const union i2c_smbus_data *data), > - TP_ARGS(adap, addr, flags, read_write, command, protocol, data), > + const union i2c_smbus_data *data, int res), > + TP_ARGS(adap, addr, flags, read_write, command, protocol, data, res), > TP_CONDITION(read_write == I2C_SMBUS_READ), Hmm, instead of tracing nothing, as this is already a "conditional trace event", why not add to that condition: TP_CONDITION(res >= 0 && read_write == I2C_SMBUS_READ), Unless you want to still trace some data on failure. -- Steve > TP_STRUCT__entry( > __field(int, adapter_nr ) > @@ -159,16 +159,16 @@ TRACE_EVENT_CONDITION(smbus_reply, > switch (protocol) { > case I2C_SMBUS_BYTE: > case I2C_SMBUS_BYTE_DATA: > - __entry->len = 1; > + __entry->len = res < 0 ? 0 : 1; > goto copy; > case I2C_SMBUS_WORD_DATA: > case I2C_SMBUS_PROC_CALL: > - __entry->len = 2; > + __entry->len = res < 0 ? 0 : 2; > goto copy; > case I2C_SMBUS_BLOCK_DATA: > case I2C_SMBUS_BLOCK_PROC_CALL: > case I2C_SMBUS_I2C_BLOCK_DATA: > - __entry->len = data->block[0] + 1; > + __entry->len = res < 0 ? 0 : data->block[0] + 1; > copy: > memcpy(__entry->buf, data->block, __entry->len); > break;