From 8c95d84b39fc0886a4417c5ddefc2ea05217c0ac Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Fri, 22 Nov 2024 13:35:29 +0100 Subject: net: lwip: fix dhcp_loop() The local variables ipstr, maskstr and gwstr in static function dhcp_loop() cannot be pointers to read-only data, since they may be written to in case the device index is > 0. Therefore make them char arrays allocated on the stack. Reported-by: Ilias Apalodimas Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- net/lwip/dhcp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'net') diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c index 23b56226921..bfc72ca6c57 100644 --- a/net/lwip/dhcp.c +++ b/net/lwip/dhcp.c @@ -27,9 +27,9 @@ static void call_lwip_dhcp_fine_tmr(void *ctx) static int dhcp_loop(struct udevice *udev) { - char *ipstr = "ipaddr\0\0"; - char *maskstr = "netmask\0\0"; - char *gwstr = "gatewayip\0\0"; + char ipstr[] = "ipaddr\0\0"; + char maskstr[] = "netmask\0\0"; + char gwstr[] = "gatewayip\0\0"; unsigned long start; struct netif *netif; struct dhcp *dhcp; -- cgit v1.2.3 From 7d80e7368e1012355695e1fb580e5b20c8de03b9 Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Mon, 18 Nov 2024 15:31:25 +0100 Subject: net: lwip: fix get_udev_ipv4_info() The local variables ipstr, maskstr and gwstr in static function get_udev_ipv4_info() cannot be pointers to read-only data, since they may be written to in case the device index is > 0. Therefore make them char arrays allocated on the stack. Reported-by: Ilias Apalodimas Reported-by: Adriano Cordova Link: https://lists.denx.de/pipermail/u-boot/2024-November/572066.html Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- net/lwip/net-lwip.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'net') diff --git a/net/lwip/net-lwip.c b/net/lwip/net-lwip.c index 470217781a4..b863047f598 100644 --- a/net/lwip/net-lwip.c +++ b/net/lwip/net-lwip.c @@ -91,9 +91,9 @@ struct netif *net_lwip_get_netif(void) static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip, ip4_addr_t *mask, ip4_addr_t *gw) { - char *ipstr = "ipaddr\0\0"; - char *maskstr = "netmask\0\0"; - char *gwstr = "gatewayip\0\0"; + char ipstr[] = "ipaddr\0\0"; + char maskstr[] = "netmask\0\0"; + char gwstr[] = "gatewayip\0\0"; int idx = dev_seq(dev); char *env; -- cgit v1.2.3 From 2cde2f4a0073ac1e4a528a1fab40e3d6c1f4bf29 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Thu, 14 Nov 2024 16:29:15 +0200 Subject: net: lwip: provide entropy to MBed TLS in one go We currently provide entropy to mbedTLS using 8b chunks. Take into account the 'len' parameter passed by MBed TLS to the entropy gathering function instead. Note that the current code works because len is always 128 (defined at compile time), therefore mbedtls_hardware_poll() is called repeatedly and the buffer is filled correctly. But passing 'len' to dm_rng_read() is both better and simpler. Reviewed-by: Jerome Forissier Suggested-by: Simon Glass Signed-off-by: Ilias Apalodimas Reviewed-by: Simon Glass --- net/lwip/wget.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'net') diff --git a/net/lwip/wget.c b/net/lwip/wget.c index e85d57bc1dd..062aa7c44f0 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -42,7 +42,6 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t *olen) { struct udevice *dev; - u64 rng = 0; int ret; *olen = 0; @@ -52,12 +51,11 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, log_err("Failed to get an rng: %d\n", ret); return ret; } - ret = dm_rng_read(dev, &rng, sizeof(rng)); + ret = dm_rng_read(dev, output, len); if (ret) return ret; - memcpy(output, &rng, len); - *olen = sizeof(rng); + *olen = len; return 0; } -- cgit v1.2.3 From 13e13f58671305ac20a889d7271d85cb7e27af78 Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Thu, 14 Nov 2024 18:20:07 +0100 Subject: net: lwip: dhcp: support arguments for TFTP file download The dhcp command is supposed to have the following syntax as per "help dhcp": dhcp [loadAddress] [[hostIPaddr:]bootfilename] In other words, any arguments should be passed to an implicit tftpboot command after the DHCP exchange has occurred. Add the missing code to the lwIP version of do_dhcp(). Signed-off-by: Jerome Forissier --- net/lwip/dhcp.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'net') diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c index bfc72ca6c57..9b882cf5b87 100644 --- a/net/lwip/dhcp.c +++ b/net/lwip/dhcp.c @@ -111,9 +111,21 @@ static int dhcp_loop(struct udevice *udev) int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { + int ret; + eth_set_current(); - return dhcp_loop(eth_get_dev()); + ret = dhcp_loop(eth_get_dev()); + if (ret) + return ret; + + if (argc > 1) { + struct cmd_tbl cmdtp = {}; + + return do_tftpb(&cmdtp, 0, argc, argv); + } + + return CMD_RET_SUCCESS; } int dhcp_run(ulong addr, const char *fname, bool autoload) -- cgit v1.2.3