Message ID | 20230131155559.35800-1-chao@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2833995wrn; Tue, 31 Jan 2023 08:03:55 -0800 (PST) X-Google-Smtp-Source: AK7set9obe9ZpcMPjjuiseK1v2uQV9S/KcktXsFxD90ha31fKoWetLjKCuj/l5++DjZtdRgrKycN X-Received: by 2002:a17:906:c18d:b0:887:4c52:bfb5 with SMTP id g13-20020a170906c18d00b008874c52bfb5mr9557805ejz.70.1675181035801; Tue, 31 Jan 2023 08:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675181035; cv=none; d=google.com; s=arc-20160816; b=oPzobg8RgRDPBbiDwt+Z7FUyfgs1r9Fk2OE2ofVx+ff0eVd0GP5NWdG3U4u6NVnPvG 4KSS2IVkJ5+nMWrxgO3aQ4mA+ZkqKrebLYc974MPXs8tQ3nwV1uN3bxKByb9tAnqvekI E63/QfmdRghLrSa7tKoUkmS1vFcO9aLb/5JuNIf/czrqriPLpl395+4o6rFHFNQPH+nb h3xOVXmJPihZcbbu9P/DrkrQrVh19E0VQlY8hEaMWRO7UENgy1lj3anEkJ/+I169XauI gslNzd3kx9yDMTuWhuqq9dRLWVT9t234B1BqFuoTXqmZIcv2iNMdAoBKDh3zPuh24lSV Okxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=oK9tnBRle3ypGdEQ4VoAQD6TolgGO8nnElDzrdGn6A8=; b=ymaJAaRtzzjp5SxKI3T55uidEGfxf6VA0MAs5BTsuqDtA3FhHKMtnf+IOo9vaM6Dp9 Gw6B00S2snYuCv57qJXzZwrwcgnBudfMM+5i0KsYJ4fxXvuDjxrnkVSFjc3Me7oSOm88 olpRPLuU1OfRD7/IrL1VSs1MXVVH1hH2/DlXP2MYbeKOCli8nvvC0b9rACYX5AeeVyie Z6BE4ETyvJHUhdQthr2LSAw6gEfcZ6bAK829Jsx8OI9mf7pdv+JO1PGSeHqybIiDQ4X6 hhEutDX9M8Lc+KQUviUiiVhATRH4ZFn5q2Qr6gYhV1qDP0Por+SOtYxHI8aPFOwLp1P+ x3kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D0G7i5l+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ss2-20020a170907c00200b00877db5bfb4csi21577348ejc.670.2023.01.31.08.03.09; Tue, 31 Jan 2023 08:03:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D0G7i5l+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232562AbjAaP4O (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Tue, 31 Jan 2023 10:56:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232199AbjAaP4M (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 31 Jan 2023 10:56:12 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 657FA17154; Tue, 31 Jan 2023 07:56:11 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0331B6158D; Tue, 31 Jan 2023 15:56:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79A9BC433D2; Tue, 31 Jan 2023 15:56:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675180570; bh=FDlHK/H4Jh89Tca25M42ibJ74C6dgzbMwkQIcxTDWhE=; h=From:To:Cc:Subject:Date:From; b=D0G7i5l+vHCPeJhaI7CisXTHBWimO9WD5x6Jx9RQKfhtjpD11MBk49H+Q9dib9Wnm ehvasr+/pg88d2zULRByTanGWs4ymgOkECrEVuNgW1EoaFoyd6v45ikDohdGoodlvf yOzQAisSW+ZnL5Py7DZ9SV1ISXOxorcCper207AKwMFnH+yxeg69rdoRybErEUZ6du LDmGxdGzDI6ZdbhDs+QiWIq14DtjVPdiUleUvIRQaAM8Csw+kWRg3NTR2fdvyWXMMI 6kQaMGZ68qjWnsVaJzZ2suNNmWxSvK4BU2uKT0HKMyFzLNJAcuVDyKqWmZp3sUgGkX o1GWTMPG/9L1w== From: Chao Yu <chao@kernel.org> To: akpm@linux-foundation.org, adobriyan@gmail.com Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Chao Yu <chao@kernel.org> Subject: [PATCH 1/2] proc: fix to check name length in proc_lookup_de() Date: Tue, 31 Jan 2023 23:55:58 +0800 Message-Id: <20230131155559.35800-1-chao@kernel.org> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756554629987987889?= X-GMAIL-MSGID: =?utf-8?q?1756554629987987889?= |
Series |
[1/2] proc: fix to check name length in proc_lookup_de()
|
|
Commit Message
Chao Yu
Jan. 31, 2023, 3:55 p.m. UTC
__proc_create() has limited dirent's max name length with 255, let's
add this limitation in proc_lookup_de(), so that it can return
-ENAMETOOLONG correctly instead of -ENOENT when stating a file which
has out-of-range name length.
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/proc/generic.c | 5 ++++-
fs/proc/internal.h | 3 +++
2 files changed, 7 insertions(+), 1 deletion(-)
Comments
Hi Andrew, Could you please take a look at this patchset? Or should I ping Alexey Dobriyan? Thanks, On 2023/1/31 23:55, Chao Yu wrote: > __proc_create() has limited dirent's max name length with 255, let's > add this limitation in proc_lookup_de(), so that it can return > -ENAMETOOLONG correctly instead of -ENOENT when stating a file which > has out-of-range name length. > > Signed-off-by: Chao Yu <chao@kernel.org> > --- > fs/proc/generic.c | 5 ++++- > fs/proc/internal.h | 3 +++ > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/fs/proc/generic.c b/fs/proc/generic.c > index 878d7c6db919..f547e9593a77 100644 > --- a/fs/proc/generic.c > +++ b/fs/proc/generic.c > @@ -245,6 +245,9 @@ struct dentry *proc_lookup_de(struct inode *dir, struct dentry *dentry, > { > struct inode *inode; > > + if (dentry->d_name.len > PROC_NAME_LEN) > + return ERR_PTR(-ENAMETOOLONG); > + > read_lock(&proc_subdir_lock); > de = pde_subdir_find(de, dentry->d_name.name, dentry->d_name.len); > if (de) { > @@ -401,7 +404,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, > goto out; > qstr.name = fn; > qstr.len = strlen(fn); > - if (qstr.len == 0 || qstr.len >= 256) { > + if (qstr.len == 0 || qstr.len > PROC_NAME_LEN) { > WARN(1, "name len %u\n", qstr.len); > return NULL; > } > diff --git a/fs/proc/internal.h b/fs/proc/internal.h > index b701d0207edf..7611bc684d9e 100644 > --- a/fs/proc/internal.h > +++ b/fs/proc/internal.h > @@ -142,6 +142,9 @@ unsigned name_to_int(const struct qstr *qstr); > /* Worst case buffer size needed for holding an integer. */ > #define PROC_NUMBUF 13 > > +/* Max name length of procfs dirent */ > +#define PROC_NAME_LEN 255 > + > /* > * array.c > */
On Wed, 1 Feb 2023 21:01:14 +0800 Chao Yu <chao@kernel.org> wrote: > Hi Andrew, > > Could you please take a look at this patchset? Or should I ping > Alexey Dobriyan? > [patch 1/2]: Alexey wasn't keen on the v1 patch. What changed? [patch 2/2]: What is the benefit from this change?
On Thu, Feb 02, 2023 at 03:41:54PM -0800, Andrew Morton wrote: > On Wed, 1 Feb 2023 21:01:14 +0800 Chao Yu <chao@kernel.org> wrote: > > > Hi Andrew, > > > > Could you please take a look at this patchset? Or should I ping > > Alexey Dobriyan? > > > > [patch 1/2]: Alexey wasn't keen on the v1 patch. What changed? Nothing! /proc lived without this check for 30 years: int proc_match(int len,const char * name,struct proc_dir_entry * de) { register int same __asm__("ax"); if (!de || !de->low_ino) return 0; /* "" means "." ---> so paths like "/usr/lib//libc.a" work */ if (!len && (de->name[0]=='.') && (de->name[1]=='\0')) return 1; if (de->namelen != len) return 0; __asm__("cld\n\t" "repe ; cmpsb\n\t" "setz %%al" :"=a" (same) :"0" (0),"S" ((long) name),"D" ((long) de->name),"c" (len) :"cx","di","si"); return same; }
On 2023/2/3 7:41, Andrew Morton wrote: > [patch 1/2]: Alexey wasn't keen on the v1 patch. What changed? I replied to Alexey's comments on v1, but still didn't get any feedback, so I just rebase the code to last -next. Sorry, too rush to missed to add change log on v2. > > [patch 2/2]: What is the benefit from this change? Block size is mismatch in between results of stat() and statfs(), this patch tries to fix this issue. stat /proc/ File: /proc/ Size: 0 Blocks: 0 IO Block: 1024 directory Device: 14h/20d Inode: 1 Links: 310 Access: (0555/dr-xr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2023-01-28 23:14:20.491937242 +0800 Modify: 2023-01-28 23:14:20.491937242 +0800 Change: 2023-01-28 23:14:20.491937242 +0800 Birth: - stat -f /proc/ File: "/proc/" ID: 0 Namelen: 255 Type: proc Block size: 4096 Fundamental block size: 4096 Blocks: Total: 0 Free: 0 Available: 0 Inodes: Total: 0 Free: 0
On 2023/2/5 20:21, Alexey Dobriyan wrote: > Nothing! /proc lived without this check for 30 years: Oh, I'm trying make error handling logic of proc's lookup() to be the same as other generic filesystem, it looks you don't think it's worth or necessary to do that, anyway, the change is not critial, let's ignore it, thank you for reviewing this patch. Thanks, > > int proc_match(int len,const char * name,struct proc_dir_entry * de) > { > register int same __asm__("ax"); > > if (!de || !de->low_ino) > return 0; > /* "" means "." ---> so paths like "/usr/lib//libc.a" work */ > if (!len && (de->name[0]=='.') && (de->name[1]=='\0')) > return 1; > if (de->namelen != len) > return 0; > __asm__("cld\n\t" > "repe ; cmpsb\n\t" > "setz %%al" > :"=a" (same) > :"0" (0),"S" ((long) name),"D" ((long) de->name),"c" (len) > :"cx","di","si"); > return same; > }
diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 878d7c6db919..f547e9593a77 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -245,6 +245,9 @@ struct dentry *proc_lookup_de(struct inode *dir, struct dentry *dentry, { struct inode *inode; + if (dentry->d_name.len > PROC_NAME_LEN) + return ERR_PTR(-ENAMETOOLONG); + read_lock(&proc_subdir_lock); de = pde_subdir_find(de, dentry->d_name.name, dentry->d_name.len); if (de) { @@ -401,7 +404,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, goto out; qstr.name = fn; qstr.len = strlen(fn); - if (qstr.len == 0 || qstr.len >= 256) { + if (qstr.len == 0 || qstr.len > PROC_NAME_LEN) { WARN(1, "name len %u\n", qstr.len); return NULL; } diff --git a/fs/proc/internal.h b/fs/proc/internal.h index b701d0207edf..7611bc684d9e 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -142,6 +142,9 @@ unsigned name_to_int(const struct qstr *qstr); /* Worst case buffer size needed for holding an integer. */ #define PROC_NUMBUF 13 +/* Max name length of procfs dirent */ +#define PROC_NAME_LEN 255 + /* * array.c */