From patchwork Sat May 13 17:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 682219 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 27050C77B7D for ; Sat, 13 May 2023 17:57:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233528AbjEMR5u (ORCPT ); Sat, 13 May 2023 13:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjEMR5s (ORCPT ); Sat, 13 May 2023 13:57:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 431591727; Sat, 13 May 2023 10:57:47 -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 C821A61BC5; Sat, 13 May 2023 17:57:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F940C4339B; Sat, 13 May 2023 17:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684000666; bh=CMDkEplk7SwUbCVMsf6DA2exjxBJ4jdP0rE7gAI0KQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o6TQx+CtcfUS5lhy76YLTxbGgBg1XLqLr7mHpR+r1daC0tqTcCRDuIHR5Wec1n8XE pW4zncwIT0yFjUNyLqklxkSUU327YpKQ4VR/vKIfwdf7N+HMf4m3koUUJOc7nKjGWr 1EabB5SZvLDktSRZq19KHKybvyHypT8zvAbsWpvgPmpucTwiq5esjkiWAVD9AgN5PA vPzQ31XzDo9DeBGbKNFsPXUrhgTMAHL1otGxT5YEQ1cFSDN+cZ2PKLk18uVazwQ96t cnavQROP72STzUrgHRc6sDuMP8H5KGUmzZvBLiRtkbWTrnVdZs5/6jJ/3Sc2W7AOIw 1pF9YYx5Ub5ZQ== Received: from mchehab by mail.kernel.org with local (Exim 4.96) (envelope-from ) id 1pxtV1-001txn-1G; Sat, 13 May 2023 18:57:43 +0100 From: Mauro Carvalho Chehab Cc: Wei Chen , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 08/24] media: dvb-usb: digitv: fix null-ptr-deref in digitv_i2c_xfer() Date: Sat, 13 May 2023 18:57:25 +0100 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: <53558de2b5c4f4ee6bfcfbe34e27071c2d0073d5.1684000646.git.mchehab@kernel.org> References: <53558de2b5c4f4ee6bfcfbe34e27071c2d0073d5.1684000646.git.mchehab@kernel.org> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Wei Chen In digitv_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 digitv_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()") Link: https://lore.kernel.org/linux-media/20230313095008.1039689-1-harperchen1110@gmail.com Signed-off-by: Wei Chen Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/dvb-usb/digitv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/media/usb/dvb-usb/digitv.c b/drivers/media/usb/dvb-usb/digitv.c index 2756815a780b..32134be16914 100644 --- a/drivers/media/usb/dvb-usb/digitv.c +++ b/drivers/media/usb/dvb-usb/digitv.c @@ -63,6 +63,10 @@ static int digitv_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num warn("more than 2 i2c messages at a time is not handled yet. TODO."); for (i = 0; i < num; i++) { + if (msg[i].len < 1) { + i = -EOPNOTSUPP; + break; + } /* write/read request */ if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { if (digitv_ctrl_msg(d, USB_READ_COFDM, msg[i].buf[0], NULL, 0,