From patchwork Sat May 13 17:57:21 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: 93562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5907412vqo; Sat, 13 May 2023 11:08:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4QcW1wH7l2tUQ/6ypk+vo6koYGlncuIyxL6fu+UZgI33ouHY0yZABhOcihzOwsETG9o1f9 X-Received: by 2002:a05:6a00:a81:b0:62d:8376:3712 with SMTP id b1-20020a056a000a8100b0062d83763712mr40566358pfl.28.1684001315805; Sat, 13 May 2023 11:08:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684001315; cv=none; d=google.com; s=arc-20160816; b=UWdbQV0JDkQYVXQNzY5N3PCqnMvkkFG+RSMsejElIx95ap6hyc7vSd2YGweEEbGWZd HCoeX2aWIOtbrVR8EOnD2uTRNqMQ4qbnb/7Mg+eco3JAgHhNF+DOp+AD5Ar1fiZRSfzi NdM1z1810uOTaaY6n1XrB8K+Az30rZ1+bBQm1OztLQIEjNtiJVxLmyiaBgUtlbGHKumz LIy1egOCum2CGiQcvpZY6oIBx5su/sIHFfvw5F9ilX+XuS3bZ0PfL2iC/K0bB0GHx/S7 F6nn6G6Rx/8kFfC5pt2V+LL/oPGUiEc7B8XOtHfulKOY/t1oJOSvwuFTXiaw6jfypk8X 5oww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=+uQKBP2DkCulqp+KjYjltqeGU1msqJMPWDDAMngi/gM=; b=JuFzEZfZvOCI/Vvz+j63PoVWcyvTCtm+z/wabNaDwsf6MJZcvcOSYaIGdA4jW91J8N 7kVzvt51sYg/lZYmzAI3bJZCmV140tz7bx3+lzL1wPC/70lqdJ4P4BFHI7ppw7incnNu eFMR3I1bKPWMpG1cAmQzliP4W4SkCgMDcbAI2zQ/mrnowsRQwVttzxBifq+Os+JnF5QY 4Qoz95IZ41+kD2U+5by6CsqiDHbTo99tVJgLN59ufBEVRCHrmNm7no623dz2JnOZTJ7+ 5sfOmHZB6REhM5PSvXgmBVHfVF8NidbLolqfJ0JwI0cCPF6+VKaYm6IHQ+MhYZJsRNCq sc6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b="W1DGKgy/"; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w18-20020aa79552000000b00643af2c3432si12897584pfq.222.2023.05.13.11.08.23; Sat, 13 May 2023 11:08:35 -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=fail header.i=@kernel.org header.s=k20201202 header.b="W1DGKgy/"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237188AbjEMR6x (ORCPT + 99 others); Sat, 13 May 2023 13:58:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233483AbjEMR5u (ORCPT ); Sat, 13 May 2023 13:57:50 -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 ABE9F2D4F; Sat, 13 May 2023 10:57:49 -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 6FF7961C55; Sat, 13 May 2023 17:57:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DBEBC433AE; Sat, 13 May 2023 17:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684000666; bh=5VWVO7uCqtpTtyq7WX0BHcu+gdmJb2AfY2VtJgOfah4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W1DGKgy/izDBaJnf5WSQPcpX+BfLT9gdqK2xVJsT7nXqk2z3vx30fxRyGCZJ6Oy4G Nz8i8BalrjvE53PvsKkGDi0p/o9/mg8gm8wsfjoToZjCdHsas9FTQ8ocZBNjwjke7Q trkSR3FcIJjcJ9iJ0w3hM4ZrrfehG80KGgHkipeESwciLvGi9XTTpk2ETRjkBXRvWK GXDEpk/lFtM9q4yzzZdbzQhvtJhsNxo8LsPegJsS/4ysUvaz/jiDBFkZtmzN8bBhXU AGI5kiY4vjO+HA2SZ/zME8FqBLdJ3F0IPMV/g/wl4LwYmZonMEcB1f5Wh98Z7snddp Z1qt//DhzU8ZA== Received: from mchehab by mail.kernel.org with local (Exim 4.96) (envelope-from ) id 1pxtV1-001txb-13; 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 04/24] media: dvb-usb: az6027: fix three null-ptr-deref in az6027_i2c_xfer() Date: Sat, 13 May 2023 18:57:21 +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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) 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?1765803363705494390?= X-GMAIL-MSGID: =?utf-8?q?1765803363705494390?= From: Wei Chen In az6027_i2c_xfer, msg is controlled by user. When msg[i].buf is null, commit 0ed554fd769a ("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()") fix the null-ptr-deref bug when msg[i].addr is 0x99. However, null-ptr-deref also happens when msg[i].addr is 0xd0 and 0xc0. We add check on msg[i].len to prevent null-ptr-deref. Link: https://lore.kernel.org/linux-media/20230310165604.3093483-1-harperchen1110@gmail.com Signed-off-by: Wei Chen Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/dvb-usb/az6027.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/media/usb/dvb-usb/az6027.c b/drivers/media/usb/dvb-usb/az6027.c index 7d78ee09be5e..a31c6f82f4e9 100644 --- a/drivers/media/usb/dvb-usb/az6027.c +++ b/drivers/media/usb/dvb-usb/az6027.c @@ -988,6 +988,10 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n /* write/read request */ if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD)) { req = 0xB9; + if (msg[i].len < 1) { + i = -EOPNOTSUPP; + break; + } index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff)); value = msg[i].addr + (msg[i].len << 8); length = msg[i + 1].len + 6; @@ -1001,6 +1005,10 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n /* demod 16bit addr */ req = 0xBD; + if (msg[i].len < 1) { + i = -EOPNOTSUPP; + break; + } index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff)); value = msg[i].addr + (2 << 8); length = msg[i].len - 2; @@ -1026,6 +1034,10 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n } else { req = 0xBD; + if (msg[i].len < 1) { + i = -EOPNOTSUPP; + break; + } index = msg[i].buf[0] & 0x00FF; value = msg[i].addr + (1 << 8); length = msg[i].len - 1;