Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2701579pxj; Mon, 31 May 2021 08:35:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybqSzxk8GVLTZzRjmIkPGcnujVnhQNqE1g8fIqG8jKZhSHXmQsXOPb+0C30I/iFFwc5yoD X-Received: by 2002:a05:6402:268f:: with SMTP id w15mr25735257edd.321.1622475341611; Mon, 31 May 2021 08:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475341; cv=none; d=google.com; s=arc-20160816; b=vcL7UuDrXKmTCgKRVHx01VJiMMORS0rYi2n655vUfvAmTZa8NQyycBbqaeuUHKVLsQ hidgAYE8O3Xv4OaTEM0yPI9seVPiLXn6lqEDOvouONNC1bePCKoyX2k/tscdxZInEYX9 d/UmDaKeWPglbNCO469cZXKEBSIO0J22OPsTBTejKDZLSmn0nsqPu0wZuyTkrbZNP3Y9 nHtTGQeFKPp7/QfRFnL9n8d8w/PIXzS1UBpDmn4aEOKjN5jyKJsRnKYq2oqdPYE6X+0v yL/zWrjdr+RA1reLJ8XNODQALkET0hqU+T8G8mv6w7EydTKepnFsItp9na4qq5o8T5J/ hrKA== 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=G3TVcBy29CGyDjFLcfVRjOFLA5BXn1cAzKfakS1uaXU=; b=yHwczIclGvf0S4WOzpT8oyuVIhu37hJVXJhRn0yGtHtoVOkRdNGkCXaQMGXzFdSnyr KIFqz1NF76/8acdf/OWymwOsRsqFNn3b9NHnsblggBB9XnGbpP3JiQiGHqPZS4fr4Gd0 CKjNA3ZUh98tsdgHV9tHtHnNgwsHde4lkhegQkWiEeEQ5EbMU4aQd53S3YuzeGnxMFp6 kl0GpJRKUzIoiG4m2M1Ve98yfnQZZFEn11BGy1pMzRXNceJTI/HnTHHPv+hBLjoghN2i N4ztx7CV72J6PYruRjTFh7d4prRFc+2P0jV5wNt3kWZ2MzedokiRGLgQ3yKnhtWkvxza r5NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n6d0byo4; 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 ga21si6052810ejb.24.2021.05.31.08.35.18; Mon, 31 May 2021 08:35:41 -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=n6d0byo4; 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 S232598AbhEaPgC (ORCPT + 99 others); Mon, 31 May 2021 11:36:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:47632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233634AbhEaOV1 (ORCPT ); Mon, 31 May 2021 10:21:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B6BAE619BE; Mon, 31 May 2021 13:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468676; bh=ezXMTCLsDDx1RyLbx2iUnmSFMxypZ69TyYkwwfbxN2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n6d0byo42ykk5GDFp5rqMoA3cOsHr+TN2Wic3Q+oQ0oy1dsSY2j8yPspXZuEPXf3m SfCuPJIY7MSTo9XggSIoSo287XHGrstU/shEz45wRIJYxnKweX7buMC/piWcyPAZCh pNTP1nGEVPOuDTEvqj06RkSFDL7c1bfHSwHlYvtI= 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.4 082/177] i2c: s3c2410: fix possible NULL pointer deref on read message after write Date: Mon, 31 May 2021 15:13:59 +0200 Message-Id: <20210531130650.738481011@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 @@ -484,7 +484,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;