Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3345197pxv; Sun, 4 Jul 2021 16:08:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4G81hTPg8237SpAgQBf/CTEr3CsYrFNkXdYnaGpWf5n/6pPBQSN4ao3UTGwkCQqNFwjVe X-Received: by 2002:a02:6f1e:: with SMTP id x30mr9643718jab.122.1625440117234; Sun, 04 Jul 2021 16:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440117; cv=none; d=google.com; s=arc-20160816; b=THzQGds28B0IWQ+rPWzz8UijQ0J2irwd1ZUb0vmPO81CKuUOpZcwnbrJjzQzagQCzT ix8FuZtsVgxs1HgkxDg9dLqiJ+Jxf5mODAwvmaIu1uggo2KSVr23Y6fNLDMtfrDpDx/e yFM2JJwIrZ8gmafQPVmd2myFudBYpk/c8XspFmy4uzBnaC/Z+jY4yApj5G5zONyrlAGU OtGSEE+KO4Q4LmFq22zAKKpjrlUDifqte/jMYsHnjI9YY/AWAZBJsK0FxwycjK4YyyCL tZ55ZiNvAvLSOMYBfxauMD9CzNPYs2gfzVvZibSv2PWD2bRxuzT7N3XpEhIxGjr22ueu dNQg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tFcj5YwJYF6r/VcCDW26XLev6e8wY5vIVzNBah9yMPc=; b=s+4nVkm8Zm+XH9qWG+TFvOUK0aPJwpAGPBY0I8V7bAZLAgxitW7uIHR7+SJWTU6bTg dhYGkJ/ybjbrw6G222+G81/oatO6GmnBPC8XE4GhvAbqHvwMiEbP1g1Oilbchu/jV9W4 apXtLFpyClxZcB/ri3bq/gIgASP56udLBIn2sxWg62cnLH5Nbaz6UkouIR/5JWsezFYD NAP5vib9YmY9K9AAVBI61mxQJtya0ZvjpiIxjx3t7vBHz4xei50V6eyPbcvkq7hoJVP8 iK/QsVn1tfH2dFmfWeM1ekGoRJaf5duM4nlY3/TZeii7/GFebzXXIqLulj+DI/xDS7uX f4Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EtccjjZl; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si11261595ils.58.2021.07.04.16.08.25; Sun, 04 Jul 2021 16:08:37 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=EtccjjZl; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231622AbhGDXJB (ORCPT + 99 others); Sun, 4 Jul 2021 19:09:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:46010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230511AbhGDXIR (ORCPT ); Sun, 4 Jul 2021 19:08:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 46F05613E5; Sun, 4 Jul 2021 23:05:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439941; bh=ehz4wRZJTq5WtUVqNeuBwjXjAL4ZYS58kSqK78k9AMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EtccjjZlgJ9zysWwbvbsTqC5hcKpXtLHqxOFK2KeHhO7F/j5nFF2jCl8tvMWvLrD+ is2z64BXHotF6HCC3fsWZdM036XniEqSwjAbldHPoEiiIwCVkde2ziupC4Ie4mEgtx +bbYf+4ZpMg2Zh0AgMLmsnmwopgm6AXZWrUntiAfxlpNzGKSHn+o6I8nFUuU29FnLa WFJGp01p3JF4BTmv9x8JJ8+HsI+cmCleZgej07z3BQYfXBfbxLrr/GF3ioVoR8S/gc qTaU2P1INkqceO+rqzi5OgL93yVwW5vyB9Znf/I/xvuAxeje/S9guGv8Vn7AdxBAVE 7+MnQHTKrrF/A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org Subject: [PATCH AUTOSEL 5.13 59/85] media: dvb_net: avoid speculation from net slot Date: Sun, 4 Jul 2021 19:03:54 -0400 Message-Id: <20210704230420.1488358-59-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mauro Carvalho Chehab [ Upstream commit abc0226df64dc137b48b911c1fe4319aec5891bb ] The risk of especulation is actually almost-non-existing here, as there are very few users of TCP/IP using the DVB stack, as, this is mainly used with DVB-S/S2 cards, and only by people that receives TCP/IP from satellite connections, which limits a lot the number of users of such feature(*). (*) In thesis, DVB-C cards could also benefit from it, but I'm yet to see a hardware that supports it. Yet, fixing it is trivial. Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/dvb-core/dvb_net.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c index 89620da983ba..dddebea644bb 100644 --- a/drivers/media/dvb-core/dvb_net.c +++ b/drivers/media/dvb-core/dvb_net.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -1462,14 +1463,20 @@ static int dvb_net_do_ioctl(struct file *file, struct net_device *netdev; struct dvb_net_priv *priv_data; struct dvb_net_if *dvbnetif = parg; + int if_num = dvbnetif->if_num; - if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX || - !dvbnet->state[dvbnetif->if_num]) { + if (if_num >= DVB_NET_DEVICES_MAX) { ret = -EINVAL; goto ioctl_error; } + if_num = array_index_nospec(if_num, DVB_NET_DEVICES_MAX); - netdev = dvbnet->device[dvbnetif->if_num]; + if (!dvbnet->state[if_num]) { + ret = -EINVAL; + goto ioctl_error; + } + + netdev = dvbnet->device[if_num]; priv_data = netdev_priv(netdev); dvbnetif->pid=priv_data->pid; @@ -1522,14 +1529,20 @@ static int dvb_net_do_ioctl(struct file *file, struct net_device *netdev; struct dvb_net_priv *priv_data; struct __dvb_net_if_old *dvbnetif = parg; + int if_num = dvbnetif->if_num; + + if (if_num >= DVB_NET_DEVICES_MAX) { + ret = -EINVAL; + goto ioctl_error; + } + if_num = array_index_nospec(if_num, DVB_NET_DEVICES_MAX); - if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX || - !dvbnet->state[dvbnetif->if_num]) { + if (!dvbnet->state[if_num]) { ret = -EINVAL; goto ioctl_error; } - netdev = dvbnet->device[dvbnetif->if_num]; + netdev = dvbnet->device[if_num]; priv_data = netdev_priv(netdev); dvbnetif->pid=priv_data->pid; -- 2.30.2