From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C472C433F5 for ; Mon, 27 Sep 2021 20:11:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2F7C260FD7 for ; Mon, 27 Sep 2021 20:11:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2F7C260FD7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BDE716B0071; Mon, 27 Sep 2021 16:11:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8E796B0072; Mon, 27 Sep 2021 16:11:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7E206B0073; Mon, 27 Sep 2021 16:11:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0068.hostedemail.com [216.40.44.68]) by kanga.kvack.org (Postfix) with ESMTP id 9A3936B0071 for ; Mon, 27 Sep 2021 16:11:29 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5DAEF2FD73 for ; Mon, 27 Sep 2021 20:11:29 +0000 (UTC) X-FDA: 78634448298.12.FD93DD3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf08.hostedemail.com (Postfix) with ESMTP id D44B130000A9 for ; Mon, 27 Sep 2021 20:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632773488; 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=pj/EUfIghA08vvhVZK2MUBzA9iLVxgFUTk/F+NTTbH4=; b=HCaM8PRNXLOYtvVkx14Qs4tueyA8dqDvvQYPpRWdRrbqmIk7SIPdEzSyMIPZvI3S3AqKBV sgxKXn5gaHAw30Kqk4sUVZlYoUk91HmIuKPB2xRZjm34K78pRqSiDXKB2KHUM1k0uokPuE YRBENji7068/utkYJGVzxGdtNz0xSXQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-217-QOXHFZpUPIqSZ9azRsqvGA-1; Mon, 27 Sep 2021 16:11:27 -0400 X-MC-Unique: QOXHFZpUPIqSZ9azRsqvGA-1 Received: by mail-wm1-f71.google.com with SMTP id j21-20020a05600c1c1500b0030ccce95837so337226wms.3 for ; Mon, 27 Sep 2021 13:11:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=pj/EUfIghA08vvhVZK2MUBzA9iLVxgFUTk/F+NTTbH4=; b=JEjIj9Hn+0/TfnDEvCxzIxuf68G9nxX1Iwb2B592OHcIVMq4JpHhsjf6Z2Nusqm/oy NTid94jkue/L/rlimQUnW7DBQW9NKZ/FLgqdHp2xj7l5K7VphYBnLoJU783NMGTB55Jx mOsGue7fkC1+bpqbyjJ6Hmd3nWdSxSskisv+20Hq/VWQlYsbdaFFvzLbFUPG0OHxqBKl RV8vrbYL+E/aC3ASIKhlXe1VjJgqJLbNWQ6ttZKRkPFBqqJWzlSFF+QKsb8AC+SojSS2 IkCE2BqWi/lCG8K+NhyXiAfVO9+LMzYZzZXwkNuATwLf14jGplGgbJn8Tfb3yg7pe2yg 7rkA== X-Gm-Message-State: AOAM532J4mlIeYeFht0bnZPfrnGxBFwHWgj/6FUMLqqaT0D4bagW9zwS bzN39YmYG63xFNWxR8x40qyiUNWUYuLCcptnECpB3JlMoWVzjJ0TH6tDlW05BTbmHxZdSgJnRC6 Xf1rlvNuWfLI= X-Received: by 2002:a5d:664f:: with SMTP id f15mr851849wrw.143.1632773485931; Mon, 27 Sep 2021 13:11:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoWvQUJqxRNlHP8f8DrBT7m8as2FOZ2XM1YS2Y0rWerq8c02XB8yG4qH8aOZoEGqYDpXufyw== X-Received: by 2002:a5d:664f:: with SMTP id f15mr851828wrw.143.1632773485671; Mon, 27 Sep 2021 13:11:25 -0700 (PDT) Received: from [192.168.3.132] (p5b0c654d.dip0.t-ipconnect.de. [91.12.101.77]) by smtp.gmail.com with ESMTPSA id i203sm544747wma.7.2021.09.27.13.11.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Sep 2021 13:11:25 -0700 (PDT) Subject: Re: [RFC PATCH] userfaultfd: support control over mm of remote PIDs To: Nadav Amit Cc: Andrew Morton , Linux-MM , Linux Kernel Mailing List , Andrea Arcangeli , Mike Rapoport , Peter Xu References: <20210926170637.245699-1-namit@vmware.com> <83827672-0996-4c25-9991-697ad443b6b3@redhat.com> <21c6a41d-3f65-6a49-f604-b75ef53d2910@redhat.com> <75ECD9E1-4696-42CB-BD84-FF9C350BB227@gmail.com> From: David Hildenbrand Organization: Red Hat Message-ID: <6ab883e5-e49e-73ca-9f48-6251d57622e9@redhat.com> Date: Mon, 27 Sep 2021 22:11:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <75ECD9E1-4696-42CB-BD84-FF9C350BB227@gmail.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: D44B130000A9 X-Stat-Signature: 5kewgjbaufftcunibu56tb8hxwmmhaey Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HCaM8PRN; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf08.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com X-HE-Tag: 1632773488-744347 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 27.09.21 22:08, Nadav Amit wrote: >=20 >=20 >> On Sep 27, 2021, at 10:06 AM, David Hildenbrand wro= te: >> >> On 27.09.21 12:19, Nadav Amit wrote: >>>> On Sep 27, 2021, at 2:29 AM, David Hildenbrand wr= ote: >>>> >>>> On 26.09.21 19:06, Nadav Amit wrote: >>>>> From: Nadav Amit >>>>> Non-cooperative mode is useful but only for forked processes. >>>>> Userfaultfd can be useful to monitor, debug and manage memory of re= mote >>>>> processes. >>>>> To support this mode, add a new flag, UFFD_REMOTE_PID, and an optio= nal >>>>> second argument to the userfaultfd syscall. When the flag is set, t= he >>>>> second argument is assumed to be the PID of the process that is to = be >>>>> monitored. Otherwise the flag is ignored. >>>>> The syscall enforces that the caller has CAP_SYS_PTRACE to prevent >>>>> misuse of this feature. >>>> >>>> What supposed to happen if the target process intents to use uffd it= self? >>> Thanks for the quick response. >>> First, sorry that I mistakenly dropped the changes to userfaultfd.h >>> that define UFFD_REMOTE_PID. >> >> Didn't even notice it :) >> >>> As for your question: there are standard ways to deal with such cases= , >>> similarly to when a debugged program wants to use PTRACE. One way is >>> to block the userfaultfd syscall, using seccomp. Another way is to do >>> chaining using ptrace (although using ptrace for anything is >>> challenging). >>> It is also possible to add tailor something specific to userfaultfd, >>> but I think seccomp is a good enough solution. I am open to suggestio= ns. >> >> If we have something already in place to handle PTRACE, we'd better re= use what's already there. Thanks! >=20 > Just to ensure we are on the same page: I meant that this is usually > left for the user application to handle. The 2 basic solutions are to > not expose userfaultfd to the monitored process (easy using seccomp) > or to chain the two monitors (hard using ptrace). Yes, and I agree that the first approach then makes sense. Chaining=20 might be way to complicated to support. As long as the kernel will continue working when a second one tries to=20 register (which I think is the case), that should be good enough. >=20 > Since ptrace is hard, in theory we can have facilities to =E2=80=9Chija= ck=E2=80=9D > a context and =E2=80=9Cinject=E2=80=9D uffd event to another monitor. I= just think > it is a total overkill at this stage. Agreed --=20 Thanks, David / dhildenb