mirror of
https://git.proxmox.com/git/grub2
synced 2025-10-04 18:53:29 +00:00
net/netbuff: Block overly large netbuff allocs
A netbuff shouldn't be too huge. It's bounded by MTU and TCP segment reassembly. This helps avoid some bugs (and provides a spot to instrument to catch them at their source). Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
parent
557370849b
commit
4ea64c827f
@ -79,10 +79,23 @@ grub_netbuff_alloc (grub_size_t len)
|
|||||||
|
|
||||||
COMPILE_TIME_ASSERT (NETBUFF_ALIGN % sizeof (grub_properly_aligned_t) == 0);
|
COMPILE_TIME_ASSERT (NETBUFF_ALIGN % sizeof (grub_properly_aligned_t) == 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The largest size of a TCP packet is 64 KiB, and everything else
|
||||||
|
* should be a lot smaller - most MTUs are 1500 or less. Cap data
|
||||||
|
* size at 64 KiB + a buffer.
|
||||||
|
*/
|
||||||
|
if (len > 0xffffUL + 0x1000UL)
|
||||||
|
{
|
||||||
|
grub_error (GRUB_ERR_BUG,
|
||||||
|
"attempted to allocate a packet that is too big");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (len < NETBUFFMINLEN)
|
if (len < NETBUFFMINLEN)
|
||||||
len = NETBUFFMINLEN;
|
len = NETBUFFMINLEN;
|
||||||
|
|
||||||
len = ALIGN_UP (len, NETBUFF_ALIGN);
|
len = ALIGN_UP (len, NETBUFF_ALIGN);
|
||||||
|
|
||||||
#ifdef GRUB_MACHINE_EMU
|
#ifdef GRUB_MACHINE_EMU
|
||||||
data = grub_malloc (len + sizeof (*nb));
|
data = grub_malloc (len + sizeof (*nb));
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user