Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1550442pxx; Fri, 30 Oct 2020 12:40:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfDmDLEIfVVAhdNu0bMdQYjhRnQ1H+tmybFYa3+3AuVJk9oXVm4E0OytFOHe9OAC2mPVbf X-Received: by 2002:a17:906:4b0f:: with SMTP id y15mr3931907eju.198.1604086846340; Fri, 30 Oct 2020 12:40:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604086846; cv=none; d=google.com; s=arc-20160816; b=MRzwu/0YAspnpoXgszMnitf6NrphJW+UE9UfEpDkKlzf9ZDoBmBfBZnQYrJTzcNXpx 5qjktyRA1lc6FCti7eASvni7hwkSg4vQGShG8FGbpz4YxGdi6qEJHmegizcDAEa3ROia BQlvYTM+cBNo/Zez67B8qnkRoAIUL+a3CSBlRULxM5xFAzDiy8TFE9Eu1fK+Bxx8mIfZ ahFa/CLS7jwZ3ixuYEjQLrZEvJFWmBwHFLFeY1/wK+IIIkMO37A9BZLRx/hICTXiUJcn SOGNr5X3PJ8LiE52WtNEkE55pJQMI0oMKKl2wdjS3C55Izsc+APLd0CnXp3OSYTSIF4r fPOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7ltXFGIEC1wD1/DcBqIE9Zp9UpD0Eob4weHsly+LU6s=; b=WyvJ70hOMIipFV903ILtxHJpgK0cW+WwIa3ZEQBWCWGyZAe31wIhjNzKywGnp52dTc jKFuzDxTyh4QXGZpJzkHoeXWg4a5EgRRurUXRYziuDny9bDd3kutYOP4r1Es6SfX9j1i N/I+2L0bMlXxaLJp3yLHQJu3y3XgFOnCJ3yppY3RLRaXEyBvG/dFMuAu4N71lrzJoP/R 9l8Msf+eYDudDTyiHdCVHZ0OSdImDum10dDPw8cJiQix95PngF2Mo30y7U8vlMaG2kFP 1QKLTdPMx8pb1crwoeyVIsqD8WZvB5TQ0q11XQSq6Ty12RWPPrSgj8FrVdyV4sa+zzXk q1og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NKzAXeWR; 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 u8si5675769edy.179.2020.10.30.12.40.23; Fri, 30 Oct 2020 12:40:46 -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=NKzAXeWR; 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 S1727566AbgJ3TWx (ORCPT + 99 others); Fri, 30 Oct 2020 15:22:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727571AbgJ3TUw (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 4FC64C0613CF for ; Fri, 30 Oct 2020 12:20:52 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id a7so9242849lfk.9 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=iHFF5BpHGSVVB89MygCQgcLCxvAy3RGCxaB/bufM6J8eV+KF+J26Gcd4ZCRWoX/NOx TowLvryJMfPeyhBQrJPMvJ/fsrthaGhAQ/Q91+UHiqNBKlzCkLv+dViOPgrlIzTJRAQI RfVaKdUxtYI2NPc/ZZ1tfVXx9jA2awPgxKGs7Jf96mGjud9UnQUqr6yBI//l4j+BsIab /VVjRYNCwOKBxQZ9WN8yTRxrkqfBvrrba6clTWfz4a103mCcMCPdt/cWUgRFXkakQRRE RoH8vM8qBmeP8WtjemuFo6IPwdcpyQn9Z9beLe/rmxIeNTwAaPw07QduojlMZrog6187 lTng== X-Gm-Message-State: AOAM531OH2cyx4T+toDuAvlMkFhRhEpqxTud8ivX+pbYxkDR/s48y/KT 3+bR/aoKybnHj32sfrh0qDur9vT+Zx4sdqkLNc+sAQ== 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-kernel@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.