Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7002468imu; Wed, 14 Nov 2018 10:07:31 -0800 (PST) X-Google-Smtp-Source: AJdET5dvduTpXVOd9y+G2gZozaNCj8CE5/PB/r+fiOGD56QVjJ01QhHiJsbLfLtev2gMDixQ9ZQD X-Received: by 2002:a63:6205:: with SMTP id w5mr2687945pgb.53.1542218851398; Wed, 14 Nov 2018 10:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542218851; cv=none; d=google.com; s=arc-20160816; b=tDsRIvUmneEyzkDo26RSlvB1gM1aevvaASeUba7EW1obvRonWOw4UDmp7ILh7rF70y phTWGQalAfLPpX3pfIxfTABh9cqf0GUm8ZaAsE1MRLQwUiiDYO1wE1O2+pX+u3n6e8qU QuPhAu6SZdpjvc5aO+BLeBDDmW7xGpoGTnJkZLMMf6E3nKB6Lohk1LX6tvvSlsXruVsG dk6VPVd+7PIlxP3XAnQOgryQWwottXR4f1ui5tqtO54WpgA9ttgGCNzWQA5Xi1NKKWyZ FqXRcQrfOVK9rx86fYcfPlg2Ui5l9bFf0t965dLh7xXPvlFoYQVDbeQ/6Tn6UZma9ChK 3NbA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sCkrbaApNMWNpCr4ZdMrY3i05BYNU74CxCxo2jQah9g=; b=j0J0aiZnY9VH02PiQLZCu7RtAK3/czxDLrcPTfVZKDnXDR2nQWu1Uelytcz2t4omFW yXU60P/z9ksib2UyxN/65UPstIP1tSd2ON+EZejq4C7SyiQ13VRZE1uYbhfAnbA2AYON Fj/JPjhz6TJaWQeWz83SD9R8mpdPc6bV1lWtJEY/giKZsmE/wuluKTraipFNx8IOclxz KmXRNHQEs+6Xy9OUT7lMjK8EAiB0mKnOxm7irWzwcimGYz3y11t6XG3+p4OW7bBAcETF LxsTf7DeHJn1q3jsxWXo0ydyc2o5V7xHqi7x/mRKuN5FKbKWwtAAXuCQa13Won5V4Oik 0olA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v3HMdWKv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k25-v6si25973617pfe.36.2018.11.14.10.07.03; Wed, 14 Nov 2018 10:07:31 -0800 (PST) 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=v3HMdWKv; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732981AbeKOEHT (ORCPT + 99 others); Wed, 14 Nov 2018 23:07:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:35506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727773AbeKOEHT (ORCPT ); Wed, 14 Nov 2018 23:07:19 -0500 Received: from ebiggers.mtv.corp.google.com (unknown [104.132.1.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CF30C21780; Wed, 14 Nov 2018 18:03:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542218586; bh=a2WhmBeZzt2mlohrRWK6xogUa3I/TV4DiusWV0Ecbxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v3HMdWKvX/DNINNazhk5/z17HaUYL3xtZ66p3oGbd+aee15umxPuFS2zNVlzW5dBY SW8XfTpTX3pdxUiiCxeFID6WF8NXMrGL/CO9fXNOlFfphjrd8qGwObqcYB62IPpm0M atXzglTthJYnnK5V8wV+c1POJf/zA0ol+g8gL9Yw= From: Eric Biggers To: David Herrmann , Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Dmitry Vyukov , Dmitry Torokhov , syzbot+72473edc9bf4eb1c6556@syzkaller.appspotmail.com, stable@vger.kernel.org, Jann Horn Subject: [PATCH] HID: uhid: prevent uhid_char_write() under KERNEL_DS Date: Wed, 14 Nov 2018 10:02:17 -0800 Message-Id: <20181114180217.195917-1-ebiggers@kernel.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181114171447.GA87768@gmail.com> References: <20181114171447.GA87768@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers When a UHID_CREATE command is written to the uhid char device, a copy_from_user() is done from a user pointer embedded in the command. When the address limit is KERNEL_DS, e.g. as is the case during sendfile(), this can read from kernel memory. Therefore, UHID_CREATE must not be allowed in this case. For consistency and to make sure all current and future uhid commands are covered, apply the restriction to uhid_char_write() as a whole rather than to UHID_CREATE specifically. Thanks to Dmitry Vyukov for adding uhid definitions to syzkaller and to Jann Horn for commit 9da3f2b740544 ("x86/fault: BUG() when uaccess helpers fault on kernel addresses"), allowing this bug to be found. Reported-by: syzbot+72473edc9bf4eb1c6556@syzkaller.appspotmail.com Fixes: d365c6cfd337 ("HID: uhid: add UHID_CREATE and UHID_DESTROY events") Cc: # v3.6+ Cc: Jann Horn Signed-off-by: Eric Biggers --- drivers/hid/uhid.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c index 3c55073136064..e94c5e248b56e 100644 --- a/drivers/hid/uhid.c +++ b/drivers/hid/uhid.c @@ -705,6 +705,12 @@ static ssize_t uhid_char_write(struct file *file, const char __user *buffer, int ret; size_t len; + if (uaccess_kernel()) { /* payload may contain a __user pointer */ + pr_err_once("%s: process %d (%s) called from kernel context, this is not allowed.\n", + __func__, task_tgid_vnr(current), current->comm); + return -EACCES; + } + /* we need at least the "type" member of uhid_event */ if (count < sizeof(__u32)) return -EINVAL; -- 2.19.1.930.g4563a0d9d0-goog