Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp917277ybx; Tue, 5 Nov 2019 07:31:31 -0800 (PST) X-Google-Smtp-Source: APXvYqyJrs8xgQOERZ58idPnvizIGcUZaqTWZP7P/qpfVRbQxQccI22VXpHRbWHzwMHB9fNXpV6H X-Received: by 2002:a17:906:1c4d:: with SMTP id l13mr19191987ejg.308.1572967891138; Tue, 05 Nov 2019 07:31:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572967891; cv=none; d=google.com; s=arc-20160816; b=ZD3VxdmFJ2zVfSPva2H6Afpr6RF8/g6O6QcX6ZaSYBSzhjB9+aS0cXCvYp/s3dazgM UU2Jf5T3lYgcxVE82mAcHG/N34LFfvUr342Ft3s37hgbyZ0hkAcNYc3YbEjVD67OhJd+ Pjec8V6Df09AgBQ4UOdR2LoVNXz9yDmcCRAlFbTnwUgC8Bo+/ZJiMunFGsDNqelIHynS VUET3+5txQapqzpvo7RE8HYxrKAtXqtCreU0YOmxeLNkrSUjShcIsXk5lA86BAAqO+mw ri40QreY7VkPHnjYCU2m15TIGds2ZJ8GlUxJy0Ehga3iIvFpQ/VZllXReZ4mgqYx9Rlt 4osQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from; bh=Ko9+86eEplRLpCvT3ewDoVWjH8/7BbEq69b+YqyDsx0=; b=SPIOiUt8b8St/Ue9bB1ejp5Q9nwJ/pFURpO+DBTvq1vVpK4XnPTJuhyKRoZ5W9Bwa+ KSU0HjqxgTqBxsVh/p3jPBns3s9xYzrQdcjnWq/JPFHdqH2zAE28UKSfZVMQY4ibbsis Lp+vUJvpHOZIC/hdDu4L5w+0oicxijRe4v9iFkn2Y9qrbPJNUmKO2IdSgoNg0mopRQf6 QlDR+0jhg0o7bSJn19i+MOpiPILFhc7G4qQNhucQiEG2NrnwBafLVAlaaLvZ2mtwYQRl hIgTJtyg6UJqdErbz18semd0i+fFv7otZAXgUDVS6AQnAbCJrKPdvDgWZrj4YKsZvZdj ye1A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j11si10351158edj.43.2019.11.05.07.31.07; Tue, 05 Nov 2019 07:31: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389959AbfKEP3w (ORCPT + 99 others); Tue, 5 Nov 2019 10:29:52 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:48256 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389925AbfKEP3v (ORCPT ); Tue, 5 Nov 2019 10:29:51 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id xA5FRcuf042315 for ; Tue, 5 Nov 2019 10:29:50 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2w3apstdrr-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 05 Nov 2019 10:29:49 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Nov 2019 15:29:48 -0000 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 5 Nov 2019 15:29:44 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id xA5FT82Z18809216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Nov 2019 15:29:08 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 822D352052; Tue, 5 Nov 2019 15:29:43 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.8.59]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 703345204E; Tue, 5 Nov 2019 15:29:41 +0000 (GMT) Received: by rapoport-lnx (sSMTP sendmail emulation); Tue, 05 Nov 2019 17:29:40 +0200 From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , Andrew Morton , Andy Lutomirski , Daniel Colascione , Jann Horn , Linus Torvalds , Lokesh Gidra , Nick Kralevich , Nosh Minwalla , Pavel Emelyanov , Tim Murray , linux-api@vger.kernel.org, linux-mm@kvack.org, Mike Rapoport Subject: [PATCH 1/1] userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK Date: Tue, 5 Nov 2019 17:29:37 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1572967777-8812-1-git-send-email-rppt@linux.ibm.com> References: <1572967777-8812-1-git-send-email-rppt@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19110515-0020-0000-0000-00000382C8FB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19110515-0021-0000-0000-000021D8F36B Message-Id: <1572967777-8812-2-git-send-email-rppt@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-11-05_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1911050127 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current implementation of UFFD_FEATURE_EVENT_FORK modifies the file descriptor table from the read() implementation of uffd, which may have security implications for unprivileged use of the userfaultfd. Limit availability of UFFD_FEATURE_EVENT_FORK only for callers that have CAP_SYS_PTRACE. Signed-off-by: Mike Rapoport --- fs/userfaultfd.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index f9fd18670e22..d99d166fd892 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1834,13 +1834,12 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api))) goto out; features = uffdio_api.features; - if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) { - memset(&uffdio_api, 0, sizeof(uffdio_api)); - if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api))) - goto out; - ret = -EINVAL; - goto out; - } + ret = -EINVAL; + if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) + goto err_out; + ret = -EPERM; + if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE)) + goto err_out; /* report all available features and ioctls to userland */ uffdio_api.features = UFFD_API_FEATURES; uffdio_api.ioctls = UFFD_API_IOCTLS; @@ -1853,6 +1852,11 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, ret = 0; out: return ret; +err_out: + memset(&uffdio_api, 0, sizeof(uffdio_api)); + if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api))) + ret = -EFAULT; + goto out; } static long userfaultfd_ioctl(struct file *file, unsigned cmd, -- 2.7.4