Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3919236pxv; Mon, 28 Jun 2021 16:39:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPA0iR02T81lvN+h0JySWnLCtSkjAlD6LTFJUQzer2y2BfiMAmZJrXKIkIsGR0ZmwZ24an X-Received: by 2002:a92:da0e:: with SMTP id z14mr1810132ilm.239.1624923598237; Mon, 28 Jun 2021 16:39:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624923598; cv=none; d=google.com; s=arc-20160816; b=tF3CcLOrNlAsJQ0owf/f5MBhlsedpN4I6YRjoCFzj7tf/+7SwQJ/6QzLkcs/2zfhaZ pELTPERcWzN6Bwu1G8zuOuEv91IFHPr8zh/zO6VK7diDQRFrt73agbLyK+gBLNBwhkPJ dn7rEaWf9uoWl43d4HcBsJs/nRhWtJGtMEasbpEKFJdHO7xiREfZ+v5bXRrVkjNjybdE zr/ZQOJ6r/2jU2oebQ7lwLIeVU3utJ1LhU22JMHehWRdwLjmDNl7yzX+tQqyuUQHMsGA rogtvVssW0whBGoXOifsFrKJmuDeTaIZ4cnWXbFItTQBiF4GoLTT6U0Ou/NOlKydP5i9 gIyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :user-agent:message-id:in-reply-to:date:references:cc:to:from; bh=KraxPjDlW7R7GhJmDKxllUoA0pjG+1szWrRmDdQi06Q=; b=HNZ6ibBk0edEu173BVYRv2ts72Icb3HuAT+oga/gfR2cSjeFVetdzlf3Yip7rNTj+/ djJB6kgdAb7C+4D5mJrBAiNQ5CsnPpItNkHSHIfyOFW4WIBQe4y/ro4aUK+ntDXerxpb HE9dHOD+fLhQZZMOqMVtgGXfC9z9mw8cgTRVzs0RO9Q9RCw6OB1NncGxFq0xhR9buJd6 9OmIFdqn91rNul/TOYEN6hpnuvv8cLOkL7iDdhHxVwMU1xW0FR0H7GLDfxgtGjCqAbTI q6TJB7PITZD7Pj7kLu5RSIrD1/s23oC+unv7Kn7XIJaoVaMbjH10E0eDWOWg8aqYBPxe bbPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q11si6247709ilt.85.2021.06.28.16.39.46; Mon, 28 Jun 2021 16:39:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234962AbhF1SUw convert rfc822-to-8bit (ORCPT + 99 others); Mon, 28 Jun 2021 14:20:52 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:44528 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235850AbhF1SUp (ORCPT ); Mon, 28 Jun 2021 14:20:45 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lxvpo-005Y4n-1h; Mon, 28 Jun 2021 12:18:16 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:37902 helo=email.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lxvpm-00GUVd-To; Mon, 28 Jun 2021 12:18:15 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Jann Horn Cc: Andy Lutomirski , Andrei Vagin , Linux Kernel Mailing List , Linux API , linux-um@lists.infradead.org, criu@openvz.org, avagin@google.com, Andrew Morton , Anton Ivanov , Christian Brauner , Dmitry Safonov <0x7f454c46@gmail.com>, Ingo Molnar , Jeff Dike , Mike Rapoport , Michael Kerrisk , Oleg Nesterov , "Peter Zijlstra \(Intel\)" , Richard Weinberger , Thomas Gleixner References: <20210414055217.543246-1-avagin@gmail.com> <20210414055217.543246-3-avagin@gmail.com> Date: Mon, 28 Jun 2021 13:18:07 -0500 In-Reply-To: (Jann Horn's message of "Mon, 28 Jun 2021 19:14:31 +0200") Message-ID: <87o8bpyhsw.fsf@disp2133> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-XM-SPF: eid=1lxvpm-00GUVd-To;;;mid=<87o8bpyhsw.fsf@disp2133>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+tjKQ2S/wElv4BubhnpKaH2QbS07hFhis= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa05.xmission.com X-Spam-Level: *** X-Spam-Status: No, score=3.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01, T_XMDrugObfuBody_08,XMNoVowels,XMSubLong,XM_B_SpammyWords,XM_B_Unicode autolearn=disabled version=3.4.2 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4998] * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * 0.0 XM_B_Unicode BODY: Testing for specific types of unicode * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa05 1397; Body=1 Fuz1=1 Fuz2=1] * 0.2 XM_B_SpammyWords One or more commonly used spammy words * 1.0 T_XMDrugObfuBody_08 obfuscated drug references * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;Jann Horn X-Spam-Relay-Country: X-Spam-Timing: total 497 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 13 (2.6%), b_tie_ro: 11 (2.3%), parse: 1.56 (0.3%), extract_message_metadata: 7 (1.3%), get_uri_detail_list: 3.4 (0.7%), tests_pri_-1000: 7 (1.4%), tests_pri_-950: 1.82 (0.4%), tests_pri_-900: 1.49 (0.3%), tests_pri_-90: 105 (21.0%), check_bayes: 102 (20.6%), b_tokenize: 13 (2.6%), b_tok_get_all: 11 (2.1%), b_comp_prob: 3.7 (0.7%), b_tok_touch_all: 71 (14.2%), b_finish: 1.27 (0.3%), tests_pri_0: 340 (68.4%), check_dkim_signature: 0.78 (0.2%), check_dkim_adsp: 3.4 (0.7%), poll_dns_idle: 0.88 (0.2%), tests_pri_10: 2.2 (0.4%), tests_pri_500: 7 (1.4%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 2/4] arch/x86: implement the process_vm_exec syscall X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jann Horn writes: > On Mon, Jun 28, 2021 at 6:30 PM Andy Lutomirski wrote: >> On Mon, Jun 28, 2021, at 9:13 AM, Jann Horn wrote: >> > On Wed, Apr 14, 2021 at 7:59 AM Andrei Vagin wrote: >> > > This change introduces the new system call: >> > > process_vm_exec(pid_t pid, struct sigcontext *uctx, unsigned long flags, >> > > siginfo_t * uinfo, sigset_t *sigmask, size_t sizemask) >> > > >> > > process_vm_exec allows to execute the current process in an address >> > > space of another process. >> > [...] >> > >> > I still think that this whole API is fundamentally the wrong approach >> > because it tries to shoehorn multiple usecases with different >> > requirements into a single API. But that aside: >> > >> > > +static void swap_mm(struct mm_struct *prev_mm, struct mm_struct *target_mm) >> > > +{ >> > > + struct task_struct *tsk = current; >> > > + struct mm_struct *active_mm; >> > > + >> > > + task_lock(tsk); >> > > + /* Hold off tlb flush IPIs while switching mm's */ >> > > + local_irq_disable(); >> > > + >> > > + sync_mm_rss(prev_mm); >> > > + >> > > + vmacache_flush(tsk); >> > > + >> > > + active_mm = tsk->active_mm; >> > > + if (active_mm != target_mm) { >> > > + mmgrab(target_mm); >> > > + tsk->active_mm = target_mm; >> > > + } >> > > + tsk->mm = target_mm; >> > >> > I'm pretty sure you're not currently allowed to overwrite the ->mm >> > pointer of a userspace thread. For example, zap_threads() assumes that >> > all threads running under a process have the same ->mm. (And if you're >> > fiddling with ->mm stuff, you should probably CC linux-mm@.) >> >> exec_mmap() does it, so it can’t be entirely impossible. > > Yeah, true, execve can do it - I guess the thing that makes that > special is that it's running after de_thread(), so it's guaranteed to > be single-threaded? Even the implementation detail of swapping the mm aside. Even the idea of swaping the mm is completely broken, as an endless system calls depend upon the state held in task_struct. io_uring just tried running system calls of a process in a different context and we ultimately had to make the threads part of the original process to make enough things work to keep the problem tractable. System calls deeply and fundamentally depend on task_struct and signal_struct. I can think of two possibilities. 1) Hijack and existing process thread. 2) Inject a new thread into an existing process. Anything else is just an exercise in trouble. Of this I think Hijacking an existing thread is the only one that won't require lots of tracking down of special cases. I seem to remember audit is still struggling with how to properly audit io_uring threads. Eric