All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/relocator: always enforce the requested alignment in malloc_in_range()
@ 2023-04-27 15:06 Roger Pau Monne
  2023-04-28 14:15 ` Daniel Kiper
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monne @ 2023-04-27 15:06 UTC (permalink / raw
  To: grub-devel
  Cc: daniel.kiper, dkiper, alexander.burmashev, phcoder,
	Roger Pau Monne

On failure to allocate from grub_relocator_firmware_alloc_region() in
malloc_in_range() the function would stop enforcing the alignment, and
the following was returned:

lib/relocator.c:431: trying to allocate in 0x200000-0xffbf9fff aligned 0x200000 size 0x406000
lib/relocator.c:1197: allocated: 0x74de2000+0x406000
lib/relocator.c:1407: allocated 0x74de2000/0x74de2000

Fix this by making sure that target always contains a suitably aligned
address.  After the change the return from the function is:

lib/relocator.c:431: trying to allocate in 0x200000-0xffb87fff aligned 0x200000 size 0x478000
lib/relocator.c:1204: allocated: 0x74c00000+0x478000
lib/relocator.c:1414: allocated 0x74c00000/0x74c00000

Fixes: 3a5768645c05 ('First version of allocation from firmware')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 grub-core/lib/relocator.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
index bfcc70dac3cc..d8840682c19c 100644
--- a/grub-core/lib/relocator.c
+++ b/grub-core/lib/relocator.c
@@ -744,7 +744,7 @@ malloc_in_range (struct grub_relocator *rel,
 	    {
 	      target = starta;
 	      if (target < start)
-		target = start;
+		target = ALIGN_UP (start, align);
 	      if (target + size <= end && target + size <= events[j].pos)
 		/* Found an usable address.  */
 		goto found;
@@ -761,7 +761,7 @@ malloc_in_range (struct grub_relocator *rel,
 	    {
 	      target = starta - size;
 	      if (target > end - size)
-		target = end - size;
+		target = ALIGN_UP (end - size, align);
 	      if (target >= start && target >= events[j].pos)
 		goto found;
 	    }
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/relocator: always enforce the requested alignment in malloc_in_range()
  2023-04-27 15:06 [PATCH] lib/relocator: always enforce the requested alignment in malloc_in_range() Roger Pau Monne
@ 2023-04-28 14:15 ` Daniel Kiper
  2023-05-08  7:34   ` Roger Pau Monné
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Kiper @ 2023-04-28 14:15 UTC (permalink / raw
  To: Roger Pau Monne via Grub-devel
  Cc: Roger Pau Monne, daniel.kiper, alexander.burmashev, phcoder

On Thu, Apr 27, 2023 at 05:06:54PM +0200, Roger Pau Monne via Grub-devel wrote:
> On failure to allocate from grub_relocator_firmware_alloc_region() in
> malloc_in_range() the function would stop enforcing the alignment, and
> the following was returned:
>
> lib/relocator.c:431: trying to allocate in 0x200000-0xffbf9fff aligned 0x200000 size 0x406000
> lib/relocator.c:1197: allocated: 0x74de2000+0x406000
> lib/relocator.c:1407: allocated 0x74de2000/0x74de2000
>
> Fix this by making sure that target always contains a suitably aligned
> address.  After the change the return from the function is:
>
> lib/relocator.c:431: trying to allocate in 0x200000-0xffb87fff aligned 0x200000 size 0x478000
> lib/relocator.c:1204: allocated: 0x74c00000+0x478000
> lib/relocator.c:1414: allocated 0x74c00000/0x74c00000
>
> Fixes: 3a5768645c05 ('First version of allocation from firmware')
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

LGTM but I would like to hear Vladimir's opinion too.

Daniel

> ---
>  grub-core/lib/relocator.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c
> index bfcc70dac3cc..d8840682c19c 100644
> --- a/grub-core/lib/relocator.c
> +++ b/grub-core/lib/relocator.c
> @@ -744,7 +744,7 @@ malloc_in_range (struct grub_relocator *rel,
>  	    {
>  	      target = starta;
>  	      if (target < start)
> -		target = start;
> +		target = ALIGN_UP (start, align);
>  	      if (target + size <= end && target + size <= events[j].pos)
>  		/* Found an usable address.  */
>  		goto found;
> @@ -761,7 +761,7 @@ malloc_in_range (struct grub_relocator *rel,
>  	    {
>  	      target = starta - size;
>  	      if (target > end - size)
> -		target = end - size;
> +		target = ALIGN_UP (end - size, align);
>  	      if (target >= start && target >= events[j].pos)
>  		goto found;
>  	    }


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/relocator: always enforce the requested alignment in malloc_in_range()
  2023-04-28 14:15 ` Daniel Kiper
