Re: [PATCH v2 1/2] x86/fpu: Fix memory leak with dynamic fpstate and exec()

From: Chang S. Bae

Date: Mon Oct 19 2026 - 15:01:41 EST


On 10/14/2026 5:19 PM, Chang S. Bae wrote:
On 10/7/2026 10:59 PM, Guixiong Wei wrote:

-void fpstate_free(struct fpu *fpu)
+void fpstate_free(struct fpstate *fpstate)
  {
-    if (fpu->fpstate && fpu->fpstate != &fpu->__fpstate)
-        vfree(fpu->fpstate);
+    if (fpstate && fpstate->is_valloc)
+        vfree(fpstate);
  }

Shouldn't is_valloc be cleared here, or when fpstate_reset() replaces fpu->fpstate with the embedded fpstate?

No, is_valloc is pat of the vmalloc'ed memory itself.

That said, removing the original check does not seem reassuring either. Maybe, another option would be adding an internal helper:

void __fpstate_reset(struct fpstate *fpstate)
{
if (fpstate && fpstate->is_valloc)
vfree(fpstate);
}

Then, refactor fpstate_realloc() and replace the vfree() in fpstate_free() with it, keeping the fpstate_free() prototype unchanged.

Thanks,
Chang