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 */ From patchwork Tue Jan 31 15:55:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 50946 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2834362wrn; Tue, 31 Jan 2023 08:04:28 -0800 (PST) X-Google-Smtp-Source: AK7set9bOVcPocnA3ORFFtRLmpXKWwuMeNKE/QL1rWEs1gcZxJBXiZURqGvh22PeVgACN8ZrK0hh X-Received: by 2002:a17:907:78ce:b0:87b:d3dd:e0ca with SMTP id kv14-20020a17090778ce00b0087bd3dde0camr3507967ejc.26.1675181068030; Tue, 31 Jan 2023 08:04:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675181068; cv=none; d=google.com; s=arc-20160816; b=jBy1DNJD8v54Xv+dFlY6oFQ/90xaYZoTiTgsxMOWtjhQgf6H53VSCYLlRNCV0flMmx 9HXcMVjetoACwQv8HttWWhMSjvyInP8F00VRPhNDFmth863LW1YyfsoWEcEWMWTXFEu1 24g6dIFaAbiQAN2mpf5vPUt/rv9xfzWbhrUqlc6GoE984Xw8eBuXU5Gkux54HPo7rpPc WDRtGlKAd3JdQdXThgcZUxkuZo+NiRiUIcEuWkiXDcIULQnQXuOVOUDrTFojqbf6uee5 5wtV1cj/Eezp59RFcxnoW610nEMNrfJHkmcEpeD4DzjlioTbIUEn5mZiOgp7vMC/Ob1Q 50QQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5aDylVt5iIkRP+6m4TYrXFK5dxRfmuol7bt4BmuWIO8=; b=U2/amt5IbNaSdp6azwkq5Ni/0MPRy9TxzCOoAzST5kuHsB34NeY7W48NMn9t286KDa fl96S4cAA5h4ODRRlkiR32LvT0ggyY3uC70DVs9vunxDz1VKtfg0g5zU4K1sV9zEKVlX G5REhhOKLqfMo6Zy1vTQpI2usMEnCunv9Iyxb/2ypAp9+PgjI3cyAGW1hEyHMr/MAeMU p31hbVxsL9BxyoDXFFyUlFU+fC/0ZChAiJahY9cDLFPgQrczKOK6GMnd8OPr8Vqcqmkh 4ja4QPn/2sgsPibJjfMsJwgk9RVftOBSU07nV4UIZOOVzDKvm30JtG0DURLMEwPMCNnJ ijyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tPWYl3nI; 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 26-20020a17090601da00b0084d7c9a5e5esi19750370ejj.101.2023.01.31.08.03.48; Tue, 31 Jan 2023 08:04:28 -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=tPWYl3nI; 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 S233195AbjAaP4T (ORCPT + 99 others); Tue, 31 Jan 2023 10:56:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232384AbjAaP4O (ORCPT ); Tue, 31 Jan 2023 10:56:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60FDA17154; Tue, 31 Jan 2023 07:56:13 -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 F0B1061551; Tue, 31 Jan 2023 15:56:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E59B6C4339C; Tue, 31 Jan 2023 15:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675180572; bh=IcXc4uCVYnYjMccYdVFqtLssqj6bmugsjF7l8KDMQvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tPWYl3nIji/sBLzHAe/gJE26dnOHxgLscyV0BilJgs9cjTo863AuYpMem6rSCS7ix MIWlk5KncNGbAxhaLtKNU7lA6W0wbYGqxTbzbDWfo5KGZVr3rnW/B3+npjWMouJcg5 3iYQYWqq4OjLX6zDGD/SA8GUxJKZBogibcHETvaCY1uOaMDc5mKX01OXlqQB5EhUg7 eDWDHUAj9SODyG5r/urpi3JAHtpoMXET4l8XfCheuBsgw2ZJajZpi+jgVCjYTiZEZo BriA6Vz7cEDZiLpJmwo/daU7Tej5o9+fZwsQL/heSI2/jygk7QePD9Jp5+hmz2Yuls 2e/0O6pktWO/A== 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 2/2] proc: fix .s_blocksize and .s_blocksize_bits Date: Tue, 31 Jan 2023 23:55:59 +0800 Message-Id: <20230131155559.35800-2-chao@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20230131155559.35800-1-chao@kernel.org> References: <20230131155559.35800-1-chao@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1756554663534552346?= X-GMAIL-MSGID: =?utf-8?q?1756554663534552346?= procfs uses seq_file's operations to process IO, and seq_file uses PAGE_SIZE as basic operating unit, so, fix to update .s_blocksize and .s_blocksize_bits from 1024 and 10 to PAGE_SIZE and PAGE_SHIFT. Signed-off-by: Chao Yu --- v2: - fix to update blocksize to PAGE_SIZE pointed out by Alexey Dobriyan. fs/proc/root.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/proc/root.c b/fs/proc/root.c index 3c2ee3eb1138..8bf5a9080adc 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -173,8 +173,8 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc) /* User space would break if executables or devices appear on proc */ s->s_iflags |= SB_I_USERNS_VISIBLE | SB_I_NOEXEC | SB_I_NODEV; s->s_flags |= SB_NODIRATIME | SB_NOSUID | SB_NOEXEC; - s->s_blocksize = 1024; - s->s_blocksize_bits = 10; + s->s_blocksize = PAGE_SIZE; + s->s_blocksize_bits = PAGE_SHIFT; s->s_magic = PROC_SUPER_MAGIC; s->s_op = &proc_sops; s->s_time_gran = 1;