Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp339746imu; Thu, 3 Jan 2019 21:32:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN42G2uxZXOCFrbq2rU8F3HvcQ9wQBBHS+1seK/2By4xm6FaiYcaN2wBfRAmZQ1dhsxqISL0 X-Received: by 2002:a17:902:8641:: with SMTP id y1mr49511620plt.159.1546579963865; Thu, 03 Jan 2019 21:32:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546579963; cv=none; d=google.com; s=arc-20160816; b=cqadVMsB6v9Jgkizm4gB8fH71zvMgaFgkksL2Y8yh723eSqylbkSxd1nsLC+bqbLsx xhYMxn2h6jdx8KyakAvQO3NafXPxx2M6XpTLZcsLls/fydSg3bmAKP5fbaqW6+FipkGc bqOXwSQwp1P/BJRTamexXpQpx1dKhh/ylZDTTj/7J9JW3QjlKGmFKrbF7WA0EL+1rcj7 ThgmTeyGbEoQEpjX06tz4tZXsbilsnCl0S/N6uT4loMkYpS7287F985JK5U3Y5GYEO91 aSfcMjyh8k4DJi619jMr269OTNO8MxxAilcL8cjtX1DvCbiugsqX//X6EOhfZhKgk1eX qRNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=UhcxMxiwBOiKaw8gDgE2cvjkyx4EHhVXjk74arqb5fk=; b=QkzDR8h0aBndfzVBc/TQhmrTLNRnePLIf9LNhExTzdEP2/9ROeIiQcni4LmztnMHm5 ifPb1Qmgduqq8Bdhn4d/YZ3vJ6gJdh0RUDwBuQbCMMAN61ngbKRUx+TYVh8DkU7VIMvQ GqbhHCuSXlrFb6KgX/hyFKHPA5COYUtQccDNrN3GS8nrFPX813UlNvWJVe/6mmMBXbMH FB9XUyU0Ocjk6i+W9O+7dTJJaxvN5rI89DTrLGFnNdwzWAjcrCc0/0R270cvFzCxc5r8 LdTMQycIuhJJXSgrbmooec4jv4EbOwpqu4DiDCeNmq510obmyFs46P5yybxpD87Q6uL1 z4XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JTblI9xX; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y17si20942709pgh.353.2019.01.03.21.32.28; Thu, 03 Jan 2019 21:32:43 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=JTblI9xX; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727392AbfADAmg (ORCPT + 99 others); Thu, 3 Jan 2019 19:42:36 -0500 Received: from mail-io1-f73.google.com ([209.85.166.73]:39498 "EHLO mail-io1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726021AbfADAmg (ORCPT ); Thu, 3 Jan 2019 19:42:36 -0500 Received: by mail-io1-f73.google.com with SMTP id q23so40155150ior.6 for ; Thu, 03 Jan 2019 16:42:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=UhcxMxiwBOiKaw8gDgE2cvjkyx4EHhVXjk74arqb5fk=; b=JTblI9xXkog2U8oOQ4flQbXi8Vv4XJ/X0+GOODMJfpn+SpyOSjsS/sxp24kRKgqU+q zS3xfS9+2wfq6c9MEEDV6psZBLRWGjy8rR+QUJ3HUd4IzIJA/59m37EuRD55dRdvGaqn B11fpwIJcU7wr7Tpw0qes3Gj1UJK7Nwjff3fri5eMhkbhkkUU2qLAI0O24BdUqm/JVmJ NGFmvoTWW8hhBK9HQC0F/LHUrpD65J0lCmcW8dqH/SoWIXpd9xKHYILcv02SWNadoOqw tfBSfh0Dweh4MO5tp8F68MI7CMpcm1Amv83DruKQ7bbBTduR1+Pds4lQhjKGpB2hwrMV nzqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=UhcxMxiwBOiKaw8gDgE2cvjkyx4EHhVXjk74arqb5fk=; b=lHSEOK3I2yxP7rhFz1bj0Q6MfU0c/bmnbjOEDNozcEqOFwtORO/0g09aQ7APnzcDGc fkcGr+3Rw+xG5R+Zb7Bx+DiHI9kKeovxLKUZAGMF8TufGT0V0SxrjzERsfOZ0iGB7dO3 5etRD43gM9sjsjgMgxirzOdd+fbFHNLic+zrvxCrnX1wbNvQVlTt/2k6ZW+7lh2y//e3 j1VsBPS3cQLoZABzMYnevHbCOF7lhMh9ibwtZxsQaiv60jADoqk9m86XLpvF/lVJQLXT lyIBjgWdlA1ma5qgntKHjT5UjZD6+QUsdFryu9rvzG5kZLt1ESFbimJymG2hrufnjMIp E7bg== X-Gm-Message-State: AA+aEWZrdJF8UyeqhKSO0P8QpA8Ls7eTe0uxy4JevirPVot/7yl54Rjp pdj3BbStc+wRd2ubgfzd7e7v0NcQkQgVdxk= X-Received: by 2002:a24:760e:: with SMTP id z14mr36502756itb.5.1546562554900; Thu, 03 Jan 2019 16:42:34 -0800 (PST) Date: Thu, 3 Jan 2019 16:42:03 -0800 Message-Id: <20190104004203.116155-1-jsperbeck@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1.415.g653613c723-goog Subject: [PATCH] i2c: core-smbus: don't trace smbus_reply data on errors From: John Sperbeck To: Wolfram Sang Cc: Steven Rostedt , Ingo Molnar , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, John Sperbeck Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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), 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; -- 2.20.1.415.g653613c723-goog