Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3712449pxb; Mon, 24 Jan 2022 16:05:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzV482DqMs8uDB03WZMz8rT0q6AqGRenbBgJ1jUxgB5nNzhKJDJPwktAlaYX2duyjochShY X-Received: by 2002:a62:7e0d:0:b0:4ca:cb85:9100 with SMTP id z13-20020a627e0d000000b004cacb859100mr170234pfc.0.1643069105716; Mon, 24 Jan 2022 16:05:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069105; cv=none; d=google.com; s=arc-20160816; b=mUPM/s1i/QMgTg7vKK/NTH2vqnx7VDgvJ4fy0LaypWrZU7jIAlgLxxgKVfB/O0Dcds JIRo9a1ivQWhOUSn/dF7EsMpphopEEPaZUQlXDjhA3Jq/mVdfTFpxXFEgah9WpzoRIOk d8+Ah4Sy1Vuvw1jW/z1ItjXAIy6j48Ynbq6ZWJTFx7Pd6QCo4zfEVZFuje1YOL8/xRDP QZ2N3spFVdXp7JjjdmfPp+9feC4O25uvkmn7Lfv3Q+Oes7qsnptF6QPChQNTYvSksOxF C2KT2Sa/JMkFKTmN1BCRfVqPxgg0wHZUvkG19teTgFxpZT0x2gFI10xNTw1m+2htRDyD fBcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HfV2Up4hhFfdWCdjNBvfu9aW/dcib9aOw08HrCMUPIU=; b=cpzEGcVO9IYipf+4WKFvnURVsgule7sjCtDejtHt9Wj+cY2E19e5q6sU7SjN/0my9b zMbfDlcMRKr0sn+Q0LFHmN2mRKlukmfJmtadF8eKECogOhAdEaHKaa6plCD2KDiy6VlL BdZUaBThCEEFuXh57kvxNVuagObJ+URJdzqQ8s4i4cbo5emr86FHlKR3bZ4cAJYtuNNR zphHGAR5XPtDEs0voCSv/SPiKgKF/A0YHbyp7kKyDidBbVD9YqcSUiek1/mNumm2xIue zWY90U2h+SModnyk9GjSva4P/0RCReE1l6IE2RT5Iy8gGod0otCw+J/lQ6L1UElry0qi 4XFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ro2tTWLd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u8si12903142plr.208.2022.01.24.16.04.52; Mon, 24 Jan 2022 16:05:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ro2tTWLd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1583109AbiAXX52 (ORCPT + 99 others); Mon, 24 Jan 2022 18:57:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1847015AbiAXXSP (ORCPT ); Mon, 24 Jan 2022 18:18:15 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DC5CC0604EE; Mon, 24 Jan 2022 13:25:54 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id CF857B81218; Mon, 24 Jan 2022 21:25:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02440C340E4; Mon, 24 Jan 2022 21:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059551; bh=aXgAlWjFhuTYaGo0IQrs5NxFaBkHUtQAgDjh1OBwC9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ro2tTWLdYBWodTRVoWxNoy0BcL28R00NgoBt6SNrGv3s8lR+3End87UEf257g56zl 2QRUih8jqJBV3d6sSblODJrFXj70+dX2hkIoAhnA1Kdh3O7G3ZhtQJrUtc07ILyqzF iEyvuqFvPshWaqUpk9cjOD84kuiJoBpUxGz3nnYo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, rkardell@mida.se, Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.16 0621/1039] media: m920x: dont use stack on USB reads Date: Mon, 24 Jan 2022 19:40:10 +0100 Message-Id: <20220124184146.213169199@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mauro Carvalho Chehab [ Upstream commit a2ab06d7c4d6bfd0b545a768247a70463e977e27 ] Using stack-allocated pointers for USB message data don't work. This driver is almost OK with that, except for the I2C read logic. Fix it by using a temporary read buffer, just like on all other calls to m920x_read(). Link: https://lore.kernel.org/all/ccc99e48-de4f-045e-0fe4-61e3118e3f74@mida.se/ Reported-by: rkardell@mida.se Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/dvb-usb/m920x.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/dvb-usb/m920x.c b/drivers/media/usb/dvb-usb/m920x.c index 4bb5b82599a79..691e05833db19 100644 --- a/drivers/media/usb/dvb-usb/m920x.c +++ b/drivers/media/usb/dvb-usb/m920x.c @@ -274,6 +274,13 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu /* Should check for ack here, if we knew how. */ } if (msg[i].flags & I2C_M_RD) { + char *read = kmalloc(1, GFP_KERNEL); + if (!read) { + ret = -ENOMEM; + kfree(read); + goto unlock; + } + for (j = 0; j < msg[i].len; j++) { /* Last byte of transaction? * Send STOP, otherwise send ACK. */ @@ -281,9 +288,12 @@ static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int nu if ((ret = m920x_read(d->udev, M9206_I2C, 0x0, 0x20 | stop, - &msg[i].buf[j], 1)) != 0) + read, 1)) != 0) goto unlock; + msg[i].buf[j] = read[0]; } + + kfree(read); } else { for (j = 0; j < msg[i].len; j++) { /* Last byte of transaction? Then send STOP. */ -- 2.34.1