Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp926839ybx; Tue, 5 Nov 2019 07:40:11 -0800 (PST) X-Google-Smtp-Source: APXvYqyYbHA8KCXfSRjpkJNuT/lqAM7bl4h4Z2QKeAnAASPV1U/lTOiDhTxrJEMmRXxA38fF+Ved X-Received: by 2002:a50:fb14:: with SMTP id d20mr32501455edq.190.1572968411256; Tue, 05 Nov 2019 07:40:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572968411; cv=none; d=google.com; s=arc-20160816; b=zY2JgU16UzKe5ybw/Tu7dvgJ4GkEH7/DsDtCZvdmErFa3Be2zAFVPzMrTeGc9HzhXf opEalM0qXPKsLenaS9PvATl5cabD9EEZGv391sHP5Sqw3HyO4eRRsii293yk0vfC9dTq eEeChAMKfeKoiL+X+tZUzTxvcJLFi68iK8Y7uTNpfWY15aiTRCgJVZlFIYV6AAQi4MCw X3C2rst70PpGDqK/FYdx/WE7kpH9FdUfaixUIbi67dg+6WYGXEU50cbg8qtSmvUKcm+o TK69afaa3ShEWKkNtFsfmEZWb/ndN8DaJt2hEMPNOD9FkFYJAimSPin/e41LHEfXzBGL wIcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:user-agent:in-reply-to:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=llQqP/MIKLwYmmOq7Ay07ojdKO0cDkSl+N2wZY18JQY=; b=ZhYZlYWiFwnl6CzHAQkX+68001B+5wqJMM1VJk2xShfpD/ZLZNmBiiG/BgsVSAC7hk BmWA4DkeXLUJGb+KsuhcDx2Q6FTh6u1PFSTB9BEfcIKXmFfbWK7X8Rj1pLa9XJ3sIpmS Rquqqhd8ZPiy+25nTyp1dO85sVTeOg54bOzkDqRdsGgxEzpGGLrTSdr4+C7bxODg5QvM 81xpXN2Rckqw5K6cycP9nhrgQmtdlcvqX/18CGZD7mAwaFy0cdw2YGAanjjIo83hBkuX kBibzWfVpfqteCFpErtRBX2AkpPxulrHclmfJGkpBrl35bIlom2DgksiBcJwIxIZVvi8 05WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Zw7ktJVt; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3si9008977edx.449.2019.11.05.07.39.46; Tue, 05 Nov 2019 07:40:11 -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=@redhat.com header.s=mimecast20190719 header.b=Zw7ktJVt; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731058AbfKEPhm (ORCPT + 99 others); Tue, 5 Nov 2019 10:37:42 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:35161 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727779AbfKEPhl (ORCPT ); Tue, 5 Nov 2019 10:37:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1572968261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=llQqP/MIKLwYmmOq7Ay07ojdKO0cDkSl+N2wZY18JQY=; b=Zw7ktJVt/mVElyzinUqSP7Hmrkc/caqlJc2jCV4MLD5CfA1cI43NaV7ckGT2bkjW0MwoOU QcPIfUeDapg4K9cUdYvTl9jOUQP2yTIqFP6JgZiOy0pCezCML2932U8kvjYJkWur1nu1ZM 83VrmfODLUAnohSc6rjsC280bqt3zVU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-367-N41daoeQO8a46iXCKb8-vw-1; Tue, 05 Nov 2019 10:37:38 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 193C6477; Tue, 5 Nov 2019 15:37:36 +0000 (UTC) Received: from mail (ovpn-121-157.rdu2.redhat.com [10.10.121.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C8676608B4; Tue, 5 Nov 2019 15:37:35 +0000 (UTC) Date: Tue, 5 Nov 2019 10:37:35 -0500 From: Andrea Arcangeli To: Mike Rapoport Cc: linux-kernel@vger.kernel.org, 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 Subject: Re: [PATCH 1/1] userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK Message-ID: <20191105153735.GF30717@redhat.com> References: <1572967777-8812-1-git-send-email-rppt@linux.ibm.com> <1572967777-8812-2-git-send-email-rppt@linux.ibm.com> MIME-Version: 1.0 In-Reply-To: <1572967777-8812-2-git-send-email-rppt@linux.ibm.com> User-Agent: Mutt/1.12.2 (2019-09-21) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: N41daoeQO8a46iXCKb8-vw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Mike, On Tue, Nov 05, 2019 at 05:29:37PM +0200, Mike Rapoport wrote: > 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. >=20 > Limit availability of UFFD_FEATURE_EVENT_FORK only for callers that have > CAP_SYS_PTRACE. >=20 > Signed-off-by: Mike Rapoport > --- > fs/userfaultfd.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) >=20 > 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, > =09if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api))) > =09=09goto out; > =09features =3D uffdio_api.features; > -=09if (uffdio_api.api !=3D UFFD_API || (features & ~UFFD_API_FEATURES)) = { > -=09=09memset(&uffdio_api, 0, sizeof(uffdio_api)); > -=09=09if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api))) > -=09=09=09goto out; > -=09=09ret =3D -EINVAL; > -=09=09goto out; > -=09} > +=09ret =3D -EINVAL; > +=09if (uffdio_api.api !=3D UFFD_API || (features & ~UFFD_API_FEATURES)) > +=09=09goto err_out; > +=09ret =3D -EPERM; > +=09if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE)) > +=09=09goto err_out; > =09/* report all available features and ioctls to userland */ > =09uffdio_api.features =3D UFFD_API_FEATURES; > =09uffdio_api.ioctls =3D UFFD_API_IOCTLS; > @@ -1853,6 +1852,11 @@ static int userfaultfd_api(struct userfaultfd_ctx = *ctx, > =09ret =3D 0; > out: > =09return ret; > +err_out: > +=09memset(&uffdio_api, 0, sizeof(uffdio_api)); > +=09if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api))) > +=09=09ret =3D -EFAULT; > +=09goto out; > } > =20 > static long userfaultfd_ioctl(struct file *file, unsigned cmd, Reviewed-by: Andrea Arcangeli Thanks, Andrea