diff mbox series

[2/6] tools/pygrub: Fix bug in LIMIT_FSIZE env variable override

Message ID 20231106150508.22665-3-alejandro.vallejo@cloud.com (mailing list archive)
State New, archived
Headers show
Series Pygrub security enhancements and bugfixes | expand

Commit Message

Alejandro Vallejo Nov. 6, 2023, 3:05 p.m. UTC
The env variable must be interpreted as an integer. As it is, the override
logic simply causes an exception.

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
---
 tools/pygrub/src/pygrub | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andrew Cooper Nov. 22, 2023, 8:12 p.m. UTC | #1
On 06/11/2023 3:05 pm, Alejandro Vallejo wrote:
> The env variable must be interpreted as an integer. As it is, the override
> logic simply causes an exception.

Fixes: e0342ae5556f ("tools/pygrub: Deprivilege pygrub")

> Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
> ---
>  tools/pygrub/src/pygrub | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
> index 08540ad288..327cf51774 100755
> --- a/tools/pygrub/src/pygrub
> +++ b/tools/pygrub/src/pygrub
> @@ -89,7 +89,7 @@ def downgrade_rlimits():
>      # write permissions are bound.
>      fsize = LIMIT_FSIZE
>      if "PYGRUB_MAX_FILE_SIZE_MB" in os.environ.keys():
> -        fsize = os.environ["PYGRUB_MAX_FILE_SIZE_MB"] << 20
> +        fsize = int(os.environ["PYGRUB_MAX_FILE_SIZE_MB"]) << 20
>  
>      resource.setrlimit(resource.RLIMIT_FSIZE, (fsize, fsize))
>  

This change on its own is correct, so Acked-by: Andrew Cooper
<andrew.cooper3@citrix.com>

However, there's a bug/misfeature which you've copied in patch 3, so
I've inserted a patch 2.5 to try and fix it in a nice order.  It's
probably a little rude to merge the pythonic-fix into this functional fix.

~Andrew
diff mbox series

Patch

diff --git a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
index 08540ad288..327cf51774 100755
--- a/tools/pygrub/src/pygrub
+++ b/tools/pygrub/src/pygrub
@@ -89,7 +89,7 @@  def downgrade_rlimits():
     # write permissions are bound.
     fsize = LIMIT_FSIZE
     if "PYGRUB_MAX_FILE_SIZE_MB" in os.environ.keys():
-        fsize = os.environ["PYGRUB_MAX_FILE_SIZE_MB"] << 20
+        fsize = int(os.environ["PYGRUB_MAX_FILE_SIZE_MB"]) << 20
 
     resource.setrlimit(resource.RLIMIT_FSIZE, (fsize, fsize))