From patchwork Sat May 13 17:57:23 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: 93565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5908215vqo; Sat, 13 May 2023 11:10:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5sMnsKGYvsi5uqLnu0z0wAXwBjqRwW0oDRNeorPTePrWw5Xwoxf79X2u3eVvwrsW9uhiuR X-Received: by 2002:a17:903:41ca:b0:1ac:3fe0:d6ad with SMTP id u10-20020a17090341ca00b001ac3fe0d6admr34342775ple.65.1684001429509; Sat, 13 May 2023 11:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684001429; cv=none; d=google.com; s=arc-20160816; b=wXTrNR9SaJo6OxWwgYhGC/xxlURtAitwcxxKtWdgJtEEHdohGVO00BBq/hMBARBnJx UAF0/CRpMbcW7OYNU0dhCaFAn030h4rz2vmIM3YP2Epg6auTJ0qcTyF0McFWhllXzsu1 /xcrABIiJ3QvaCOgTOUh+m4zKxzlcDMdvPTEvPx9xFVDjrPIXJNhth/5HswJ8NcuF51r IcdLW7lC+OfGOoTY6tfb/+S3rl3M1ndiguGEpaU6ApoLfd7g0cnzqL/Cx9Sm2r121tfa Q1SqLKnuvUUq727497nT5BLqqPUKHReJFtGiyqypHfMpzr3Ei/z6AxJnN6OgMz53tFwg F1Rg== 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=Pu3ksSJvx+FMiqBVgrs8XphLHgVKL6goEZ42iHXz0/I=; b=zuOC0pJuvCxsEBbIMUWdBnHKpnuR5T+8G3gWFvhlV4hCsdQphnM24DbUVt+1mxvGTe c5xAWQs91yTd4mbRonyn+4Ehh8mkvHgbaI3BxZkdl6jb2Z6RttNPYtGB+LbhaWWcqHnF ym5fXvm9gJs0SK7S0ivY/Z/SvhpxXEJhrkmkxA9Uk80xV1XVYWE4CBNQ3ZHfwOxT0jDD kjLoqnfqQZ0e6UDAJgZDV4dmTz9I2qj9FLY9+SaFJyhyViIFhr1n1PGyQ+siiwToEOv2 g+jv046yQ5F0C5uRj6KI2/UAgGhIl5qfT7EH1A4xjjrzwvXAusBAUG93a6F9nXebj8zP QsBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=HzzaiWOJ; 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 u11-20020a170902e5cb00b0019ccffb3fd3si12611532plf.509.2023.05.13.11.10.17; Sat, 13 May 2023 11:10:29 -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=HzzaiWOJ; 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 S234322AbjEMR55 (ORCPT + 99 others); Sat, 13 May 2023 13:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232846AbjEMR5t (ORCPT ); Sat, 13 May 2023 13:57:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E14F273F; 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 EA68F61BD5; Sat, 13 May 2023 17:57:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 261F7C433A1; 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=AobujLsjg+9WUQDOtPi3QpnUN+pCkaFzFNpt8y5ouZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HzzaiWOJLRDLeAs/iKYsZTgBhGzGCDXquQtMQiq70xUzv10n4JLC3NmJWtU1vnTCE XosG4ZrEj31xqAX+EJextwjLmcA1EofzWH2lMNcjhF/Ow2Tv3n6/Fb+JChDqAeDGeC Bdt2xjzy2q3Uh2928nuMqT9KIsZ1SCjQ+sSri3GCodPb2fX+i6nE+xp8TwoKG3Z+K5 bO9fN6KgyPZME/rzPbUy4Ydgln8l4HOC4iF5bIqhwwBk5eG06OwZVl7CoK6EK/Q/t0 OgbtruFu/Lmfe02PUSafZ1LZnJpIBqmd6n7u3Rthk4WWSxUQn0mPklAVKZ03rfVGDD 4WjM32uJOfUIg== Received: from mchehab by mail.kernel.org with local (Exim 4.96) (envelope-from ) id 1pxtV1-001txh-19; 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 06/24] media: dvb-usb-v2: ce6230: fix null-ptr-deref in ce6230_i2c_master_xfer() Date: Sat, 13 May 2023 18:57:23 +0100 Message-Id: <663aac154527f5d905fe84ae6e9c97fccd061655.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?1765803482864749201?= X-GMAIL-MSGID: =?utf-8?q?1765803482864749201?= From: Wei Chen In ce6230_i2c_master_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 ce6230_i2c_master_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/20230313092751.209496-1-harperchen1110@gmail.com Signed-off-by: Wei Chen Signed-off-by: Mauro Carvalho Chehab --- drivers/media/usb/dvb-usb-v2/ce6230.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/usb/dvb-usb-v2/ce6230.c b/drivers/media/usb/dvb-usb-v2/ce6230.c index 44540de1a206..d3b5cb4a24da 100644 --- a/drivers/media/usb/dvb-usb-v2/ce6230.c +++ b/drivers/media/usb/dvb-usb-v2/ce6230.c @@ -101,6 +101,10 @@ static int ce6230_i2c_master_xfer(struct i2c_adapter *adap, if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { if (msg[i].addr == ce6230_zl10353_config.demod_address) { + if (msg[i].len < 1) { + i = -EOPNOTSUPP; + break; + } req.cmd = DEMOD_READ; req.value = msg[i].addr >> 1; req.index = msg[i].buf[0]; @@ -117,6 +121,10 @@ static int ce6230_i2c_master_xfer(struct i2c_adapter *adap, } else { if (msg[i].addr == ce6230_zl10353_config.demod_address) { + if (msg[i].len < 1) { + i = -EOPNOTSUPP; + break; + } req.cmd = DEMOD_WRITE; req.value = msg[i].addr >> 1; req.index = msg[i].buf[0];