Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5775092ybl; Tue, 10 Dec 2019 11:16:05 -0800 (PST) X-Google-Smtp-Source: APXvYqySu3PjAVgRaboNw29nVhQHw2PbGn25Vl76UOUSBSao9XJtpZb4Jg28oem4acjD5Hp9zzsW X-Received: by 2002:aca:4785:: with SMTP id u127mr383044oia.94.1576005364867; Tue, 10 Dec 2019 11:16:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576005364; cv=none; d=google.com; s=arc-20160816; b=LLR8IX2Wkd23NvuDChLwIztOMK6JwI1x9xcRgGcOT96XqFQqsNBH0kn+oT5GD+XWmL jyueXT+rLB+yL/75n+NYm8WgrssRIPyFn1FHRGIu9F2SUGooQa0KkuVAIPKH1YqxWh7M m3l6GmpqWFFX0bF4MWDMU+pF9Ukbjj8/JttXhPs3b3EgrpGMZtHcGlp/qQLgJJqnmoII e2Ijj+hsB0jIekzheCaVrPBxcDTYTb5LkSY0wzcEn3gsbRZQyawqXQhuOUebYIunpUf2 5hq0XvczMhMoDjR+5cB/dD1S+DZA2tNEP3AXsuxLyOS2DHReS7g3BHuiakr54sWHXHYe zJnA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=sssnGQdUpsg/Eg1loSN8PmVozGuxKM7BIKdE0y+0xdU=; b=RSUwWrtjvU69Ymd6/FLjZF2asTW7WvpgHHTm8/9fNoj/4hrHgPfAQ65lV2bugkIoQu uK/6TUv6CnOcz+w9sioA2Q3WyLlfiZ4XHiCv1HsgEbn+ywXSy/HWS62d4A/o/K5nJNht m4r9CakgdqMV050GAm4HWKC5Qq5CPJ6zBs4Lr/Id5DA/pZ3zswdUPfDTWLF5p3nsy4iA UUcrELOWU+X+j/hgfBvdxGVVfmxm5+9RMFV7Yq1DVl0hIyj+lCHTFVyE+N9XQbm/8UaV ZSCSc2OAfkzDEv+vooGUbPGj4wayhVrvzr6dmlBYcNX5/2CsHSDbjSKTmXH/r9ZKYn6y ivzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jaoT3lzg; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1si2396539otr.45.2019.12.10.11.15.51; Tue, 10 Dec 2019 11:16:04 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=jaoT3lzg; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727716AbfLJTPB (ORCPT + 99 others); Tue, 10 Dec 2019 14:15:01 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:42365 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727374AbfLJTPB (ORCPT ); Tue, 10 Dec 2019 14:15:01 -0500 Received: by mail-lf1-f65.google.com with SMTP id y19so14600972lfl.9; Tue, 10 Dec 2019 11:15:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=sssnGQdUpsg/Eg1loSN8PmVozGuxKM7BIKdE0y+0xdU=; b=jaoT3lzgDn3ui+a04zf/2bTSL01qab+Ewy7BoghxrMCkeGna0nBVvcrKzV47DEpkLQ 3Opg/5o+YaKdtLKAie2mVqDILwnUuwT3fb7v3AP/p81Wo9FXplapvF5w9DJMxil3Otnw q3Ef57fojlyn3fO4dBYyYqL7dukVW1KQwtoRAXlgNOgMHceMGbiNAgMjHdFmQy582D0f D1VnQvxGFgkNdBKYKpIw/rC23AHRfyNmwweVlRhLzN5Ic+eqViUkKttEb8/RqBEAZ5hY CgHaUonikmLReKub6qcDhd9lvNlzdsH7gdbvCVSMDnH3uD48aoLpqzBHOGO4z+W5oZLQ oDLA== 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:content-transfer-encoding; bh=sssnGQdUpsg/Eg1loSN8PmVozGuxKM7BIKdE0y+0xdU=; b=ScSoEgWq9g+/lIc4Q6XAJ0xpUdarsijryB8wkZkYQkHUUpADdrpZP8tHdKlfOHkfqf bRXm9g4Kl4DpGh94wEKhSOv3Q4Mi4zfFz1MMSGHieWsxSTnLKtCS4aAFnTBrvSUV1xgH XVBJ3DYi6GCEshs3su2F9CdsuuINicEzoFJPolGxVcsb3f2SszY2gZnOOpjeEUQZ1t8M jRHhymzdY54IzwvO/griv8Kb8i17kevAUNNJPqhWozZGC+5U1LfrZ29OEeOB6M7x/mbg gBHT2HY0K8/k2xNUpeJdXgEJDyLuvbedEJ1Pwxyr1TJ3ERINKu2h5CoYu2oHmWCrhbIP L1WA== X-Gm-Message-State: APjAAAW22RIgnZjCoIvaVXTgVLqEhvB062IU3w0MiGibyty3YxrlGjD+ 7wYmVix0CLyDa+zICVfY4LcgfbW7+nnlIS/GtJUAUMY= X-Received: by 2002:ac2:57cc:: with SMTP id k12mr6119304lfo.36.1576005299289; Tue, 10 Dec 2019 11:14:59 -0800 (PST) MIME-Version: 1.0 References: <20190829050237.GA5161@jagdpanzerIV> <20190921223847.GB29065@ZenIV.linux.org.uk> <20191209003413.GY4203@ZenIV.linux.org.uk> In-Reply-To: <20191209003413.GY4203@ZenIV.linux.org.uk> From: Pavel Shilovsky Date: Tue, 10 Dec 2019 11:14:48 -0800 Message-ID: Subject: Re: build_path_from_dentry_optional_prefix() may schedule from invalid context To: Al Viro Cc: Sergey Senozhatsky , Steve French , Ronnie Sahlberg , linux-cifs , Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org =D0=B2=D1=81, 8 =D0=B4=D0=B5=D0=BA. 2019 =D0=B3. =D0=B2 16:34, Al Viro : > > On Mon, Sep 30, 2019 at 10:32:16AM -0700, Pavel Shilovsky wrote: > > =D1=81=D0=B1, 21 =D1=81=D0=B5=D0=BD=D1=82. 2019 =D0=B3. =D0=B2 15:38, A= l Viro : > > > > IOW, kindly lose that nonsense. More importantly, why bother > > > with that kmalloc()? Just __getname() in the very beginning > > > and __putname() on failure (and for freeing the result afterwards). > > > > > > What's more, you are open-coding dentry_path_raw(), badly. > > > The only differences are > > > * use of dirsep instead of '/' and > > > * a prefix slapped in the beginning. > > > > > > I'm fairly sure that > > > char *buf =3D __getname(); > > > char *s; > > > > > > *to_free =3D NULL; > > > if (unlikely(!buf)) > > > return NULL; > > > > > > s =3D dentry_path_raw(dentry, buf, PATH_MAX); > > > if (IS_ERR(s) || s < buf + prefix_len) > > > __putname(buf); > > > return NULL; // assuming that you don't care about de= tails > > > } > > > > > > if (dirsep !=3D '/') { > > > char *p =3D s; > > > while ((p =3D strchr(p, '/')) !=3D NULL) > > > *p++ =3D dirsep; > > > } > > > > > > s -=3D prefix_len; > > > memcpy(s, prefix, prefix_len); > > > > > > *to_free =3D buf; > > > return s; > > > > > > would end up being faster, not to mention much easier to understand. > > > With the caller expected to pass &to_free among the arguments and > > > __putname() it once it's done. > > > > > > Or just do __getname() in the caller and pass it to the function - > > > in that case freeing (in all cases) would be up to the caller. > > > > Thanks for pointing this out. Someone should look at this closely and > > clean it up. > > Could you take a look through vfs.git#misc.cifs? Looks good. I would only add the same or a similar comment as fs/hostfs/hostfs_kern.c has when calling dentry_path_raw(): /* * This function relies on the fact that dentry_path_raw() will place * the path name at the end of the provided buffer. */ Otherwise it is not straightforward at the first glance how the code works. Acked-by: Pavel Shilovsky -- Best regards, Pavel Shilovsky