Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2629694pxj; Mon, 31 May 2021 06:58:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdFSiSQ1qy25GkUx8MEp/raWJlLULWRAvIXF0BaCh0BceeqWV3tSlOwx1qb+77aMbkYCtR X-Received: by 2002:a6b:fb0f:: with SMTP id h15mr17111805iog.24.1622469526041; Mon, 31 May 2021 06:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622469526; cv=none; d=google.com; s=arc-20160816; b=UL37iE1U8JGq0MIVgSqMEe9JKd6ukOgncoK4psbGoSXcxI0kwXL6BBhic2U0v0oYNA EU6vHS4ZjpClHtZCnkAG8Ftnsp4K+ayhoyzjeLI5nbLwBfH7H/LtnS++DzB7FTCChy0H jTf7CIMMQVibr3wKT2q5IUUxgYvj17kGmM2cXCZnipdubgCO9GCqU+g+pdg27MC7WLSN JbuoHXM+jpi88kbaRJ4x9gi04naiSyzjCOOaqalr6wvlwrHoYquQ4mzXtweF47OldvHO GCldrX/M8VSNYevszYekqyQLCX5a02yuNBIjnDU8U5xSxaY0hZQCFiNz8LBnod9qUkEz klsA== 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=+bF+7417F6TsUdOYLTtB/Ui1fuwmtfwjBrUbTuuBhVw=; b=e2fYnsi21mq+tYIGUouBM/eZJVB7HDVPaZGfpmPk5n+jrdDGYgLckK9HEdzOmYvg8v B4bvFCjXBlJDdTo3dgHNBAJGCLrtLtDNo0yTH+6sWXh7iMDBg6hxroP9pN7Y5AwbBvw9 7W90vyiF4mY2ErnuKuPSfpKEGOay4liVGXwW4Hna7tjVdHqizBLiSIH5W7AQ76mzsytB W0foGalEN1gviVLBBggeS1O74O3aMedcvam9PQNa8Xo790mULBQunoh0v2+0BRS5Lk4m lFbmiXSTWqisV9N0yPxFZrom8ePxxENwpOYjcwcC4tydey120OqSqyC3UKxlUwqxUu2P ae7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vN35TSvX; 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 y3si16263074jad.12.2021.05.31.06.58.33; Mon, 31 May 2021 06:58:46 -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=vN35TSvX; 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 S233110AbhEaN73 (ORCPT + 99 others); Mon, 31 May 2021 09:59:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:40218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232222AbhEaNgY (ORCPT ); Mon, 31 May 2021 09:36:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EE3726138C; Mon, 31 May 2021 13:25:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467550; bh=b71SBhQkLUOf6GBO37cJl0H9l5cJbYbHDn/ybg4UNOo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vN35TSvXaQs1vNzb6qVVXWkzFE+b+e5qquh1YoA7FPecIERKp/MXfoJRnKM0SKnAO HxHMoNBxk1gx2i3VRA0aNr3uQsPDjCB+KYtAJiSWVYNubCjERPjxa1oFmcFsVL8C8o rN2iIx2IciyGXhoQ7S/BtRTSJURf8FoH+6vcKDWM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Krzysztof Kozlowski , Wolfram Sang Subject: [PATCH 4.19 072/116] i2c: s3c2410: fix possible NULL pointer deref on read message after write Date: Mon, 31 May 2021 15:14:08 +0200 Message-Id: <20210531130642.595831487@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130640.131924542@linuxfoundation.org> References: <20210531130640.131924542@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 @@ -493,7 +493,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;