Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4975903imm; Tue, 16 Oct 2018 03:14:30 -0700 (PDT) X-Google-Smtp-Source: ACcGV61+5oEWSsuaXhqYx948KgwuPP6oLG6sOQ/U+mUiYr7byOsmgM4M9hTkEE+Zrqw9Fx34DB2w X-Received: by 2002:a63:cc0b:: with SMTP id x11-v6mr19380814pgf.33.1539684870770; Tue, 16 Oct 2018 03:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539684870; cv=none; d=google.com; s=arc-20160816; b=S8yLpccBu4s1mbhh13nPbn2r0zcu5yR9a05NCDBCYH4YcM+undRwUP7E0rtawTWHss 86egSpHgL+vbKqvLzVQmMrBnIfw/36u2AoOwmeuxIGmrUPwY0BKRGcaL0uCp3vRvnkxy zNUYNw17QlnG/PY+59hjFLCX/bKuVv5A2h3XC3z1zWMB8khbnF+UvuuxUWNjVB3BzFUt LoZZm9+T+5KylHviWJYyvgufEM8X4lagwV3UjcR/RPrWWnxZZalU/TA7c5L+6y6i7WCT hwo+AXLkM6ZR5hPIxN/TK6uReOYQcUQXkzIrDYemO/65gNTEqEGnTSv+G/oa6pXG2ggj f8eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=7uNAYnPgtJw6+YBx+gk0ePVXOLp/I6yrYK+l3EJU2jI=; b=1G2gTLABQ2tkrz0SFmG0qO+MaMbt3VHndsm6ZX6g6tLWBC44sdEx8gdkr82hSf5Ohu +MEGV/SjoZP8WNjkt/LIOFITNmdSOq4i/Kn38G9j9YmdYP5tBQIgfGwH5holK7dyNp6R zaasSZWSHmKkAaWD65ieT+XbZxG4J/qYNBFgJqVJFpSL11/yoVjW3vicUe9YfGsza7R2 5yhiikEtg6FvtorWPn4eFk5iGk6SzYj/6dqMrXawI24Ha8lgjfL5DOt77K+YfXnzTTPN e1jPxnOFWWCWMdsbwZLvz9XVtGzqdo6jqddcAmggAuTirSX1zBdPwyrTd31IpmwSu/a1 JBqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=WXwdWzVH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11-v6si12497043pfn.212.2018.10.16.03.14.14; Tue, 16 Oct 2018 03:14:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=WXwdWzVH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726976AbeJPSDd (ORCPT + 99 others); Tue, 16 Oct 2018 14:03:33 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:44743 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726083AbeJPSDd (ORCPT ); Tue, 16 Oct 2018 14:03:33 -0400 Received: by mail-ed1-f66.google.com with SMTP id z21-v6so20714259edb.11 for ; Tue, 16 Oct 2018 03:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=7uNAYnPgtJw6+YBx+gk0ePVXOLp/I6yrYK+l3EJU2jI=; b=WXwdWzVHTGMCY4OXxsMyFnMLS9XkX5c0Gn+uXZwToIQLIygL6KW4tQkAYZRpfUXU4E ZtH9Voup2uDfcTjnx8ToO4esR/HdpDZ+fvG/ELfNuSiGVd98XpzyzPohqUN3FsKzNEB6 U7BNsoD7zxMEAJjDOGEkFiGocWInwsFwlJwYs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=7uNAYnPgtJw6+YBx+gk0ePVXOLp/I6yrYK+l3EJU2jI=; b=LErI+WTp3S9xuS4uJG/5U6vWcmyYQgC2UlID1ZX1cEAWnyd+G6wliRyr532hEDzXRS 3/OS5A6VhNE3OcU5ba0T163oPlk2uAOtzB5/TRJ2GUcR4DD8ZFSnYeGSA/WRBW5ZVuhl u7g07z2U8y7VEwu3UNZyD5LGqlgWXuhAeWQE7Va/i0rfyrmGmGYg4U0UbiDdMpGf5wBu sFNpS++GV+sTj75G+Zq+eklSHAxwcSN4MB0rxIe0Jmmi64AWtkqi5jSrmWbB6qdfnLCc dge3qTDJFjxjQPA9skun0HXFFjaqHC1qYpvB1IxUpQuUDx0f1NrHv6AVd8BseVydqb5J p33Q== X-Gm-Message-State: ABuFfogBpLlFZ4vvqCQHukd7RWQeQsaxaJ8AwFQl11J4snonpjwiA1uE oePRmfsGB3OzwL7MDFu1zjb5NaPVSTw= X-Received: by 2002:aa7:d3d4:: with SMTP id o20-v6mr29283648edr.193.1539684829534; Tue, 16 Oct 2018 03:13:49 -0700 (PDT) Received: from [172.26.255.55] ([193.47.71.171]) by smtp.gmail.com with ESMTPSA id r55-v6sm7780646edd.80.2018.10.16.03.13.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Oct 2018 03:13:49 -0700 (PDT) Subject: Re: [PATCH v6 1/1] ns: add binfmt_misc to the user namespace To: Laurent Vivier , linux-kernel@vger.kernel.org Cc: Jann Horn , James Bottomley , linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrei Vagin , Alexander Viro , Eric Biederman , containers@lists.linux-foundation.org, Dmitry Safonov References: <20181010161430.11633-1-laurent@vivier.eu> <20181010161430.11633-2-laurent@vivier.eu> From: Rasmus Villemoes Message-ID: <97280bb2-933e-9281-bd91-99748e1dd653@rasmusvillemoes.dk> Date: Tue, 16 Oct 2018 12:13:47 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181010161430.11633-2-laurent@vivier.eu> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-10-10 18:14, Laurent Vivier wrote: > + /* create a new binfmt namespace > + * if we are not in the first user namespace > + * but the binfmt namespace is the first one > + */ > + if (READ_ONCE(ns->binfmt_ns) == NULL) { > + struct binfmt_namespace *new_ns; > + > + new_ns = kmalloc(sizeof(struct binfmt_namespace), > + GFP_KERNEL); > + if (new_ns == NULL) > + return -ENOMEM; > + INIT_LIST_HEAD(&new_ns->entries); > + new_ns->enabled = 1; > + rwlock_init(&new_ns->entries_lock); > + new_ns->bm_mnt = NULL; > + new_ns->entry_count = 0; > + /* ensure new_ns is completely initialized before sharing it */ > + smp_wmb(); > + WRITE_ONCE(ns->binfmt_ns, new_ns); > + } If ns->binfmt_ns can really change under us (given you use READ_ONCE), what prevents two instances of this code running at the same time, in which case one of them would leak its new_ns instance? Also, there doesn't seem to be any smp_rmb() buddy to that wmb(), I don't think that's implied by READ_ONCE() in binfmt_ns(). Rasmus