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 X-Spam-Level: X-Spam-Status: No, score=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02034C00A89 for ; Fri, 30 Oct 2020 19:24:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 816ED206E3 for ; Fri, 30 Oct 2020 19:24:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NKzAXeWR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727318AbgJ3TWw (ORCPT ); Fri, 30 Oct 2020 15:22:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727582AbgJ3TUw (ORCPT ); Fri, 30 Oct 2020 15:20:52 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BF99C0613D2 for ; Fri, 30 Oct 2020 12:20:52 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id a9so9279451lfc.7 for ; Fri, 30 Oct 2020 12:20:52 -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=7ltXFGIEC1wD1/DcBqIE9Zp9UpD0Eob4weHsly+LU6s=; b=NKzAXeWRhEzSsyPxWy8lABW/VB/K7yCL712Wgf/ZLf7MLh2aHZKNViiJYIbi5Z9IUk 0D2VbKnfwvyD2QdfVIYU+1lfoDbLp2UF9hubMPUnOM8plYKIesS4Jd32XnljUf+5Wr21 fZ+UR9thk5kKUDBVcXk7E/KewhR4XtulAfljMrcCfiNYGTQrDJ4EF1AvjbDZkzjilzB1 1k4tGbZ6wS/da8Gqb6S3LJWsxLFX5rCei0jdonnPR7zzIioIklmXmIkKlgBZLR+ERq9I TtV6o7qnXxRlP9zqMwKYrd9GYW6Mnx069+xDdw7tkMGQAZ/IdoP9rZYBB5nLy51sfqsR 3SeQ== 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=7ltXFGIEC1wD1/DcBqIE9Zp9UpD0Eob4weHsly+LU6s=; b=UG3eRpj/iUO6tQhoN07d6lu/JX/4kkKaWqYWJkvjLQSIZRIPWaC4Cx5bw5mt2ZQ4dR l4cBKwlJDbGLcbp0VouhA/bn8vMy8Dat+ZlMaTJc0ek2SX3DVA0UmPrXbkzMBr7We0PP ve5kFaTDwZE+01IORVubVTDnA0meOMnccuOHIzlN9IpPTbXjjTv0NowDOopnBKRPwlZt ajtER7nF/rz5G6gNoUBUXcGrAwCDeNl9//nDBeu7t3C4c1WpJFmOuYUJMRZqtJO+yGC1 6sDw7q8bqFmZ6zbIhPmi4uNbsl2YZTXUJuevbnSfgaPEx2KKij3LdW0lo3xyItgY9ylk pqww== X-Gm-Message-State: AOAM531C0oU58MTFSjv/mademQI5QBDBE6Snxb6M0SetshMB7z3Mv2tr 21teYqspK/g8/MN3fiWXvgYPPhAMxMLRnqY0EdZyZw== X-Google-Smtp-Source: ABdhPJzPd9Yn3eLEZ6vKKsiFecuFzporMourNqE58Gif0brpSLNfw6y269RW0/w1hGnLsri5OaWqZgnLzVxfJTsympg= X-Received: by 2002:a19:c357:: with SMTP id t84mr1432560lff.34.1604085650471; Fri, 30 Oct 2020 12:20:50 -0700 (PDT) MIME-Version: 1.0 References: <63598b4f-6ce3-5a11-4552-cdfe308f68e4@gmail.com> <93cfdc79-4c48-bceb-3620-4c63e9f4822e@gmail.com> In-Reply-To: <93cfdc79-4c48-bceb-3620-4c63e9f4822e@gmail.com> From: Jann Horn Date: Fri, 30 Oct 2020 20:20:24 +0100 Message-ID: Subject: Re: For review: seccomp_user_notif(2) manual page [v2] To: "Michael Kerrisk (man-pages)" Cc: Kees Cook , Tycho Andersen , Sargun Dhillon , Christian Brauner , Daniel Borkmann , Giuseppe Scrivano , Song Liu , Robert Sesek , Containers , linux-man , lkml , Aleksa Sarai , Alexei Starovoitov , Will Drewry , bpf , Andy Lutomirski Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-man@vger.kernel.org On Thu, Oct 29, 2020 at 8:14 PM Michael Kerrisk (man-pages) wrote: > On 10/29/20 2:42 AM, Jann Horn wrote: > > As discussed at > > , > > we need to re-check checkNotificationIdIsValid() after reading remote > > memory but before using the read value in any way. Otherwise, the > > syscall could in the meantime get interrupted by a signal handler, the > > signal handler could return, and then the function that performed the > > syscall could free() allocations or return (thereby freeing buffers on > > the stack). > > > > In essence, this pread() is (unavoidably) a potential use-after-free > > read; and to make that not have any security impact, we need to check > > whether UAF read occurred before using the read value. This should > > probably be called out elsewhere in the manpage, too... > > > > Now, of course, **reading** is the easy case. The difficult case is if > > we have to **write** to the remote process... because then we can't > > play games like that. If we write data to a freed pointer, we're > > screwed, that's it. (And for somewhat unrelated bonus fun, consider > > that /proc/$pid/mem is originally intended for process debugging, > > including installing breakpoints, and will therefore happily write > > over "readonly" private mappings, such as typical mappings of > > executable code.) > > > > So, uuuuh... I guess if anyone wants to actually write memory back to > > the target process, we'd better come up with some dedicated API for > > that, using an ioctl on the seccomp fd that magically freezes the > > target process inside the syscall while writing to its memory, or > > something like that? And until then, the manpage should have a big fat > > warning that writing to the target's memory is simply not possible > > (safely). > > Thank you for your very clear explanation! It turned out to be > trivially easy to demonstrate this issue with a slightly modified > version of my program. > > As well as the change to the code example that I already mentioned > my reply of a few hours ago, I've added the following text to the > page: > > Caveats regarding the use of /proc/[tid]/mem > The discussion above noted the need to use the > SECCOMP_IOCTL_NOTIF_ID_VALID ioctl(2) when opening the > /proc/[tid]/mem file of the target to avoid the possibility of > accessing the memory of the wrong process in the event that the > target terminates and its ID is recycled by another (unrelated) > thread. However, the use of this ioctl(2) operation is also > necessary in other situations, as explained in the following > pargraphs. (nit: paragraphs) > Consider the following scenario, where the supervisor tries to > read the pathname argument of a target's blocked mount(2) system > call: [...] > Seem okay? Yeah, sounds good. > By the way, is there any analogous kind of issue concerning > pidfd_getfd()? I'm thinking not, but I wonder if I've missed > something. When it is used by a seccomp supervisor, you mean? I think basically the same thing applies - when resource identifiers (such as memory addresses or file descriptors) are passed to a syscall, it generally has to be assumed that those identifiers may become invalid and be reused as soon as the syscall has returned.