Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1052518ybz; Wed, 29 Apr 2020 14:08:54 -0700 (PDT) X-Google-Smtp-Source: APiQypLaHiY+ocjQxK5czdE02Tya9/umkmIxMA0cha7XyQInZ1FkohppdKlrmEWUf/6cS6i+Q+K+ X-Received: by 2002:aa7:c38a:: with SMTP id k10mr4362020edq.74.1588194534310; Wed, 29 Apr 2020 14:08:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588194534; cv=none; d=google.com; s=arc-20160816; b=EuH8io6hm9rBa+ko3B9TuVmxify9Ovr/I/oL8kkO6pYg29Oymv3OwzoHRW7iGWNqN9 5fUeTuDUXK8ki/lZLvHwUCoVuDd3aAisw6VtWTfayO46GgKu3RvNPIOogLBkL0KH2rs8 689SYoAaD7tc5zA0izMXm7QHfRzeFbMJNIpUWcpcbSjerg0mlrptzcRicOF9yjgf2lX2 1WUkJ27ZkPgi5tZMnF1fVNBdAMfy+P132wtI3C5GlG0BA6QiuacidF4QSton76SgaMIl JBZ4pEU8G1+pprrndqhxUBClepDVllRIzQ00T6Lzy17d87N7cRAYwehF4hfZpa+KmAJk DoOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vAEd4qpGTjTsBxSUDQpX7WNc+9HLuCvKB3PWjQN65+M=; b=o/WTqplWx/FA9GQotCu1QzykHSPXfEvVGb1npssnNXg57U5RU+9fPxlpu2/LNxMXn8 MRWupFeGPAqN4NUsiI6oNsUgurQ3Ve3zIceGGdO4dMMzXkuw7ldjdG2EkuN8+vUOwOm8 6m7hJReL0w04wAUR2mtpE1xEvLP5lSaZJBykPiiZDkkA+CfL6Xbf/KNzljLC69jbc9x6 4Mv+7xG2jPGrlYjtMvXIz6/c8gfRgjZbX4f+xxmXyzFbF2zcUl6NJccjM5k5vaOozPNx h2snIg5iTJKA82zggCjOc17GGebqVnzMn7NwvPYH7G+rFaEZ2qJlZ5culbqJvN2bOI1E a4kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RpIE4N1F; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c23si4507126edy.407.2020.04.29.14.08.30; Wed, 29 Apr 2020 14:08:54 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=RpIE4N1F; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727815AbgD2VHD (ORCPT + 99 others); Wed, 29 Apr 2020 17:07:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726921AbgD2VG4 (ORCPT ); Wed, 29 Apr 2020 17:06:56 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF99DC03C1AE for ; Wed, 29 Apr 2020 14:06:55 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id b2so4187189ljp.4 for ; Wed, 29 Apr 2020 14:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vAEd4qpGTjTsBxSUDQpX7WNc+9HLuCvKB3PWjQN65+M=; b=RpIE4N1FPowHX+ITy8WXaLniD4bN254LFjfzcaiky6gLlMEzTzFXmIOW08lsIwFRPw 4kAEYwSnqYnpTDaLW26Btj6q97j9n509Tp44iyoRUvHda7BagxRbTeUL2NFKfg7uv9Fu WFxQKJYk1EH0u/p4SFcq/xN9BhfK/v+/t7E97m6jWLlHPPg9imS5kvly5P5hGpy+6WBU 45Ijg29/vaCA5lkdc2NVjZVYuYG8tyupiwMS5DDMXibOdZO+OqTGlY0thGK8qL3u/+YF aw1fUNR2wIIYae++uk9LIRxidGdkHuiP1nTZKQhO7MzJTsL3BlSN+hkFafDkxfzSW3cA Gfwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vAEd4qpGTjTsBxSUDQpX7WNc+9HLuCvKB3PWjQN65+M=; b=K9oUY+cDPnnGXrUzh0fUkf6WB/LnClFEd8X1FtBOSnQdTwdrvOzhy4JBLxMMKeR0Zz Y1s851LWKPGwuWnZ0rBp5PyFdfwcGgCIPXj1YQUz6+LC4/CQdwtwuV6lkFfcQkK3pzrg p2r2AzWsa7y1ChNDVerpjzrVrMmlMNq9G9OOfNXuYjd+EbtSB9oJkScC2rImVpPV4EDz S3J+xfltzl/AEk+BOGmwJlCS/qeyn2rTvUFB6VjCQFEauUIwhw7P4gw+/wDK0/Gs9t3+ yeIInNseaSGtIfKQBn4LW/JjzU+xT7540vxKLWYVLeSzRDMJO4ocj6NEaIVaVp5f3GB5 aRFw== X-Gm-Message-State: AGi0PubnQ72MTL0VLLA55ikCcSdj2WeDzty8J3DAmacyH5CNE0HuqqBA u9c5ESiWX4J7SbSGkejIkRtfFpG3fnFsjmFPrKZRQQ== X-Received: by 2002:a2e:87d0:: with SMTP id v16mr70612ljj.137.1588194413842; Wed, 29 Apr 2020 14:06:53 -0700 (PDT) MIME-Version: 1.0 References: <20200428190836.GC29960@redhat.com> In-Reply-To: From: Jann Horn Date: Wed, 29 Apr 2020 23:06:26 +0200 Message-ID: Subject: Re: [GIT PULL] Please pull proc and exec work for 5.7-rc1 To: Bernd Edlinger Cc: Linus Torvalds , Oleg Nesterov , "Eric W. Biederman" , Waiman Long , Ingo Molnar , Will Deacon , Linux Kernel Mailing List , Alexey Gladkov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 29, 2020 at 10:20 PM Bernd Edlinger wrote: > On 4/29/20 9:26 PM, Jann Horn wrote: > > On Wed, Apr 29, 2020 at 9:23 PM Bernd Edlinger > > wrote: > >> On 4/29/20 7:58 PM, Linus Torvalds wrote: > >>> On Tue, Apr 28, 2020 at 4:36 PM Jann Horn wrote: > >>>> > >>>> On Wed, Apr 29, 2020 at 12:14 AM Linus Torvalds > >>>> wrote: > >>>>> > >>>>> - we move check_unsafe_exec() down. As far as I can tell, there's no > >>>>> reason it's that early - the flags it sets aren't actually used until > >>>>> when we actually do that final set_creds.. > >>>> > >>>> Right, we should be able to do that stuff quite a bit later than it happens now. > >>> > >>> Actually, looking at it, this looks painful for multiple reasons. > >>> > >>> The LSM_UNSAFE_xyz flags are used by security_bprm_set_creds(), which > >>> when I traced it through, happened much earlier than I thought. Making > >>> things worse, it's done by prepare_binprm(), which also potentially > >>> gets called from random points by the low-level binfmt handlers too. > >>> > >>> And we also have that odd "fs->in_exec" flag, which is used by thread > >>> cloning and io_uring, and I'm not sure what the exact semantics are. > >>> > >>> I'm _almost_ inclined to say that we should just abort the execve() > >>> entirely if somebody tries to attach in the middle. > >>> > >>> IOW, get rid of the locking, and replace it all just with a sequence > >>> count. Make execve() abort if the sequence count has changed between > >>> loading the original creds, and having installed the new creds. > >>> > >>> You can ptrace _over_ an execve, and you can ptrace _after_ an > >>> execve(), but trying to attach just as we execve() would just cause > >>> the execve() to fail. > >>> > >>> We could maybe make it conditional on the credentials actually having > >>> changed at all (set another flag in bprm_fill_uid()). So it would only > >>> fail for the suid exec case. > >>> > >>> Because honestly, trying to ptrace in the middle of a suid execve() > >>> sounds like an attack, not a useful thing. > >>> > >> > >> I think the use case where a program attaches and detaches many > >> processes at a high rate, is either an attack or a very aggressive > >> virus checker, fixing a bug that prevents an attack is not a good > >> idea, but fixing a bug that would otherwise break a virus checker > >> would be a good thing. > >> > >> By the way, all other attempts to fix it look much more dangerous > >> than my initially proposed patch, you know the one you hated, but > >> it does work and does not look overly complicated either. > >> > >> What was the reason why that cannot be done this way? > > > > I'm not sure which patch you're talking about - I assume you don't > > mean ? > > > > No, I meant: > > [PATCH v7 15/16] exec: Fix dead-lock in de_thread with ptrace_attach > https://marc.info/?l=linux-kernel&m=158559277631548&w=2 (on lore: https://lore.kernel.org/lkml/AM6PR03MB51700577CF9EF4972FDE568AE4CB0@AM6PR03MB5170.eurprd03.prod.outlook.com/) I mean - I guess that kinda works? It'll mean that attaching to a task with "strace" as root won't work reliably if the task is in the middle of execve though, there'll be a weird race where if strace first attaches to a sibling and then tries to attach to the thread going through execve(), it'll fail to attach to that thread, and then lose the process entirely once de_thread() has killed off the other threads. My perfectionist side is somewhat irked by that. Still, it's probably far better than Linus' "simpler change" where the target just gets killed off if someone tries to trace it at the wrong time.