From patchwork Mon Oct 24 11:28:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp420391wru; Mon, 24 Oct 2022 05:18:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4HoFRov1auqe8WglSnIPzKyntDyb8X7ikLcPT7sf+mk5BN5XdTztQD4D2lKUBybF8OytjX X-Received: by 2002:a17:907:7da5:b0:78e:2c3b:55a2 with SMTP id oz37-20020a1709077da500b0078e2c3b55a2mr26944841ejc.96.1666613887001; Mon, 24 Oct 2022 05:18:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666613886; cv=none; d=google.com; s=arc-20160816; b=BPrbJGiC8tdAbDMMDymLXD2HFgVl5wpGgRTDPQ8DI85VNFH763AfU60zIgjh1kNjL8 tlBfdxiHHa9gEWkS/qHf2URc/HYlS/HVXhQSZcx2/AG8HekTjhHvBAQPs267XaOJSnaf u50Vbo+BJWRzqyf5GvP/Vhh5Zv3YjGOyGILEdD04SMsGuRV7BM8ZHmd56X1LYb2buEo6 KMK8JYuKn5RpDI5VqellrQ1coEPh8cjNcFnlOEMADnzSdvdjtgPzr1dyB0MtHosEfgAA Hygpq6mthJyLr1swa6RWOUVrJeEE3OhFKXlyynRP2Q1uhFRtxN/cGd76iQBVBSwu6vvy 5q7g== 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=m0ZCf/o+MNFXZEJA67CKj7lO7OLEvb/SOMwCUTLtyuc=; b=MG8Hoe7b9qL31GXsD8krK043DMEvyMslh8ayfbfn/hTLG1FCWnChdzT+0aI09T3ed6 V3GuSJklbYaShCQN+GR9yF3oDTxP9fzVOccJjqnIFU4PkzTa6laQbbhyzeh0PdkEfyIj UYJdKBN+u8iyXFlkT8BHv+yukziGBPqklty6S+5PEdJWtYrKh3U7EyHdIXOkgcZJI6u8 9Qcokm+hPySc2T4G3qu+Blbg1reMSnGsdNxMJ1kMBTjwxRJSzmNiykrwDehoeSREHQ/q eGPXO/P7Z85fh9Nyan1hT+lgHo7UmYzpVhe8Y7LFphCvW9uX/JdE4EW5d6HkX3RwLePc z+cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l8tpyBib; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wu13-20020a170906eecd00b00780636887fesi31731916ejb.797.2022.10.24.05.17.43; Mon, 24 Oct 2022 05:18:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=l8tpyBib; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232711AbiJXMLg (ORCPT + 99 others); Mon, 24 Oct 2022 08:11:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiJXMKD (ORCPT ); Mon, 24 Oct 2022 08:10:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CAD12BB0A; Mon, 24 Oct 2022 04:53:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 29C516129E; Mon, 24 Oct 2022 11:46:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37632C433D6; Mon, 24 Oct 2022 11:46:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611972; bh=iafMQX0LLGAsrS6c7Ds92V5u8tPAuViCsplCLjBiFQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l8tpyBib/eObZuC/jQB6lR2lLm8XFJGAIYMhB1b2UJ6Zo/89GV3IdLQu/H47YsJw9 8I25WGivDCfCoaGnGxnovfKe5mC5nHJrwHQ+tx/Rm0WNdHLzY0R4CDgU8pu9S9VQF1 m9GJcLL3RjnbfLG+wiCl9Oe5wJ8eYMuuqtlpHulk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Popov , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Wolfram Sang , Harshit Mogalapalli Subject: [PATCH 4.14 021/210] i2c: dev: prevent ZERO_SIZE_PTR deref in i2cdev_ioctl_rdwr() Date: Mon, 24 Oct 2022 13:28:58 +0200 Message-Id: <20221024112957.648694176@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747571323620748402?= X-GMAIL-MSGID: =?utf-8?q?1747571323620748402?= From: Alexander Popov commit 23a27722b5292ef0b27403c87a109feea8296a5c upstream. i2cdev_ioctl_rdwr() allocates i2c_msg.buf using memdup_user(), which returns ZERO_SIZE_PTR if i2c_msg.len is zero. Currently i2cdev_ioctl_rdwr() always dereferences the buf pointer in case of I2C_M_RD | I2C_M_RECV_LEN transfer. That causes a kernel oops in case of zero len. Let's check the len against zero before dereferencing buf pointer. This issue was triggered by syzkaller. Signed-off-by: Alexander Popov Reviewed-by: Uwe Kleine-König [wsa: use '< 1' instead of '!' for easier readability] Signed-off-by: Wolfram Sang [Harshit: backport to 4.14.y, use rdwr_pa[i].len instead of msgs[i].len as the 4.14.y code uses rdwr_pa.] Signed-off-by: Harshit Mogalapalli Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -297,7 +297,7 @@ static noinline int i2cdev_ioctl_rdwr(st */ if (rdwr_pa[i].flags & I2C_M_RECV_LEN) { if (!(rdwr_pa[i].flags & I2C_M_RD) || - rdwr_pa[i].buf[0] < 1 || + rdwr_pa[i].len < 1 || rdwr_pa[i].buf[0] < 1 || rdwr_pa[i].len < rdwr_pa[i].buf[0] + I2C_SMBUS_BLOCK_MAX) { i++;