Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2666408pxj; Mon, 31 May 2021 07:47:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4xjkaMjd7yIN0p+nv7z4SFhnt9tYmZggJsK1NZFZL12gCa0inUnxVHdIah864i8cfS2cN X-Received: by 2002:a6b:3c06:: with SMTP id k6mr17255886iob.113.1622472470350; Mon, 31 May 2021 07:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622472470; cv=none; d=google.com; s=arc-20160816; b=W4+mxICqJbkPdKx+5jXokBGGVx4fFlEFZuqF0AwYNQuHG1GkSG1/X6XeTTW/MsVCXQ PQ5/aE9id/RzIOkrPJfCgFxZB/1icP1yAA7rtlDK7WFvAFvMS3Llr2sHKHRgG4GKz3zd kAAB49A38JLmiZV397J1yUjJ50y8HhTLcIxTJbXqiaaItZPKL6g1Zu7/56qSLdXNefJ4 IlbHkuEqtGIa8ITZLfMfIfS+4hhRL4O6Bajx6mtpd5Jg3ptpaWhhpxzcsMg6LhxDRjKK l5xkWDNxUNHcIaGEKHYycUGhfuGuRG5HIGPXMYZ1TR2xfdeNe/QBfnpps8S2UQBnkSve mTcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3vjSsxp7dlY+Xvv/3dmymEEK+OQsCV351KMpXpjRh48=; b=xYboWeoAMWek+RsykIAMq3kffLsd0VvmO38/RSEcspEvOOt7VljrqvA8ASqLX0Rpzl mcry1klmgWxZWtc6PMDvHUx/ZNPk4bZEPYmaIhc/SAZdTTVxdf3qkT83RvLnBkNw1hxu lICOqxOKudvuhBzS1mQmq1pi+68IOudtWDyKvm/XB+uwPJIaHWcW5Jg4G3Iwcq+dyILU E71mil686Kd5xQ4FAeM1mvwgOuPLt+tPryA02v07bFinC3jrR9Q1bkDsElfjdlGMs04G Mtq7s++640DrwLwEDIFxjcCjvJkcrVuHnPKpiIOR9227s95xcbR8fBWpQJgWTOlSA4wZ j4wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wTtYADXP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si16100642ilu.88.2021.05.31.07.47.36; Mon, 31 May 2021 07:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wTtYADXP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232973AbhEaOsf (ORCPT + 99 others); Mon, 31 May 2021 10:48:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:36738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbhEaOBK (ORCPT ); Mon, 31 May 2021 10:01:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 220216193F; Mon, 31 May 2021 13:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468201; bh=e20Lmk7MCMyMXAM/WcjTRVpXTDQARr5G0Blz+3SQKm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wTtYADXPVxbbVEmC7R2WO5ytpzLvbmnOJzzzyWOIWPu/NrmbL4y0g15auDOhAHy5u OAwUPCZJf29F2W3p+s02SPJPac06EfdiAfIoFEroyl4qkC6DBMCo1M17qe6SCuzyTB CzGnlwqPs7u0B5TwgklrsU8hc0cqVvCD7kHBGYoc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Krzysztof Kozlowski , Wolfram Sang Subject: [PATCH 5.10 120/252] i2c: s3c2410: fix possible NULL pointer deref on read message after write Date: Mon, 31 May 2021 15:13:05 +0200 Message-Id: <20210531130702.073322977@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Krzysztof Kozlowski commit 24990423267ec283b9d86f07f362b753eb9b0ed5 upstream. Interrupt handler processes multiple message write requests one after another, till the driver message queue is drained. However if driver encounters a read message without preceding START, it stops the I2C transfer as it is an invalid condition for the controller. At least the comment describes a requirement "the controller forces us to send a new START when we change direction". This stop results in clearing the message queue (i2c->msg = NULL). The code however immediately jumped back to label "retry_write" which dereferenced the "i2c->msg" making it a possible NULL pointer dereference. The Coverity analysis: 1. Condition !is_msgend(i2c), taking false branch. if (!is_msgend(i2c)) { 2. Condition !is_lastmsg(i2c), taking true branch. } else if (!is_lastmsg(i2c)) { 3. Condition i2c->msg->flags & 1, taking true branch. if (i2c->msg->flags & I2C_M_RD) { 4. write_zero_model: Passing i2c to s3c24xx_i2c_stop, which sets i2c->msg to NULL. s3c24xx_i2c_stop(i2c, -EINVAL); 5. Jumping to label retry_write. goto retry_write; 6. var_deref_model: Passing i2c to is_msgend, which dereferences null i2c->msg. if (!is_msgend(i2c)) {" All previous calls to s3c24xx_i2c_stop() in this interrupt service routine are followed by jumping to end of function (acknowledging the interrupt and returning). This seems a reasonable choice also here since message buffer was entirely emptied. Addresses-Coverity: Explicit null dereferenced Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Krzysztof Kozlowski Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/busses/i2c-s3c2410.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -483,7 +483,10 @@ static int i2c_s3c_irq_nextbyte(struct s * forces us to send a new START * when we change direction */ + dev_dbg(i2c->dev, + "missing START before write->read\n"); s3c24xx_i2c_stop(i2c, -EINVAL); + break; } goto retry_write;