From patchwork Tue Jan 31 15:55:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 50945 Return-Path: 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 + 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 ); 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 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 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 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: 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?= __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 --- 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 */