From patchwork Sat May 13 17:57:22 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: 93557 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5903292vqo; Sat, 13 May 2023 11:00:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nngcEQPgDS6cy0Bz7/uUdfIkVSBGT982vFZ07aRDJFN5EAlCrvlTnuA8tUom0dooCDJB+ X-Received: by 2002:a17:903:41c6:b0:1ad:f7d9:1ae2 with SMTP id u6-20020a17090341c600b001adf7d91ae2mr3977337ple.55.1684000858690; Sat, 13 May 2023 11:00:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684000858; cv=none; d=google.com; s=arc-20160816; b=QtnZIwMZ5vHQeohOn2nzRDOcXtjvTurGKmOzrUgFUOipe7T2RDLLy5QesO3ArXw3+Y +bkj5XwMAUvlyF/FEW7S9+1/LIU2guQ7X1d8Hk1OwV3nkYpOnx3OgI1+tNaRIPAuWzbM m66mcxsdRV0QUlrZDFJLda00M++H0PcJI5Ncx+6RJ3L3hifdH95tq492sWPbPJ/zuYMe QDn7xZzsCGDL2kp6rP1sOFC1eGWWRvg+bbLJP657MnzNcxM3W+eJjN4H5HT2kawnffq8 5aL53mKj34CDvt2AjbMrGObmi1/LuOHYGI1mPJ0qVefk0Xa3PIVXXdP/ytgFaks5KbfN XjmA== 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=y641mR4B1DSufL81fRdIlPinVqmd2QIcpxR5Mm+kzKg=; b=WfMfehFn5lHsSbfdwAeMhThFoOnwtHjQZ/rMl2iVHBhi4WYxttCuhItEc9MquLdw5I pmWgbpwci6VyUqv/CH5BTaZoqJ53o6JG9QQEOVJu8F/XBtg3ZjeZVIGYJ4kmJ/MbLGD+ lBJJfODBgj2wG3uNzUGT4Y4AXOIXiM6JncZzQTT0Ab8G9s6yNcuyzxvKhLw7nugdvC4C gwmixpA7tdJCVMG7f+/4udCcwMYYgjxqHcqP32aBJyXSFThj6U/tNGZBF0mlrV9z9+98 EBJsl3lfqt3e3vNY5fshwNdjeYCZhxFyNwq0vVHRV2coOwt4tgMJWomt7BP1A07ZHV1y T0eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=kboJz1TE; 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 t7-20020a1709028c8700b0019a71e14c19si2705935plo.320.2023.05.13.11.00.43; Sat, 13 May 2023 11:00:58 -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=kboJz1TE; 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 S230186AbjEMR6O (ORCPT + 99 others); Sat, 13 May 2023 13:58:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233374AbjEMR5u (ORCPT ); Sat, 13 May 2023 13:57:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D9272D4A; 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 731F661C77; Sat, 13 May 2023 17:57:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E801C433AF; 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=CTfRhQWQn7pm6EUBrySW+mwubKxnJtOio7Fb/AJ6iKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kboJz1TEgai/9EZySh70l5D9V/kejQeCLlgt4nrnfXRjvxPfg3usiRyd9LSrs2GHU Uj2cLKKPvrusPuYTieqDNXLaroDjqEnYR1RX2n9KdLrx82Cuwg4q5i5bo4ykkBIdAS r6PZKdQDNXqpxUrYhyK7jWVSBLrQBQYXH1oWxBO3ufNcj9Ma1WBMmnfdtKq6bFAaBr e59p36M8Zmfy84DHhDlVU5FFchglvaDA4HtZPtrQJwmHTg+ryaBx21zRdm00A1YNSG iyCMhROx5Asd/2VpMBJQ/qULgHJw3o60FEcO6TRE/rJxr6P/srCGJN4GxRUutCc6KN k8P0BIb4W00hA== Received: from mchehab by mail.kernel.org with local (Exim 4.96) (envelope-from ) id 1pxtV1-001txe-16; Sat, 13 May 2023 18:57:43 +0100 From: Mauro Carvalho Chehab Cc: Wei Chen , Antti Palosaari , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 05/24] media: dvb-usb-v2: ec168: fix null-ptr-deref in ec168_i2c_xfer() Date: Sat, 13 May 2023 18:57:22 +0100 Message-Id: <7ced9f219d36cb0d3319b556dc0b0f4f81247fa6.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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1765802884525225575?= X-GMAIL-MSGID: =?utf-8?q?1765802884525225575?= From: Wei Chen In ec168_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. If accessing msg[i].buf[0] without sanity check, null pointer 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/20230313085853.3252349-1-harperchen1110@gmail.com Signed-off-by: Wei Chen Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/dvb-usb-v2/ec168.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/media/usb/dvb-usb-v2/ec168.c b/drivers/media/usb/dvb-usb-v2/ec168.c index 7ed0ab9e429b..0e4773fc025c 100644 --- a/drivers/media/usb/dvb-usb-v2/ec168.c +++ b/drivers/media/usb/dvb-usb-v2/ec168.c @@ -115,6 +115,10 @@ static int ec168_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], while (i < num) { if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { if (msg[i].addr == ec168_ec100_config.demod_address) { + if (msg[i].len < 1) { + i = -EOPNOTSUPP; + break; + } req.cmd = READ_DEMOD; req.value = 0; req.index = 0xff00 + msg[i].buf[0]; /* reg */ @@ -131,6 +135,10 @@ static int ec168_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], } } else { if (msg[i].addr == ec168_ec100_config.demod_address) { + if (msg[i].len < 1) { + i = -EOPNOTSUPP; + break; + } req.cmd = WRITE_DEMOD; req.value = msg[i].buf[1]; /* val */ req.index = 0xff00 + msg[i].buf[0]; /* reg */ @@ -139,6 +147,10 @@ static int ec168_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], ret = ec168_ctrl_msg(d, &req); i += 1; } else { + if (msg[i].len < 1) { + i = -EOPNOTSUPP; + break; + } req.cmd = WRITE_I2C; req.value = msg[i].buf[0]; /* val */ req.index = 0x0100 + msg[i].addr; /* I2C addr */