From patchwork Sat May 13 17:57:24 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: 93555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5902802vqo; Sat, 13 May 2023 11:00:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4eSUjapijKf0HREnXmUsO2Z0m3YdgSyPYlAm5Sinxt0rsXwNcwMp6KfwmPPgHlGYqRbaLg X-Received: by 2002:a17:90b:1009:b0:250:61cf:a2c9 with SMTP id gm9-20020a17090b100900b0025061cfa2c9mr25187291pjb.33.1684000807871; Sat, 13 May 2023 11:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684000807; cv=none; d=google.com; s=arc-20160816; b=I/eyYO1Rw2o0d4KOv1IQnr3cHdF1cluNoRF9xqYWUHwTiJCIbal5vyjFVzf/DQRlKL FRVqXbb4aZtWFbb+lx1L1tRd+yVO+WeBCUbyJ/4gqMFBShpDqDD4pBajV4XamatSyVF9 hR7NMb2qtnKDecadEz3lSrY8ATi+8mrn9xwCwHJIH/QoEcGmpEtWCsbnfjtRnD72sVLX F9nnBfFyKY7YHNsYOhuCBoOC6AiKImmRo+I9kcuS/+hAVdQ/i7x23AHOfQxsZt8UG/+P 7941sWs+khaj2ve4j4mTnEENMXy0r05SiTD9ZtnuyExR0zWniSRRl7LDzORTefvuJ8fY /O3w== 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=BoCvMpYdkf2CKy7nTOni6JbYHLgdQ6/aRKIfe9zXrSg=; b=q+h5x0iIB0W6t+pOKq7fe8to7AHXebWrLa9BW3BL9/2nD5BRyjpPHX8doSfQUtdEaG nhMb+VuvodbsH7ZMKbVytS2FvpWdfWv+M/E1r+Ku3ctx1hAe1Q4smtGq2reqkoLs4pza piCr6u0Kph6lh2MnksOztlViiuX/nqobRNwIGKY9dCCmo2LKceJ6Cx8NBOukQMu5iFMd is9Tt+lnJmUHsx0gdhyYid8yQK7UMMw772Qe3pr/FONCSNSh0CvKFUgC2/IckPqpekxf +m6tC8BEfhaXGWnNjFIBQMOu8WxAU6CAx29sxarKTowWC2hPhrHKsEULFxq8dKSVl9K8 +0yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=WfAh0T3w; 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 l2-20020a17090aec0200b0024e0758c190si29781245pjy.27.2023.05.13.10.59.52; Sat, 13 May 2023 11:00:07 -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=WfAh0T3w; 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 S233655AbjEMR6r (ORCPT + 99 others); Sat, 13 May 2023 13:58:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbjEMR5v (ORCPT ); Sat, 13 May 2023 13:57:51 -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 0AD8C2D51; 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 76CD161C7B; Sat, 13 May 2023 17:57:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41287C433AA; 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=h+o86lYY6wYE6F/X5RXOjriZlUayPYV89Y5aQCR8DXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WfAh0T3wyDbyj4r2sqFXHZUdf/gOi/wRXDcJ6WLUns/SgLlhOTiERjWa9XUYk63SF ++Vlzb2X1bOpNat2Relb+G9w4qp3KxLpCGMSHMLn2yDpwvi4fw7YKJsbqlEz/R0MsL FB2v75bydLO7R5VsNWgGhAjCgc1HcFwS2IzpCju078uIMR9dOFGTKZGOk19SUwRNZQ 3OlbX11SEydMzCfwCWRDJdWtNu4ErzS/rD087xuKtdR4+GB0V9jRGFaEAlHCmUy+xC 7VpCL2GGgYNFmzqYyQXTtAFfjy+U4eNPENSramrxX5u8J5CoH2zjiu7GElpUIpCbDd SpOjaYEYuyzbA== Received: from mchehab by mail.kernel.org with local (Exim 4.96) (envelope-from ) id 1pxtV1-001txk-1C; Sat, 13 May 2023 18:57:43 +0100 From: Mauro Carvalho Chehab Cc: Zhang Shurong , Antti Palosaari , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 07/24] media: dvb-usb-v2: rtl28xxu: fix null-ptr-deref in rtl28xxu_i2c_xfer Date: Sat, 13 May 2023 18:57:24 +0100 Message-Id: <77c81598e4c5abbc444844108f71cabc562a50d7.1684000646.git.mchehab@kernel.org> 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?1765802830647223409?= X-GMAIL-MSGID: =?utf-8?q?1765802830647223409?= From: Zhang Shurong In rtl28xxu_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 rtl28xxu_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/tencent_3623572106754AC2F266B316798B0F6CCA05@qq.com Signed-off-by: Zhang Shurong Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c index 795a012d4020..f7884bb56fcc 100644 --- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c +++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c @@ -176,6 +176,10 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], ret = -EOPNOTSUPP; goto err_mutex_unlock; } else if (msg[0].addr == 0x10) { + if (msg[0].len < 1 || msg[1].len < 1) { + ret = -EOPNOTSUPP; + goto err_mutex_unlock; + } /* method 1 - integrated demod */ if (msg[0].buf[0] == 0x00) { /* return demod page from driver cache */ @@ -189,6 +193,10 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], ret = rtl28xxu_ctrl_msg(d, &req); } } else if (msg[0].len < 2) { + if (msg[0].len < 1) { + ret = -EOPNOTSUPP; + goto err_mutex_unlock; + } /* method 2 - old I2C */ req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); req.index = CMD_I2C_RD; @@ -217,8 +225,16 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], ret = -EOPNOTSUPP; goto err_mutex_unlock; } else if (msg[0].addr == 0x10) { + if (msg[0].len < 1) { + ret = -EOPNOTSUPP; + goto err_mutex_unlock; + } /* method 1 - integrated demod */ if (msg[0].buf[0] == 0x00) { + if (msg[0].len < 2) { + ret = -EOPNOTSUPP; + goto err_mutex_unlock; + } /* save demod page for later demod access */ dev->page = msg[0].buf[1]; ret = 0; @@ -231,6 +247,10 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], ret = rtl28xxu_ctrl_msg(d, &req); } } else if ((msg[0].len < 23) && (!dev->new_i2c_write)) { + if (msg[0].len < 1) { + ret = -EOPNOTSUPP; + goto err_mutex_unlock; + } /* method 2 - old I2C */ req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); req.index = CMD_I2C_WR;