Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4466812pxf; Tue, 16 Mar 2021 14:24:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykIglUFBbwDCJa0Nz/DuGpZs77P2ZYVotgFfnVmqT/71Nbac08AiEDLuBcuk7KwcuG8o2G X-Received: by 2002:a17:906:25c4:: with SMTP id n4mr32257829ejb.359.1615929869808; Tue, 16 Mar 2021 14:24:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615929869; cv=none; d=google.com; s=arc-20160816; b=V/Lku9r3WD5FBcCTpYP6L/BtBnlv2LmPshdom3sdyBUW4IryQTX03Sc5QWZSYs0wzK d5RRFatParl2+iajdbhYETpsC1XaTkY0I3YizbOoHIhvYX9/iCFLzB8rYokoi/F9cq+K pmpbrtIQRO0F2bVo2CmoXVDZam78PBdUJfvMRixjqY4iiTCHGw9gRRRj7HxIF4Sa/MQk 7RVLfX4wfsOabQZpv8WRkc/pl8hdNRK+iLnFkrEhdXQkRg9M3Dv1j59TaYREhdglkA4y Z2yxuY/2K8hu7K6Swlz6igTjuFH2R8gGH2utaHXHe45PAc/JwJkULayBVN9wqMTE3m2q nEIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=a1ue4t11OJbVivGpc6C3VCzhlUkhH8Mj6uX3JQk/WHc=; b=zOHxf7WadfTtH+C0Wz/ejc+mbCPk98o/yeZWIybMAfkjkD7Mqz9xH9XalQidHVoUID jpj8jut9PLyGz+Tby1K11f/WyLKc7sZGk7bdgIAbZN5e7UYI89Sf0G9jCiPMesiGEgtx 3pYvMqNDh2ak55dJFsx1rJlfWYDhlF5YQLBU4D97JtufPym2E1GRiVxxD0Xp1EhYP7d/ HyqF+9AxWNlkpYp7jkues5O6l60uwb5GLGZL7/7SzFp2RiKRIOVsdyFquSJmfD45ZOHB 763VDFbZLZzgp7kF117mXoWNRXQ9RB/TkUzu4f5gEXb5TXIy9fqyK3TYVVZzTFEreUiF pjcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Nj8yYDlu; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ks7si14599429ejb.682.2021.03.16.14.24.06; Tue, 16 Mar 2021 14:24:29 -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=@chromium.org header.s=google header.b=Nj8yYDlu; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240374AbhCPTY6 (ORCPT + 99 others); Tue, 16 Mar 2021 15:24:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240397AbhCPTYV (ORCPT ); Tue, 16 Mar 2021 15:24:21 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7AFDC061756 for ; Tue, 16 Mar 2021 12:24:09 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id s7so17422451plg.5 for ; Tue, 16 Mar 2021 12:24:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=a1ue4t11OJbVivGpc6C3VCzhlUkhH8Mj6uX3JQk/WHc=; b=Nj8yYDluxqiAG+ej6jhoWTmPa96bXO9MvDia/puQbLS7/lpPxALfueZIRNjkZiCYCy Ljgk8A2MGIt5sqxHhcmGFj9bwRx66ATTPVkIOCfXJarh9XeLaTErjE/lVX2YPbMfkUTR weLoWOS0x3zLp07rZcrp0BhN98BIhcxt1Cq+U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=a1ue4t11OJbVivGpc6C3VCzhlUkhH8Mj6uX3JQk/WHc=; b=Z/bqBX0VUEHxUd8DekmtQK7LE3vmsFCO04fl5AnZMp2IncqP5gEUGLsb6LnVdjKYv5 bl4G1iB5rxuKch+bEtIsT78+R36zqmuULVqg95rGqtiPHFpahQP7hUFZCVPiVR6uH/Zw Ja0UE5ptMaq92UKwXj/m15AfiCFv0bD3OypF7wP1HSZrCEFAcHQydEK5yd9hute0L2SU tUfU9pUUSnBo8swMeQl91sWLWkkBEA8RDQKj4vUeQK5+6O66O/Fhl2YcuNTLGuK/omit JkDE71H4JaP2zRNWfWKSreIa2+bHDYYXSd8R62OWtJ7a7JTTka2P913pgL0cE2+REtcI LC8w== X-Gm-Message-State: AOAM533syNtGLf8klEf0XzffBH/OTooJ2HN2D4kxpAl7Kabzx25W7Olg NhYuKhd+1dfAvFLJA3lkG/0ssQ== X-Received: by 2002:a17:90a:b115:: with SMTP id z21mr594754pjq.162.1615922649291; Tue, 16 Mar 2021 12:24:09 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e1sm191065pjt.10.2021.03.16.12.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Mar 2021 12:24:08 -0700 (PDT) Date: Tue, 16 Mar 2021 12:24:07 -0700 From: Kees Cook To: Jann Horn Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Al Viro , James Morris , Serge Hallyn , Andy Lutomirski , Casey Schaufler , Christian Brauner , Christoph Hellwig , David Howells , Dominik Brodowski , "Eric W . Biederman" , John Johansen , Kentaro Takeda , Tetsuo Handa , Kernel Hardening , linux-fsdevel , kernel list , linux-security-module , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Subject: Re: [PATCH v4 1/1] fs: Allow no_new_privs tasks to call chroot(2) Message-ID: <202103161221.8291CC3E6@keescook> References: <20210316170135.226381-1-mic@digikod.net> <20210316170135.226381-2-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 16, 2021 at 08:04:09PM +0100, Jann Horn wrote: > On Tue, Mar 16, 2021 at 6:02 PM Micka?l Sala?n wrote: > > One could argue that chroot(2) is useless without a properly populated > > root hierarchy (i.e. without /dev and /proc). However, there are > > multiple use cases that don't require the chrooting process to create > > file hierarchies with special files nor mount points, e.g.: > > * A process sandboxing itself, once all its libraries are loaded, may > > not need files other than regular files, or even no file at all. > > * Some pre-populated root hierarchies could be used to chroot into, > > provided for instance by development environments or tailored > > distributions. > > * Processes executed in a chroot may not require access to these special > > files (e.g. with minimal runtimes, or by emulating some special files > > with a LD_PRELOADed library or seccomp). > > > > Unprivileged chroot is especially interesting for userspace developers > > wishing to harden their applications. For instance, chroot(2) and Yama > > enable to build a capability-based security (i.e. remove filesystem > > ambient accesses) by calling chroot/chdir with an empty directory and > > accessing data through dedicated file descriptors obtained with > > openat2(2) and RESOLVE_BENEATH/RESOLVE_IN_ROOT/RESOLVE_NO_MAGICLINKS. > > I don't entirely understand. Are you writing this with the assumption > that a future change will make it possible to set these RESOLVE flags > process-wide, or something like that? I thought it meant "open all out-of-chroot dirs as fds using RESOLVE_... flags then chroot". As in, there's no way to then escape "up" for the old opens, and the new opens stay in the chroot. > [...] > > diff --git a/fs/open.c b/fs/open.c > [...] > > +static inline int current_chroot_allowed(void) > > +{ > > + /* > > + * Changing the root directory for the calling task (and its future > > + * children) requires that this task has CAP_SYS_CHROOT in its > > + * namespace, or be running with no_new_privs and not sharing its > > + * fs_struct and not escaping its current root (cf. create_user_ns()). > > + * As for seccomp, checking no_new_privs avoids scenarios where > > + * unprivileged tasks can affect the behavior of privileged children. > > + */ > > + if (task_no_new_privs(current) && current->fs->users == 1 && > > this read of current->fs->users should be using READ_ONCE() Ah yeah, good call. I should remember this when I think "can this race?" :P -- Kees Cook