@ 2023-05-08  7:34   ` Roger Pau Monné
  2023-05-09 13:32     ` Daniel Kiper
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monné @ 2023-05-08  7:34 UTC (permalink / raw
  To: Daniel Kiper
  Cc: Roger Pau Monne via Grub-devel, daniel.kiper, alexander.burmashev,
	phcoder

On Fri, Apr 28, 2023 at 04:15:24PM +0200, Daniel Kiper wrote:
> On Thu, Apr 27, 2023 at 05:06:54PM +0200, Roger Pau Monne via Grub-devel wrote:
> > On failure to allocate from grub_relocator_firmware_alloc_region() in
> > malloc_in_range() the function would stop enforcing the alignment, and
> > the following was returned:
> >
> > lib/relocator.c:431: trying to allocate in 0x200000-0xffbf9fff aligned 0x200000 size 0x406000
> > lib/relocator.c:1197: allocated: 0x74de2000+0x406000
> > lib/relocator.c:1407: allocated 0x74de2000/0x74de2000
> >
> > Fix this by making sure that target always contains a suitably aligned
> > address.  After the change the return from the function is:
> >
> > lib/relocator.c:431: trying to allocate in 0x200000-0xffb87fff aligned 0x200000 size 0x478000
> > lib/relocator.c:1204: allocated: 0x74c00000+0x478000
> > lib/relocator.c:1414: allocated 0x74c00000/0x74c00000
> >
> > Fixes: 3a5768645c05 ('First version of allocation from firmware')
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> 
> LGTM but I would like to hear Vladimir's opinion too.

Thanks Daniel, just a gentle ping to see if we can unblock this.

Regards, Roger.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/relocator: always enforce the requested alignment in malloc_in_range()
  2023-05-08  7:34   ` Roger Pau Monné
@ 2023-05-09 13:32     ` Daniel Kiper
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Kiper @ 2023-05-09 13:32 UTC (permalink / raw
  To: Roger Pau Monné
  Cc: grub-devel, daniel.kiper, alexander.burmashev, phcoder

On Mon, May 08, 2023 at 09:34:15AM +0200, Roger Pau Monné wrote:
> On Fri, Apr 28, 2023 at 04:15:24PM +0200, Daniel Kiper wrote:
> > On Thu, Apr 27, 2023 at 05:06:54PM +0200, Roger Pau Monne via Grub-devel wrote:
> > > On failure to allocate from grub_relocator_firmware_alloc_region() in
> > > malloc_in_range() the function would stop enforcing the alignment, and
> > > the following was returned:
> > >
> > > lib/relocator.c:431: trying to allocate in 0x200000-0xffbf9fff aligned 0x200000 size 0x406000
> > > lib/relocator.c:1197: allocated: 0x74de2000+0x406000
> > > lib/relocator.c:1407: allocated 0x74de2000/0x74de2000
> > >
> > > Fix this by making sure that target always contains a suitably aligned
> > > address.  After the change the return from the function is:
> > >
> > > lib/relocator.c:431: trying to allocate in 0x200000-0xffb87fff aligned 0x200000 size 0x478000
> > > lib/relocator.c:1204: allocated: 0x74c00000+0x478000
> > > lib/relocator.c:1414: allocated 0x74c00000/0x74c00000
> > >
> > > Fixes: 3a5768645c05 ('First version of allocation from firmware')
> > > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> >
> > LGTM but I would like to hear Vladimir's opinion too.
>
> Thanks Daniel, just a gentle ping to see if we can unblock this.

Sorry for delay but I was on vacation last week. I will check this with
Vladimir and get back to you.

Daniel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-09 13:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-27 15:06 [PATCH] lib/relocator: always enforce the requested alignment in malloc_in_range() Roger Pau Monne
2023-04-28 14:15 ` Daniel Kiper
2023-05-08  7:34   ` Roger Pau Monné
2023-05-09 13:32     ` Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.