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=-3.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, USER_AGENT_NEOMUTT autolearn=ham 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 DB225C43387 for ; Thu, 17 Jan 2019 22:46:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9809520859 for ; Thu, 17 Jan 2019 22:46:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=brauner.io header.i=@brauner.io header.b="AJbg3yeE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726896AbfAQWqa (ORCPT ); Thu, 17 Jan 2019 17:46:30 -0500 Received: from mail-wr1-f46.google.com ([209.85.221.46]:44187 "EHLO mail-wr1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726782AbfAQWq3 (ORCPT ); Thu, 17 Jan 2019 17:46:29 -0500 Received: by mail-wr1-f46.google.com with SMTP id z5so12824740wrt.11 for ; Thu, 17 Jan 2019 14:46:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=MwuqbQMQjl6n10Bv2yR+IqF+HIVNFslr4AU1dzaGUno=; b=AJbg3yeEhOxptJuwHdxqa/FI7yhE3N3Q2YCcsNKDgHdqltLM8vvQscl3gCKcshOWsK yii6qWqy7q5aPMRGrRwZIf03qFRA+rX+bhiWJCDGidolzL/2fMbVjBv2dUQSHWPYJcl0 j3eEtOY6HIB/fajIq1OOZmKIDEZK0OFZSKuv/XVTCv82kH62kTNdtqbtfWO2g0qeQRh2 xgJtytks3OG9LuDkX9wc1oNyzKyXFUmxehumPpL9X2ilOR1q2Qt0iez7f6MvLgaO2chI vPef3+ZtFA6AyvIXA761y4uPLBVEsOOdE2lqv3+YMFF10LCf9hc3G5RgJRTOnaVrJqAR 9yYQ== 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:in-reply-to:user-agent; bh=MwuqbQMQjl6n10Bv2yR+IqF+HIVNFslr4AU1dzaGUno=; b=mlZfwqDdU8SGsp8fMFiVPn1fhGoSls52ehsFfjv6vOjHbSjATRA9AI4gHaDDsmq3OD oHpdGJhJGxNm0tJZ49dvqXj92aeg7EipP2FZ4KxXc6b+zTq+7SBGtxB2a1UH2G/vnbi5 TSXX2VsqGu8U3nimJQslkMMn2lR6hgbPlIsb6wuKESRhi+r7SuCpaS2exrzLf02j2dOC aihTxzCXb8xo3oRkpF3CKyjzWjbjDEJHkCBfUuQ2bOMf4rryfDbQn7wQAmKBgATuIBKY 88prUxZsasSn1SmyVPA9+oskuyJ2UhYH2jFaS+HOb1SbGtWwkTyaSH1SvwtkQcp4VAqZ Kbng== X-Gm-Message-State: AJcUukdMYCHmtmyWS2wGOPLaaqsaCMdvoUE2n7Y2dV++6xXExv6yvV70 P42iF/J254uWSM13uIg+1lelEQ== X-Google-Smtp-Source: ALg8bN5o6J7RBFVqbHjpys+qzVZSgM/Cq0MqKMBwqQGdEWtsj7Q4O3Dehbfxkxx91cLHyJhuktNoMw== X-Received: by 2002:a05:6000:104b:: with SMTP id c11mr14083904wrx.303.1547765187119; Thu, 17 Jan 2019 14:46:27 -0800 (PST) Received: from brauner.io ([154.119.55.246]) by smtp.gmail.com with ESMTPSA id u204sm67530768wmu.30.2019.01.17.14.46.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Jan 2019 14:46:26 -0800 (PST) Date: Thu, 17 Jan 2019 23:46:21 +0100 From: Christian Brauner To: Al Viro Cc: Greg Kroah-Hartman , linux-fsdevel@vger.kernel.org Subject: Re: [heads-up] binderfs bugs galore... Message-ID: <20190117224620.pyja4vsqz2yl67wc@brauner.io> References: <20190117224011.GW2217@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190117224011.GW2217@ZenIV.linux.org.uk> User-Agent: NeoMutt/20180716 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Thu, Jan 17, 2019 at 10:40:11PM +0000, Al Viro wrote: Thanks for all the comments they seem really helpful. I'm currently travelling but I will try to address them all within the next week! Does that sound ok to you? Thanks! Christian > 1) d_make_root() does iput() on failure. IOW, if you hit that case, > you get double iput() in err_without_dentry. > > 2) final dput() does iput() (unsurprisingly). IOW, anyone hitting > err_with_dentry will get double iput() as well. > > 3) iput(NULL) is (fortunately) a no-op. And that is the only case > when iput() in there does not cause immediate trouble. > > 4) failure in binderfs_fill_super() leads to a call of > deactivate_locked_super(). Which calls binderfs_kill_super(), > which does put_ipc_ns(info->ipc_ns). IOW, > put_ipc_ns(ipc_ns); > in failure exits of binderfs_fill_super() is also a double-put... > > 5) ... if, that is, the memory that used to hold sb->s_fs_info > until the same failure exit has kfreed it has already been stomped onto, > in which case you get put_ipc_ns() done on arbitrary address that might've > never held a struct ipc_namespace instance. > > What I really don't get here is why do you go to such contortions > in the first place. Every single thing done in err_without_dentry is wrong. > And the only thing done in err_with_dentry before it hits err_without_dentry > is pointless; deactivate_locked_super() will do that dput() just fine. > Whereas the simple return ret; (or return -ENOMEM in most of the cases) > would've worked correctly... > > Actually, looking at that a bit more, > 6) initially you have ->s_fs_info contain a pointer to > struct ipc_namespace. Then binderfs_fill_super() tries to allocate > a struct binderfs_info instance and stick *that* in place of > ->s_fs_info, moving the original value into info->ipc_ns. That's > Not Nice(tm) towards the poor binderfs_kill_super(), which has no > fscking way to tell which kind of pointer is it going to find > there. As it is, it assumes that replacement has been done and > drops ->ipc_ns it finds in there. Guess what happens if you > fail on attempt to allocate struct binderfs_info in the first > place? > > 7) binderfs_test_super() also assumes that all superblocks it > is asked to look at will have ->s_fs_info pointing to struct binderfs_info. > binderfs_set_super(), OTOH, sets it to struct ipc_namespace pointer it > (ultimately - sget_userns()) has been passed as 'data'. So if two mounts > race, you'll get a false negative out of binderfs_test_super(). > > 8) binderfs_binder_ctl_create() is a no-op on subsequent > calls (if there had been any). And the first call is done before > we unlock the superblock, so locking the root is completely pointless. > > 9) the one thing ->s_fs_info can't be in the whole thing is NULL. > There are two assignments - one in binderfs_set_super(), where we set > it to the last argument of sget_userns() and another in binderfs_fill_super() > where we set it to 'info'. In both cases we have that pointer dereferenced > a little bit earlier - while evaluating the next-to-last argument of the > same sget_userns() call or in setting info->root_uid in the other place. > Both would've obviously oopsed before storing NULL there. IOW, checking > whether it's NULL is pointless both in binderfs_test_super() and in > binderfs_kill_super(). > > 10) your ->unlink() checks if the victim is ->control_dentry. > Your ->rename(), OTOH, does not, which renders the check in ->unlink() > trivial to bypass. > > 11) speaking of the tests that are there in ->rename(), > /* binderfs doesn't support directories. */ > if (d_is_dir(old_dentry)) > return -EPERM; > is... interesting. If the comment is correct, the check is pointless. > And AFAICS the comment *is* correct... Another check in there > if (!simple_empty(new_dentry)) > return -ENOTEMPTY; > is equally pointless, for the same reason... > > 12) what is the comment in binderfs_unlink() supposed to mean? > In ->unlink() we *already* have parent locked...