Re: [RFC PATCH] initramfs: Add size validation to prevent tmpfs exhaustion
From: Stephen Eta Zhou
Date: Tue Mar 18 2025 - 08:46:31 EST
Hi Krzysztof
> Just in case before anyone tries to actually apply it: the entire patch
> has both corrupted header and actual patch is corrupted - all
> indentation messed.
Sorry, this is my oversight.....
I checked it locally using checkpatch.pl and it was fine, but I just used it to import and found that there is a problem. Sorry for wasting your time. I will regenerate this patch and resend it in the correct format.
Krzysztof, thanks for pointing this out.
Thanks,
Stephen
________________________________________
From: Krzysztof Kozlowski <krzk@xxxxxxxxxx>
Sent: Tuesday, March 18, 2025 19:55
To: David Disseldorp <ddiss@xxxxxxx>; Stephen Eta Zhou <stephen.eta.zhou@xxxxxxxxxxx>
Cc: jsperbeck@xxxxxxxxxx <jsperbeck@xxxxxxxxxx>; akpm@xxxxxxxxxxxxxxxxxxxx <akpm@xxxxxxxxxxxxxxxxxxxx>; gregkh@xxxxxxxxxxxxxxxxxxx <gregkh@xxxxxxxxxxxxxxxxxxx>; lukas@xxxxxxxxx <lukas@xxxxxxxxx>; wufan@xxxxxxxxxxxxxxxxxxx <wufan@xxxxxxxxxxxxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx <linux-kernel@xxxxxxxxxxxxxxx>; linux-fsdevel@xxxxxxxxxxxxxxx <linux-fsdevel@xxxxxxxxxxxxxxx>
Subject: Re: [RFC PATCH] initramfs: Add size validation to prevent tmpfs exhaustion
On 17/03/2025 08:21, David Disseldorp wrote:
>> From 3499daeb5caf934f08a485027b5411f9ef82d6be Mon Sep 17 00:00:00 2001
>> From: Stephen Eta Zhou <stephen.eta.zhou@xxxxxxxxxxx>
>> Date: Fri, 14 Mar 2025 12:32:59 +0800
>> Subject: [PATCH] initramfs: Add size validation to prevent tmpfs exhaustion
>>
>> When initramfs is loaded into a small memory environment, if its size
>> exceeds the tmpfs max blocks limit, the loading will fail. Additionally,
>> if the required blocks are close to the tmpfs max blocks boundary,
>> subsequent drivers or subsystems using tmpfs may fail to initialize.
>>
>> To prevent this, the size limit is set to half of tmpfs max blocks.
>> This ensures that initramfs can complete its mission without exhausting
>> tmpfs resources, as user-space programs may also rely on tmpfs after boot.
>>
>> This patch adds a validation mechanism to check the decompressed size
>> of initramfs based on its compression type and ratio. If the required
>> blocks exceed half of the tmpfs max blocks limit, the loading will be
>> aborted with an appropriate error message, exposing the issue early
>> and preventing further escalation.
>
> This behaviour appears fragile and quite arbitrary. I don't think
> initramfs should be responsible for making any of these decisions.
>
> Why can't the init binary make the decision of whether or not the amount
> of free memory remaining is sufficient for user-space, instead of this
> magic 50% limit?
>
> What are you trying to achieve by failing in this way before initramfs
> extraction instead of during / after?
Just in case before anyone tries to actually apply it: the entire patch
has both corrupted header and actual patch is corrupted - all
indentation messed.
Best regards,
Krzysztof