From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3CDB5477E for ; Sun, 26 Jul 2026 07:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785049568; cv=none; b=muXATz33ZUFrprnQiPXP7qHG0lVM46IC+CNdrfyviAzKndMJ9dTYebdX8OXzslAe+oz00uhj3S5J/IZveLNgVzHD32YYSjwp4QKVZ3e+wCoayTvJ+wTn5xA6qYG7FuVgAJ9X+2exBOT278/VKCMQUW5wogmGmPeStgmSDfcRivY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785049568; c=relaxed/simple; bh=rjKg0M5gKsJyzPERsexxlk9QrzoH2dLaFl7+sRbaZ/k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i+u5m+YW9XYoN3dYyTFdWsxjGSQbss5Ub5E0lDLpTEkGAjJEj8Ad/E66Vu/CifoK1Z9kcGzCjXufk769HwAQzf5vBanBfeYN3hGABAgs6eXsLWry6c8wBMO6+qfWXIPThYAmacUpeK0rOwZhyaP1SDYMolHO8w4MxujJ1hoGZO8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CyAZqkbl; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CyAZqkbl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A51011F000E9; Sun, 26 Jul 2026 07:06:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785049567; bh=J2ah8cmNlpy4xwoC60wqOGaGixZA4ICSm3J4Wve3bYA=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=CyAZqkbljYhbZr71MaQjuPepcqDVoDuST4CfRm+DHbB6YuW3EBVGu215mwr6WSQco OIzjVaes3+Zi3JZeDk64m0cbygsQ4AvA3A70APkPefhazaF471av+aM7+tOFPV+oPS H8zHzQhXVOgtPXAWABbqS53sOmKKAQb7fnVBcxWvIn4+2Ajqtgh05pgbsOxhcLzd0S Q2CNRYMcYKA3B9vP2ykm2OarbZ8S47AKPm3vY2qUAvxdX6u7AEhn6DPfijkxxkhwqw p0fh+NJPokNV7ztPN3qFKcIsGzuZvg6+t/Po/mGCfI/sfUuvRuIFt2/W8c9063mHSv SwI8liYCSRdWA== Date: Sun, 26 Jul 2026 10:06:01 +0300 From: Mike Rapoport To: David Laight Cc: Mahad Ibrahim , Kees Cook , Arnd Bergmann , Greg Kroah-Hartman , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] lkdtm: use kmalloc() instead of __get_free_page Message-ID: References: <20260722230246.2869-1-mahad.ibrahim.dev@gmail.com> <20260723094522.535b284c@pumpkin> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260723094522.535b284c@pumpkin> On Thu, Jul 23, 2026 at 09:45:22AM +0100, David Laight wrote: > On Wed, 22 Jul 2026 23:02:46 +0000 > Mahad Ibrahim wrote: > > > lkdtm_debugfs_entry and direct_entry use __get_free_page to allocate a > > temporary buffer, perform copy_from_user to get the crashtype name, > > strim() to strip whitespace and find_crashtype to find the corresponding > > crashtype that is being requested. > > > > The lkdtm_debugfs_read uses __get_free_page to allocate a temporary > > buffer to store all the available crashtypes, and then copy it to > > userspace. > > > > The buffers that are allocated can be allocated with kmalloc as there is > > nothing special that requires a struct page, or the page allocator. > > > > kmalloc() additionally provides a better API that doesn't require ugly > > casts which obfuscate the code and kfree does not need to know the size > > of the freed object. > > > > Replace use of __get_free_page() with kmalloc(). > > None of those buffers need to be PAGE_SIZE. > Even the sanity limit for overlong requests could be 4k. > The longest 'crashtype->name' is probably about 32 characters, so could > probably go on stack. As Arnd said, this is straightforward change, while changing actual allocation size is more intrusive patch and you can send it if you think it's worth the churn. > And can't this code use the sysfs/kernfs wrappers? > > David -- Sincerely yours, Mike.