From patchwork Sat Jul 8 16:28:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Shurong X-Patchwork-Id: 700979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A4BCEB64DA for ; Sat, 8 Jul 2023 16:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbjGHQ22 (ORCPT ); Sat, 8 Jul 2023 12:28:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjGHQ21 (ORCPT ); Sat, 8 Jul 2023 12:28:27 -0400 Received: from out203-205-221-202.mail.qq.com (out203-205-221-202.mail.qq.com [203.205.221.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D373CE50; Sat, 8 Jul 2023 09:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1688833701; bh=x3AUoKcSqNhyarawC1JJjkAvdYYgLViPABTAWorkKAs=; h=From:To:Cc:Subject:Date; b=olWwJn9WTQk117RaZtS9TqYqreb++yJWa4QLLOyQrfxB5eiG7+Ni17VfRmRmPwyPA cMIR82t5q1gwbV4kmgp/jPLQA5FZs9nNRk12x/25yO1FTgGj4G/wDHeAvz2RA4e22J xC7PEE8Xno9UHJJP792XY+z++f1D0d9X40wVBF2c= Received: from KernelDevBox.byted.org ([180.184.51.70]) by newxmesmtplogicsvrsza12-0.qq.com (NewEsmtp) with SMTP id 7131229E; Sun, 09 Jul 2023 00:28:19 +0800 X-QQ-mid: xmsmtpt1688833699ti4upo64d Message-ID: X-QQ-XMAILINFO: Md8NwmqZY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4Ny6FSmKK/uo/jdU= From: Zhang Shurong To: mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Shurong Subject: [PATCH] media: az6007: Fix null-ptr-deref in az6007_i2c_xfer() Date: Sun, 9 Jul 2023 00:28:17 +0800 X-OQ-MSGID: <20230708162817.3797791-1-zhang_shurong@foxmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In az6007_i2c_xfer, msg is controlled by user. When msg[i].buf is null and msg[i].len is zero, former checks on msg[i].buf would be passed. Malicious data finally reach az6007_i2c_xfer. If accessing msg[i].buf[0] without sanity check, null ptr deref would happen. We add check on msg[i].len to prevent crash. Similar commit: commit 0ed554fd769a ("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()") Signed-off-by: Zhang Shurong --- drivers/media/usb/dvb-usb-v2/az6007.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/usb/dvb-usb-v2/az6007.c b/drivers/media/usb/dvb-usb-v2/az6007.c index 2dcbb49d66da..2410054ddb2c 100644 --- a/drivers/media/usb/dvb-usb-v2/az6007.c +++ b/drivers/media/usb/dvb-usb-v2/az6007.c @@ -788,6 +788,10 @@ static int az6007_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], if (az6007_xfer_debug) printk(KERN_DEBUG "az6007: I2C W addr=0x%x len=%d\n", addr, msgs[i].len); + if (msgs[i].len < 1) { + ret = -EIO; + goto err; + } req = AZ6007_I2C_WR; index = msgs[i].buf[0]; value = addr | (1 << 8); @@ -802,6 +806,10 @@ static int az6007_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], if (az6007_xfer_debug) printk(KERN_DEBUG "az6007: I2C R addr=0x%x len=%d\n", addr, msgs[i].len); + if (msgs[i].len < 1) { + ret = -EIO; + goto err; + } req = AZ6007_I2C_RD; index = msgs[i].buf[0]; value = addr;