Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2456930imd; Fri, 2 Nov 2018 11:43:42 -0700 (PDT) X-Google-Smtp-Source: AJdET5cdovOc1vs2OnGApfDfSLwuyZuHXGQkpfmos4lUKCqV2JNa4gyhj0lh4z5VTuMjJA7j1ms/ X-Received: by 2002:a63:ea07:: with SMTP id c7-v6mr11296534pgi.361.1541184222680; Fri, 02 Nov 2018 11:43:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184222; cv=none; d=google.com; s=arc-20160816; b=pVEgq3q/b31HVb0+7nIT2r8ccs0K4llNLs+t8P5p8BzYRCo0krZAz0+y+1sKSQCsQz iKxShuPdJ/T3oNp2pxORdao2eKnmfkVY+Fm+sAsrHthXYlqSG8LK4uHerDlIdZ9Yig40 XVpruG8yKrw7EuaM56yxGOTEQeQJrYsrP96er4vfY2Q4JBFx+8TcAw/MfqorvGN3l8PL Aymj7DmFW1UmNKuHOGHlSHwZut7aa4y25Cu/IU8O7ITkQrWD3zKWHBrsUqJrmAgBzq/Q 9B22V8Cr9+tFj1C6HZaMB5BwawAgiyv79gikBfKWTWX1rExEzuIgQwGaoDFXTIwcuK6L LECA== 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=hfw9w4nItfcw+8uWK7vO8ZEubC42iiViKZKKlMmVYvM=; b=A5uYP1g4g1hD/pn125sECzqa8NQvkiqIq7cdC7oEFwkKn8U60ediYVgFDflGifKC3/ cb5R4zt9zOLC6uEwvkSyR7It4rkfVum/LwiNQlTduUUf7NWoWdYcQLltMG443pYvS0M0 zUr42Qt0eVi+1awB3Wizd3V9fFYJc44cydw04GFoG4+k5+PTGTRZT2T140HV+phO7ess 72KkOL5xck+RpagKrm2/fiAs9d9IkEdWkiKRtBo74nfuVtJDYkw6oP7YzlKxmU84kB9l IodFFMgqgQcGXMWvphVXDpAVAeKKcIdWJFGtdYET8X+OdEDga44W/wPaxyfWGRJH9v3U cOow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Byc1mc2u; 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 l11-v6si28904370pgm.102.2018.11.02.11.43.28; Fri, 02 Nov 2018 11:43:42 -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=Byc1mc2u; 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 S1729513AbeKCDtU (ORCPT + 99 others); Fri, 2 Nov 2018 23:49:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:43884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728441AbeKCDtT (ORCPT ); Fri, 2 Nov 2018 23:49:19 -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 99B8E2082E; Fri, 2 Nov 2018 18:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184067; bh=NHsJWOeWxfK8K9+maimBZ+1LWZomPaco6LtWQp5TaHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Byc1mc2ub6e6q532cHi5PaE1vcyO2BPxhz4Png7tx0gRKAgxX51riLwhD2Lbb0GEp HrNbE1BgSGITgV0cE1Ai1VoUjw7VhcfKDsKrNEcQIqBIxpryMtWnIPopN/x9yuv1bW tgjtu9P7Qnv+P5tGvd47y+kBGfpRdeGZFQvjm1oI= 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.18 069/150] yam: fix a missing-check bug Date: Fri, 2 Nov 2018 19:33:51 +0100 Message-Id: <20181102182908.415893703@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@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.18-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 16ec7af6ab7b..ba9df430fca6 100644 --- a/drivers/net/hamradio/yam.c +++ b/drivers/net/hamradio/yam.c @@ -966,6 +966,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; @@ -981,6 +983,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