Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2464001imd; Fri, 2 Nov 2018 11:51:54 -0700 (PDT) X-Google-Smtp-Source: AJdET5dVFsJJqDH8n7FGvRtXsO2XKxQB5QmDeH/U+hp+wxnQfwAX5NupQ1JMW/Zx07vzXHkgsygx X-Received: by 2002:a63:cc0b:: with SMTP id x11-v6mr11737093pgf.33.1541184714293; Fri, 02 Nov 2018 11:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184714; cv=none; d=google.com; s=arc-20160816; b=wGG3fyJleq8KGxlJB3gGQs290iTSlesXd7Cqmy1b78K2AEcjhHZTVIlfE15ffActLc ClDRIaL3P5ZMB+BIeyaveSkVbH982gOgFu2KrJ6Otn99o6cXQvpMKW5ZS6VIEZowZFcI TA7600iAU7n9BsnZBhTT0ilPrKzUdrp1jlX4xbCLalf8CuLHmT/tZqvIk1LpD2022rzr yftX9y5YjqWCUIbRoq9dO6JcG3EfLHKnJPY9kwGxitzIDMZcFaeQf/mySHVZ8G2t5WRX X6JTllMUfgzp4vYPntjMx6zwuFUSFYj8CqxDZjRb0UzbVTL/qMOBDjpaMutXozS3j63Q lLGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iKTJ2xvO27cHcIqGpWWfgKuVJaSDUA/Bc6fkFb78c1k=; b=ZZ7xB8FqoyCEaVPd6IJvn4ENeeOQtAxjgsBXyeMRqEbAGJ3VuVzMaE9R142MplZIgg yCw7bMaJcFck9GKeJsvvxNxXVAB4UX3eQpvNs8myVOcjw2A21pbO7m8QiSXpsTp+I6mC HqZNQca1kMCj6FUdY2MSarSUhPG5J51jAaoUQ6VB1McJaC3sAP4i43bOpzyzdw9GKlRU d1H7z7BYHfWActy/vgQmVpCX8wK6rFErnHwZHCEGo5GXmOFNM3X9BxOG+QrXsxSw3d7e kweA8isjShJnDqrV7zf8X/3P9aMweg8+ppqNgXJUEJ/p/9IZxSFDvEHLb0TZYU7S34hb hnsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HorLzLCe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5-v6si16703871pfe.237.2018.11.02.11.51.39; Fri, 02 Nov 2018 11:51:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HorLzLCe; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730765AbeKCD6T (ORCPT + 99 others); Fri, 2 Nov 2018 23:58:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:54080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728280AbeKCD6S (ORCPT ); Fri, 2 Nov 2018 23:58:18 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 443552082D; Fri, 2 Nov 2018 18:50:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184603; bh=Que25jxbaDSrZ9jNXlVNKusTgd97Doq+/1rkgDuvnTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HorLzLCeeTSj03VHkuNTdujtcOYzwY3ASxaDc3eeAqvERlt2fVYHYHxtYihAY2b4S MR93bOD06eHwXLEobOrdHdguGZxtuiStArK7lpQ04BkhWCMmBOf+g34+aoZ6p3Mbhg fONMCcyyoS8bhIKX/lCujfbIrnYbs/cavDsQuHI0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 048/143] yam: fix a missing-check bug Date: Fri, 2 Nov 2018 19:33:53 +0100 Message-Id: <20181102182900.897198861@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182857.064326086@linuxfoundation.org> References: <20181102182857.064326086@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 0781168e23a2fc8dceb989f11fc5b39b3ccacc35 ] In yam_ioctl(), the concrete ioctl command is firstly copied from the user-space buffer 'ifr->ifr_data' to 'ioctl_cmd' and checked through the following switch statement. If the command is not as expected, an error code EINVAL is returned. In the following execution the buffer 'ifr->ifr_data' is copied again in the cases of the switch statement to specific data structures according to what kind of ioctl command is requested. However, after the second copy, no re-check is enforced on the newly-copied command. Given that the buffer 'ifr->ifr_data' is in the user space, a malicious user can race to change the command between the two copies. This way, the attacker can inject inconsistent data and cause undefined behavior. This patch adds a re-check in each case of the switch statement if there is a second copy in that case, to re-check whether the command obtained in the second copy is the same as the one in the first copy. If not, an error code EINVAL will be returned. Signed-off-by: Wenwen Wang Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/hamradio/yam.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c index 7a7c5224a336..16a6e1193912 100644 --- a/drivers/net/hamradio/yam.c +++ b/drivers/net/hamradio/yam.c @@ -980,6 +980,8 @@ static int yam_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) sizeof(struct yamdrv_ioctl_mcs)); if (IS_ERR(ym)) return PTR_ERR(ym); + if (ym->cmd != SIOCYAMSMCS) + return -EINVAL; if (ym->bitrate > YAM_MAXBITRATE) { kfree(ym); return -EINVAL; @@ -995,6 +997,8 @@ static int yam_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) if (copy_from_user(&yi, ifr->ifr_data, sizeof(struct yamdrv_ioctl_cfg))) return -EFAULT; + if (yi.cmd != SIOCYAMSCFG) + return -EINVAL; if ((yi.cfg.mask & YAM_IOBASE) && netif_running(dev)) return -EINVAL; /* Cannot change this parameter when up */ if ((yi.cfg.mask & YAM_IRQ) && netif_running(dev)) -- 2.17.1