From patchwork Sat Jul 8 15:24:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Shurong X-Patchwork-Id: 700980 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 9E436EB64DA for ; Sat, 8 Jul 2023 15:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjGHPZf (ORCPT ); Sat, 8 Jul 2023 11:25:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbjGHPZd (ORCPT ); Sat, 8 Jul 2023 11:25:33 -0400 Received: from out203-205-221-209.mail.qq.com (out203-205-221-209.mail.qq.com [203.205.221.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAB6FE43 for ; Sat, 8 Jul 2023 08:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1688829929; bh=vaylDKoxgIrBhavmAwyPUc47XqT+b4piq1AuB544sWs=; h=From:To:Cc:Subject:Date; b=Bhb6Ed5aKwDf8RgcYeo63ro7Vr6v0Pj+h26hwTYi6af/PmP/UUB84s6OIVpnqO7u4 X594UIfUXq1D0gI0oN74BiZYclMQAyUz1kfXuGkPo8KAIvTL3Ba1+J+VOPaymG7a6e PphhBh88j3mvEd8bh1Lb3K+sFl3plNfYLQ/sBTeM= Received: from KernelDevBox.byted.org ([180.184.103.200]) by newxmesmtplogicsvrszb9-0.qq.com (NewEsmtp) with SMTP id 60CB8219; Sat, 08 Jul 2023 23:24:12 +0800 X-QQ-mid: xmsmtpt1688829852tphn623yf Message-ID: X-QQ-XMAILINFO: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INFO: Nq+8W0+stu50PRdwbJxPCL0= From: Zhang Shurong To: mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Shurong Subject: [PATCH] media: af9005: Fix null-ptr-deref in af9005_i2c_xfer Date: Sat, 8 Jul 2023 23:24:11 +0800 X-OQ-MSGID: <20230708152411.3694672-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 af9005_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 af9005_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/af9005.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/usb/dvb-usb/af9005.c b/drivers/media/usb/dvb-usb/af9005.c index 0827bf3d4e8c..13604e6acdb8 100644 --- a/drivers/media/usb/dvb-usb/af9005.c +++ b/drivers/media/usb/dvb-usb/af9005.c @@ -422,6 +422,10 @@ static int af9005_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], if (ret == 0) ret = 2; } else { + if (msg[0].len < 2) { + ret = -EOPNOTSUPP; + goto unlock; + } /* write one or more registers */ reg = msg[0].buf[0]; addr = msg[0].addr; @@ -431,6 +435,7 @@ static int af9005_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], ret = 1; } +unlock: mutex_unlock(&d->i2c_mutex); return ret; }