From patchwork Sun Jan 9 13:26:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heyi Guo X-Patchwork-Id: 1577430 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4JWyRK3jV5z9s9c for ; Mon, 10 Jan 2022 00:26:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233468AbiAIN0v (ORCPT ); Sun, 9 Jan 2022 08:26:51 -0500 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:42931 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231201AbiAIN0v (ORCPT ); Sun, 9 Jan 2022 08:26:51 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R901e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=guoheyi@linux.alibaba.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---0V1Il5dP_1641734775; Received: from fdadf40dcbca.tbsite.net(mailfrom:guoheyi@linux.alibaba.com fp:SMTPD_---0V1Il5dP_1641734775) by smtp.aliyun-inc.com(127.0.0.1); Sun, 09 Jan 2022 21:26:48 +0800 From: Heyi Guo To: linux-kernel@vger.kernel.org Cc: Heyi Guo , Brendan Higgins , Benjamin Herrenschmidt , Joel Stanley , Andrew Jeffery , Philipp Zabel , linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org Subject: [PATCH] drivers/i2c-aspeed: avoid invalid memory reference after timeout Date: Sun, 9 Jan 2022 21:26:13 +0800 Message-Id: <20220109132613.122912-1-guoheyi@linux.alibaba.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The memory will be freed by the caller if transfer timeout occurs, then it would trigger kernel panic if the peer device responds with something after timeout and triggers the interrupt handler of aspeed i2c driver. Set the msgs pointer to NULL to avoid invalid memory reference after timeout to fix this potential kernel panic. Signed-off-by: Heyi Guo ------- Cc: Brendan Higgins Cc: Benjamin Herrenschmidt Cc: Joel Stanley Cc: Andrew Jeffery Cc: Philipp Zabel Cc: linux-i2c@vger.kernel.org Cc: openbmc@lists.ozlabs.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-aspeed@lists.ozlabs.org --- drivers/i2c/busses/i2c-aspeed.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c index 67e8b97c0c950..3ab0396168680 100644 --- a/drivers/i2c/busses/i2c-aspeed.c +++ b/drivers/i2c/busses/i2c-aspeed.c @@ -708,6 +708,11 @@ static int aspeed_i2c_master_xfer(struct i2c_adapter *adap, spin_lock_irqsave(&bus->lock, flags); if (bus->master_state == ASPEED_I2C_MASTER_PENDING) bus->master_state = ASPEED_I2C_MASTER_INACTIVE; + /* + * All the buffers may be freed after returning to caller, so + * set msgs to NULL to avoid memory reference after freeing. + */ + bus->msgs = NULL; spin_unlock_irqrestore(&bus->lock, flags); return -ETIMEDOUT;