From patchwork Wed Mar 23 23:05:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12790201 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 998D9C433F5 for ; Wed, 23 Mar 2022 23:05:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F5D16B0073; Wed, 23 Mar 2022 19:05:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A52E6B0074; Wed, 23 Mar 2022 19:05:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11F406B0075; Wed, 23 Mar 2022 19:05:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0202.hostedemail.com [216.40.44.202]) by kanga.kvack.org (Postfix) with ESMTP id 02D546B0073 for ; Wed, 23 Mar 2022 19:05:23 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A61138249980 for ; Wed, 23 Mar 2022 23:05:22 +0000 (UTC) X-FDA: 79277184084.29.2D3251B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 3A38B1C0033 for ; Wed, 23 Mar 2022 23:05:22 +0000 (UTC) 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 85AC9617BB; Wed, 23 Mar 2022 23:05:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD0B9C340E8; Wed, 23 Mar 2022 23:05:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1648076721; bh=+jo1fmUPf4yEgBUfvNYe1AyqvsEG4CNfjSzhwCPYegY=; h=Date:To:From:In-Reply-To:Subject:From; b=WovkoyXSXyb8EJmNIK6djNY4JqS/Jh6XXOCHWSu5lq0rfDGuThI6xdJV0KlckC8Lx fhfNZlun/RNYdU2mYQrVB05DviR/1YSk9SWpUZYrwoYDg1aDZWk2qWHYoqLC1IbTPi RjD5KgWdbQHWY4thhuC6wBka2tU9yyPlQkOEIpnM= Date: Wed, 23 Mar 2022 16:05:20 -0700 To: keescook@chromium.org,jamorris@linux.microsoft.com,christian.brauner@ubuntu.com,adobriyan@gmail.com,haolee.swjtu@gmail.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220323160453.65922ced539cbf445b191555@linux-foundation.org> Subject: [patch 01/41] proc: alloc PATH_MAX bytes for /proc/${pid}/fd/ symlinks Message-Id: <20220323230520.DD0B9C340E8@smtp.kernel.org> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3A38B1C0033 X-Stat-Signature: mgmgrwcp5j55ggt9y4zygnyxcsyxezbo X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=WovkoyXS; dmarc=none; spf=pass (imf21.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1648076722-502090 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Hao Lee Subject: proc: alloc PATH_MAX bytes for /proc/${pid}/fd/ symlinks It's not a standard approach that use __get_free_page() to alloc path buffer directly. We'd better use kmalloc and PATH_MAX. PAGE_SIZE is different on different archs. An unlinked file with very long canonical pathname will readlink differently because "(deleted)" eats into a buffer. --adobriyan [akpm@linux-foundation.org: remove now-unneeded cast] Link: https://lkml.kernel.org/r/Ye1fCxyZZ0I5lgOL@localhost.localdomain Signed-off-by: Hao Lee Signed-off-by: Alexey Dobriyan Cc: Christian Brauner Cc: Kees Cook Cc: James Morris Signed-off-by: Andrew Morton --- fs/proc/base.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/fs/proc/base.c~proc-alloc-path_max-bytes-for-proc-pid-fd-symlinks +++ a/fs/proc/base.c @@ -1764,25 +1764,25 @@ out: static int do_proc_readlink(struct path *path, char __user *buffer, int buflen) { - char *tmp = (char *)__get_free_page(GFP_KERNEL); + char *tmp = kmalloc(PATH_MAX, GFP_KERNEL); char *pathname; int len; if (!tmp) return -ENOMEM; - pathname = d_path(path, tmp, PAGE_SIZE); + pathname = d_path(path, tmp, PATH_MAX); len = PTR_ERR(pathname); if (IS_ERR(pathname)) goto out; - len = tmp + PAGE_SIZE - 1 - pathname; + len = tmp + PATH_MAX - 1 - pathname; if (len > buflen) len = buflen; if (copy_to_user(buffer, pathname, len)) len = -EFAULT; out: - free_page((unsigned long)tmp); + kfree(tmp); return len; }