From patchwork Thu Apr 10 15:14:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 879755 Delivered-To: patch@linaro.org Received: by 2002:a5d:4882:0:b0:38f:210b:807b with SMTP id g2csp305277wrq; Thu, 10 Apr 2025 08:16:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVLyFIPiiaO0gBBBtz8A1bmKX7ox8tnS4SwadQxyKZmla0EwIhuqcAYl6VEmTet68gy5g/kaw==@linaro.org X-Google-Smtp-Source: AGHT+IFhoYxnBX1vYYBa/XDstL3aWImFdk25yw3N50sVhS1Gq8zB9wWnrQlAWUk/66/sJSDTGJZP X-Received: by 2002:a05:6214:224e:b0:6e8:ea17:8587 with SMTP id 6a1803df08f44-6f0e5c84b55mr41287406d6.42.1744298187597; Thu, 10 Apr 2025 08:16:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744298187; cv=none; d=google.com; s=arc-20240605; b=kXMOZFCdVMjDG0PVpXsvcYuUqYouPfOKkO1j2zCUX7xrEkg6AA/wmp46taID61po3E nsni/L2NamKfsIARKZarOOm7CGbUTaIxnehpSpahgfqHLFcYCi+UR5P+NYd/bM+WTZqu ur05sP9NWc/wDUaTT8Ew+iewApXxgM/oK0unloLNrHiItr5HQNu0URKHmq626mUOZoMn ax+LsQN0hf5O55/az+uOkPmaJNOok8u/0iRVnDAiCmbmnfBUfzo6kFWyyVZgpvV4lG30 V7b+JD3UaTCJkUaLFDFIRa8SGmgOqutMu2+8zIyldk25ICXd+Bvb74Adyd62VskAPJYQ EZ+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9a6sEajqBCa5JgFq0Elu50yxgHZt9DmBTjUOxmODvvA=; fh=97uo3cBzQPdpLfWVYNonWI5kJbZKqgaOd9/Q4Vy7ccc=; b=e2oJ8gNbcZYT2nB7PiTqaEIlU2WYGayBSIMqe0bOMy39cobbPy7H63PmKHwXnwsXmP sl1w9tDShRSqJVqOV51xS8eAZvJWfMliUPk3XN4qoyhViAtCAWwUzo4WU/gY6AKpESJA 3+FZWqOcZ/eotL/bWsSGwvbtCF8TUueGLVkeHBUfpbGCmhEyJ6zawU4FQY7WvDAk8nTq 73oS8hq2Kowovb90cdQh9Q5yZ+eH6iGW/sJuOjiC9DzxtS9wtJPYSagPg5F8EkZo12sR PrW2PphsdGs+mNDhYfg6m8RSCvLJPylUL/dBofxVz+ODRlDnVy83MbqwPY5gM+G6sQ9m unjw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bBClSTF3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ada2fe7eead31-4c9c98fc595si1223941137.538.2025.04.10.08.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 08:16:27 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bBClSTF3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 72D8683D4A; Thu, 10 Apr 2025 17:16:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bBClSTF3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5D10F83D3D; Thu, 10 Apr 2025 17:16:17 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4ABE683D28 for ; Thu, 10 Apr 2025 17:16:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3913b539aabso562269f8f.2 for ; Thu, 10 Apr 2025 08:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744298174; x=1744902974; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9a6sEajqBCa5JgFq0Elu50yxgHZt9DmBTjUOxmODvvA=; b=bBClSTF3+6CEUEBbnjP2Nkk9EpqiI9m7B7fdEJfK8z5kEW/jVUSY43g+Ub4d2ITLpP 5c7zSqfXmqqB2qzd5kAo08lQd2RLuQRTxpp5ACaJGeOXiCft7LNhPpvDG8kq40b2anIs 8eD5y7LQCwPZZr2tNRrVbp1kFHXcH0w5mDJmfMuw87K0YzW15PLjsOJPI0/smY3k6C7P y4mNP4USkCGfcuJu0TGSaeT9J0yDToaQlw0jFt8U0MVRYZBFoH4qGjKPVahDv6uvBHs2 m7QOIZ5njR2pr2XdpNGRFmQbvYpNEo04HSCm+vEqFBe4gd77LescdljrNlzlbpuIZLWo kCMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744298174; x=1744902974; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9a6sEajqBCa5JgFq0Elu50yxgHZt9DmBTjUOxmODvvA=; b=jLIXTdsUlP7kicNfxATJnLVcMPF8KKzd9HeAUft7yb8K+N3XbACff6wycQzTLuax1c XzOvh15T15kDfUCCCXm3CdxhspGSvSfn8euDIdl6GkdWnsVZ7bnSUK4Z7mUGVUJc5L01 XfEocipFuHvOdNBNViUHzXaNC0xGSxVgTymnFxhpxyIUvY1BMvNYxRvWi25PIcbTUjG6 ble3hBkoEtZwKI8ngh0qtdnzTnAQXCG+Rkb5duAZr7UsovF0G830a4UgXd0d8BjOy1AT DiUTTKCP5dGuo83J7+1+wqfs5khv+qb0iHkY4zPhJuUwKri4qto/DnEWn3lpnIdjQ/PA Mlew== X-Gm-Message-State: AOJu0YywCXd/ACmFNW6da+pvlTBQqRtDZKeyKchlA5oYWkVcAYjIhZFC 0qr+c8lKDokAS4Jz2Spd1QhIH8/2D5QVxqV7qi9aqOeZoMI+rVcRBiu834PdBhUL4WT7F7R4yjk 4sqs= X-Gm-Gg: ASbGnctsDyrDTrf6vFxZWU+8HuZw/rzZR4XMgNfHrfbWluHeB57BkPC6f3H0pnvFuVe 3sncUL36aXD/kX0HyDsH9UDDLN4ZIuicP+k01xqw8/EmwdcXtmRVyJbla0/8rsAi/9vY6uwRBcN FscLPqpYjtn7+svDPq+hUN6Kt/yIaNsUuZEGC2RszMIba4AFOgpP1XkGv+80Pb55RW5uD1M/+up DZ083yt601TbKJpqlMRwDpk1WfhcE7O2ytKWxCCMWeJkPPF3sj2nqiOQrgETZ7nZG62GzuoQkmT jBszeRCIAadbWnNuTkh8B6gQoZFdTPaKC7he3S6PoEVwfaFYeQ== X-Received: by 2002:a05:6000:420b:b0:391:3915:cfea with SMTP id ffacd0b85a97d-39d8f4e63demr2646083f8f.38.1744298174404; Thu, 10 Apr 2025 08:16:14 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:7edb:df05:a425:37cd]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43f233c824bsm54873225e9.24.2025.04.10.08.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 08:16:14 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Heinrich Schuchardt , Adriano Cordova , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Simon Glass , Tom Rini Subject: [PATCH v3 1/3] net-lwip: wget_do_request(): do not print anything to the console Date: Thu, 10 Apr 2025 17:14:52 +0200 Message-ID: <20250410151600.3370247-2-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250410151600.3370247-1-jerome.forissier@linaro.org> References: <20250410151600.3370247-1-jerome.forissier@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Functions called from EFI applications should not call printf(). Refactor wget_do_request() to implement this requirement. Signed-off-by: Jerome Forissier Reported-by: Heinrich Schuchardt --- Changes in v3: - New patch: net-lwip: wget_do_request(): do not print anything to the console net/lwip/wget.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/net/lwip/wget.c b/net/lwip/wget.c index ec098148835..d3628cf72de 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -36,6 +36,7 @@ struct wget_ctx { ulong prevsize; ulong start_time; enum done_state done; + bool silent; }; static void wget_lwip_fill_info(struct pbuf *hdr, u16_t hdr_len, u32_t hdr_cont_len) @@ -217,7 +218,8 @@ static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, memcpy((void *)ctx->daddr, buf->payload, buf->len); ctx->daddr += buf->len; ctx->size += buf->len; - if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { + if (!ctx->silent && + ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { printf("#"); ctx->prevsize = ctx->size; } @@ -255,11 +257,15 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result, elapsed = get_timer(ctx->start_time); if (!elapsed) elapsed = 1; - if (rx_content_len > PROGRESS_PRINT_STEP_BYTES) - printf("\n"); - printf("%u bytes transferred in %lu ms (", rx_content_len, elapsed); - print_size(rx_content_len / elapsed * 1000, "/s)\n"); - printf("Bytes transferred = %lu (%lx hex)\n", ctx->size, ctx->size); + if (!ctx->silent) { + if (rx_content_len > PROGRESS_PRINT_STEP_BYTES) + printf("\n"); + printf("%u bytes transferred in %lu ms (", rx_content_len, + elapsed); + print_size(rx_content_len / elapsed * 1000, "/s)\n"); + printf("Bytes transferred = %lu (%lx hex)\n", ctx->size, + ctx->size); + } if (wget_info->set_bootdev) efi_set_bootdev("Http", ctx->server_name, ctx->path, map_sysmem(ctx->saved_daddr, 0), rx_content_len); @@ -372,13 +378,14 @@ static int set_cacert(char * const saddr, char * const ssz) #endif #endif /* CONFIG_WGET_CACERT || CONFIG_WGET_BUILTIN_CACERT */ -static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) +static int wget_loop(ulong dst_addr, char *uri, bool silent) { #if CONFIG_IS_ENABLED(WGET_HTTPS) altcp_allocator_t tls_allocator; #endif httpc_connection_t conn; httpc_state_t *state; + struct udevice *udev; struct netif *netif; struct wget_ctx ctx; char *path; @@ -390,6 +397,13 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) ctx.size = 0; ctx.prevsize = 0; ctx.start_time = 0; + ctx.silent = silent; + + if (!wget_info) + wget_info = &default_wget_info; + + net_lwip_set_current(); + udev = eth_get_dev(); if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https)) return CMD_RET_USAGE; @@ -471,12 +485,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) int wget_do_request(ulong dst_addr, char *uri) { - net_lwip_set_current(); - - if (!wget_info) - wget_info = &default_wget_info; - - return wget_loop(eth_get_dev(), dst_addr, uri); + return wget_loop(dst_addr, uri, true); } int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) @@ -521,7 +530,7 @@ int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_FAILURE; wget_info = &default_wget_info; - if (wget_do_request(dst_addr, nurl)) + if (wget_loop(dst_addr, nurl, false)) return CMD_RET_FAILURE; return CMD_RET_SUCCESS; From patchwork Thu Apr 10 15:14:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 879756 Delivered-To: patch@linaro.org Received: by 2002:a5d:4882:0:b0:38f:210b:807b with SMTP id g2csp305391wrq; Thu, 10 Apr 2025 08:16:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVFoStcPBzFm5TCVbDYaxz6EEs+T/WEIeA7k1nLAmbcV3ffuNWnuUY9j7Mzjvz99n/XClU1Hw==@linaro.org X-Google-Smtp-Source: AGHT+IEERZKtQYkArDHnlMXhihbzUXxBb5xsTE4l7VhfuTYUVwXXK42GCx72g+len7lgN/6AwUQZ X-Received: by 2002:a05:620a:4251:b0:7c7:a6fe:500 with SMTP id af79cd13be357-7c7a76d091fmr513462985a.55.1744298196742; Thu, 10 Apr 2025 08:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744298196; cv=none; d=google.com; s=arc-20240605; b=ECQD0lGsq1UWKQjn4Fvv834kLSYSa520bOe0W0PhUEuZy1myAwoWzbbesD0jfkqPds 6WO077cTlbWy+wWUpqwsAZMp9eBcTm3toqnwQTYkCUfRaQyjF3L4vqp+5nL5vuLM8sSV HEYAr11aBSWlMuaNFxNdr36sEnMaGHgdepBVaTHfCn+PGPQYh8hRiYisbWT31IT7oMLo 1RVuD9UihbaMo/xEEOtVqSU8KESP5qE3zVb/qoya6rYnWCYQQTSoX5IuxMb8JK0bOofw Ikqv+y7/FDF1nYMzB31AcSI0/paYJGa8Qrhb+B47bLnwxfCCxmZaueGjDr/6y71RrQS+ G1QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2qrIYvhrPni0ORHgstbrNs0wtrrGI1JHSjKov0eTU/E=; fh=Nh72lUSdYooCwChGvpRzkAxqTTKBSHBw+XTRimgIlH0=; b=Yu904Jh1l6Piwxf3nczBC8J76oG8Vb1e2+K2WhckWg914N8+8/aN7DaGj+/Bx1TZaQ 4TwrkZEOBktZu0mb7sQiLa2s7O6PBnj6mFafrzj813raN1j7Ktd5P9Z0f/0vBEgHRkyH Wl3fvM2vupX5DhnrkvM3RDDC9mCQdXPrtAqvqpd7kwTRTU5+4FxtKTkN0ogJ6C9X57ag TadVIUFm4H5UNzIX42lW/CLa1mLmCa8BftL9cAkRihHjfvpR7HtK3Ujj2kbk6iQLTTK6 n6ranw2TbTvpZ/luaNJG6zJrcSR2pwvz6Z1/REOpCVordVfZ55L8Q2SXN+9ezU7LZ489 920Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ivi7YfAO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a1e0cc1a2514c-875571761b5si1094010241.81.2025.04.10.08.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 08:16:36 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ivi7YfAO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B6E5883B8F; Thu, 10 Apr 2025 17:16:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Ivi7YfAO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D41898192A; Thu, 10 Apr 2025 17:16:18 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2170F83D39 for ; Thu, 10 Apr 2025 17:16:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-43cec5cd73bso7595745e9.3 for ; Thu, 10 Apr 2025 08:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744298175; x=1744902975; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2qrIYvhrPni0ORHgstbrNs0wtrrGI1JHSjKov0eTU/E=; b=Ivi7YfAOuFYdfQ6QF8K8mVcCf6/xZwtRd//dMlRu+JkV24JRvoJAqUPXNMWYisN9eY gkbRCAqCpyVXQ72DkIbouwmJy1P+iPk3XfmesPXw1WSxnEJMpMYwb1JLEoxoThQZhKHB eeSKvPDXnY49zPlw2E3brsrKDe+x3WCEXrjXRYyoSUl6X8MvMtLI7gPehRiWFYI3IYfp h625IK8gPj5UpXMuNHa1YK5lhq4MFlqSXRdoYSfu5b9TfA2cYqYx6l+lL3mSSBDJm+0e Xo8gdu30NIXACygmjalXlIhb7SnuvJUR/I0Ht4ar+XIciCneRiLj0OZGu2Nl4DxHlRK0 axTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744298175; x=1744902975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2qrIYvhrPni0ORHgstbrNs0wtrrGI1JHSjKov0eTU/E=; b=B5Er0o003RkMvlsoaPB4IumP0pIFEfnk2OoXdPAJj6l2jE8QfYxu6Kk+dykVvaA39j ZD/erfQSa+g797gVwK2Oguz6/EKBqC2gg6vVX9u2H6ClXEyGDqQ7rGo/rFjHuDEf2A+k 2m+D6go9TF2HoEIyxliBQkq1dEg3JdEnfZZH1FhS5LHRS6XtIz629uC2IsRjY2bGKqyw vEsd9lKSfXmIAorxRPeY7vUHbEHrn6s27G/nyliqPJvh1BRF7IdO7HRw63Z7p0HQ20Uq mj7a94UbbPJVuEF0DCIN3bg16M7trmKXuOp+Z0q8h2io6Vaw7oyz1TX/VrmWJTP2gDiV GNBQ== X-Gm-Message-State: AOJu0YyB0uZs8AGVZIf5GXiLRQnonKCMSm0VaN/a4UDURv6MClHprBzh gMfZi6a0VEB+5KAeaC5MjGhx3p9AaXy+LuXAu2pVu/zTBLOM20Tov4zP4WoelEnSDO+DcoLP5Bw v7bM= X-Gm-Gg: ASbGnctsdxAxbgXoCwYxzSNlnDrvnBjiBfGSRPssIZQUCtX72Yt0Ztr0mE2MSnIejQb mE5NF9fTSBmu3PqPoAaRnvBK8aoBk4zT4EqnUhxj1GB4ZrkeqBE0IrOF25i1NyWG52io8l31fyS I6mshR0zGeP159JPnf8zwS8QnBTb98U3P84HlTvXBSOaj3IIqnUDpjmx+cQMfp2MPRijMWpLch6 afOp0HDldnQ/T4J32VfTIOATHz2B2HXHWgYp1CPFds1g7UPNITan1r9JvRpFInLvNEiX2MAPy12 6MrsalBvCBUcvqc2th0rDpyROq+K4ZMwYEE7v/28b+opjEhOtg== X-Received: by 2002:a5d:64e3:0:b0:39a:cc34:2f9b with SMTP id ffacd0b85a97d-39d8f469224mr3200185f8f.16.1744298175285; Thu, 10 Apr 2025 08:16:15 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:7edb:df05:a425:37cd]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43f233c824bsm54873225e9.24.2025.04.10.08.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 08:16:14 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Sughosh Ganu , Adriano Cordova , Heinrich Schuchardt , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Simon Glass , Tom Rini Subject: [PATCH v3 2/3] net-lwip: wget: add LMB and buffer checks Date: Thu, 10 Apr 2025 17:14:53 +0200 Message-ID: <20250410151600.3370247-3-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250410151600.3370247-1-jerome.forissier@linaro.org> References: <20250410151600.3370247-1-jerome.forissier@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Legacy NET wget invokes a store_block() function which performs buffer validation (LMB, address wrapping). Do the same with NET_LWIP. Signed-off-by: Jerome Forissier Suggested-by: Sughosh Ganu --- Changes in v3: - store_block() [wget]: add Sphinx-like documentation - store_block() [wget]: do not print to the console if ctx->silent Changes in v2: - httpc_recv_cb(): add a call to altcp_abort(). Otherwise the transfer continues and we try to write later blocks which makes no sense if one has been rejected already. Thanks Sughosh G. for testing and reporting. net/lwip/wget.c | 63 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/net/lwip/wget.c b/net/lwip/wget.c index d3628cf72de..ebea6ea21a0 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "lwip/altcp_tls.h" #include @@ -202,11 +203,57 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem) return 0; } +/** + * store_block() - copy received data + * + * This function is called by the receive callback to copy a block of data + * into its final location (ctx->daddr). Before doing so, it checks if the copy + * is allowed. + * + * @ctx: the context for the current transfer + * @src: the data received from the TCP stack + * @len: the length of the data + */ +static int store_block(struct wget_ctx *ctx, void *src, u16_t len) +{ + ulong store_addr = ctx->daddr; + uchar *ptr; + + /* Avoid overflow */ + if (wget_info->buffer_size && wget_info->buffer_size < ctx->size + len) + return -1; + + if (CONFIG_IS_ENABLED(LMB) && wget_info->set_bootdev) { + if (store_addr + len < store_addr || + lmb_read_check(store_addr, len)) { + if (!ctx->silent) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory\n"); + } + return -1; + } + } + + ptr = map_sysmem(store_addr, len); + memcpy(ptr, src, len); + unmap_sysmem(ptr); + + ctx->daddr += len; + ctx->size += len; + if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { + printf("#"); + ctx->prevsize = ctx->size; + } + + return 0; +} + static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, err_t err) { struct wget_ctx *ctx = arg; struct pbuf *buf; + err_t ret; if (!pbuf) return ERR_BUF; @@ -215,19 +262,17 @@ static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, ctx->start_time = get_timer(0); for (buf = pbuf; buf; buf = buf->next) { - memcpy((void *)ctx->daddr, buf->payload, buf->len); - ctx->daddr += buf->len; - ctx->size += buf->len; - if (!ctx->silent && - ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { - printf("#"); - ctx->prevsize = ctx->size; + if (store_block(ctx, buf->payload, buf->len) < 0) { + altcp_abort(pcb); + ret = ERR_BUF; + goto out; } } - altcp_recved(pcb, pbuf->tot_len); + ret = ERR_OK; +out: pbuf_free(pbuf); - return ERR_OK; + return ret; } static void httpc_result_cb(void *arg, httpc_result_t httpc_result, From patchwork Thu Apr 10 15:14:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 879757 Delivered-To: patch@linaro.org Received: by 2002:a5d:4882:0:b0:38f:210b:807b with SMTP id g2csp305486wrq; Thu, 10 Apr 2025 08:16:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVIPJgubqzTVT41goI403wrZB/OQxu7kg9aP2C4MIn82Z8qMQhGMTQqf9c+dwWPkqGJ9qGZnQ==@linaro.org X-Google-Smtp-Source: AGHT+IGxzmZob9wqYvs4/jhHxQQlgk0oyQjgBFJLm2i1yOmO38dSayuCumq/R2rlf8Kn0saRME3k X-Received: by 2002:a05:6102:3a10:b0:4af:deaf:f891 with SMTP id ada2fe7eead31-4c9d347d9c5mr2665692137.4.1744298205852; Thu, 10 Apr 2025 08:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744298205; cv=none; d=google.com; s=arc-20240605; b=AVbxETHBVWQSplTBjcUIt0IPA2r6hX/xUKYnUtu4FudNY9IQqhQUaRBkfB929UhL7v yG9nsZUAt7iXN9OJoL+CtR/E8VdEVU6fR1sBHYl0aXc/PVvuAyY4GtPD5rPMQ9+gfLZ4 L5YX4sSJa4bgYgFqVbtR4x57kuRxDLmZIiPkWuvO96q7/n+TCh5mcSazFuv78kSk53yn tYzc8EWw2Nc7PASNjLwKD3Zd38+lxwb35E3lQhd/H5elwFGmxmYRCLZi4ctvAZhEBrEk R0NDO60GCvz3RH6I0VNFCM2dhuyv9o7evQ78kbEbd+JzdZsxmWTuBSAclXnV1FXPC+m1 WKUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GiQhEdzxFC/SizZUKx6GlyeI6XqT1jcQhvAy1drEgA8=; fh=PQg1uaxoFkVPH7GvYt2sPX/rmqpadkXu1gxBQgKczic=; b=DSZadR8CX60K6pZd9cKG4Qoza6mGQu6O+/6huOANa7wuitQ4U5Pb8deGe3oLEAk6zG imoN9l6elnUrMBbLpWN+sv+1lGqihlx449w59O25qrflr8/REgmP9e+MfnF8GhTL9/yt 7ja09/vf8Hdtx79ceznVvsU3obdTd3wFBYWJ0k3wrtnB96sS9gOQfvmjrcB3XQkW9tPr P5b64DNNm0VtrWplTaNzyADop0WbYWL+yTlT2zpwaYoX41/ZffY621T5gBV53Pgef8wj cQ7fxAiro703KuO8zYXsU3ORLL9IzFeGtQV57R3kC5rvMgCJy4JVXH/zhNvyc/Rp0lez rU8g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qI47O1w4; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ada2fe7eead31-4c9c988f020si1107928137.313.2025.04.10.08.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 08:16:45 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qI47O1w4; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 09F1083D3C; Thu, 10 Apr 2025 17:16:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="qI47O1w4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 102918192A; Thu, 10 Apr 2025 17:16:19 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DDEBC83B8F for ; Thu, 10 Apr 2025 17:16:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-43edecbfb94so10460105e9.1 for ; Thu, 10 Apr 2025 08:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744298176; x=1744902976; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GiQhEdzxFC/SizZUKx6GlyeI6XqT1jcQhvAy1drEgA8=; b=qI47O1w4IXxfzshbZ32bylguhhTu9auFbqsTm9CNhcYeSVWcFVK6JX0psyLpvimBky BiqjzghFuZByh0K0BcbXPG1WfHxnzyQqMjZ3UFUj71NRgq8lYWgfsaBlV7s7SFaS69CR Z9A0YF8uc0iEx4KKwn5/IgdRiBT9Uo3J1T3o2N1er+f/6D/qoeicPoefDgvHdQj7BGjm ZxcLdiP1QC2xxj0Nlak5V3JfWGzlSVFC3uSQc8gZKA/wFJJfKWlAFt5y0TnwCltVjNfo 7zSwwrUJQWpXb4dMhUA++NqFkA/8l3pLJ0ysyejYNLfx0Z58Z9M1mC+xkjlNgbjYkbn7 /w+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744298176; x=1744902976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GiQhEdzxFC/SizZUKx6GlyeI6XqT1jcQhvAy1drEgA8=; b=u/AEvrOxdZnrikmy8eF7KrFnTy8uc22ZspSMTCFeYDkJZXepjz2qHbveCwZ4QkeeFx 3/4jZPfSUXNd7U/eJAVuApOXULHet5mBI6VtYi/cKVXHVEpZHAEl3tmQAZsU7LLaiVIo Pwt1Hj+SjTzD4elFnZr5g8yaLbPzmutnHDRK8BqIrOycBv4dJ56/4g0JMJHOhePvrDoN rxFng37nuvwaQL+jV9laFUDgEHLF1zr6Cw/cVc2WgeGvCPZx4qS5Zq7bxwGdNshhyVpq qt4ENVqHsYxy/51YEAXGNbWdfUI8V1/VnGNfKE9l7/o/JE3YN/a3l6/2MwfWPFfAHV8R xa5Q== X-Gm-Message-State: AOJu0YyEIojvhvoYdp7XaI9o/hn+KE9fztu6FmdFMCCFwMudhryrBCgc brnK+jfAMME/k4eZ7VDtgA+/3WnlJtdPt3mkmxaxdhZyoZSHDizvuhM473+wDbQazM3BuNogJt7 BvAE= X-Gm-Gg: ASbGncuZRhjG6MQT3cZwMN1DxeGF4W1BPknuPS3GjqEZxJq/VJHfQierMm6tqXaVDHk 5dd3HMZsayprJETrKONh/sK4AB5sUNupgIoQEQ1lDDC79teTjbbUjQDLD3LcZNF0QiRnrSsf8bj dB1hXDlCFrmLk0W5gfeu+3e1bknN6yE38lw4AKC+c9etgzMm2drTnXG+BY6RKgrDEwl3YA/KZWp hJG+mLviZqkjQ5b3STLO5bY+jHPDRDIZWPhpYAEyTmAFIh6bmJDaSUh4Immc7DIHZF0lrooEnJ8 DWa3gvgr89/cPiR9TUSB+aGE0zo1GoMj4rdWNE8xJF+ujx397g== X-Received: by 2002:a5d:5f4b:0:b0:399:6d26:7752 with SMTP id ffacd0b85a97d-39d8fd8b4bamr2633423f8f.38.1744298176113; Thu, 10 Apr 2025 08:16:16 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:7edb:df05:a425:37cd]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43f233c824bsm54873225e9.24.2025.04.10.08.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Apr 2025 08:16:15 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Sughosh Ganu , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Tom Rini Subject: [PATCH v3 3/3] net-lwip: tftp: add LMB and buffer checks Date: Thu, 10 Apr 2025 17:14:54 +0200 Message-ID: <20250410151600.3370247-4-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250410151600.3370247-1-jerome.forissier@linaro.org> References: <20250410151600.3370247-1-jerome.forissier@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Legacy NET tftp invokes a store_block() function which performs buffer validation (LMB, address wrapping). Do the same with NET_LWIP. Signed-off-by: Jerome Forissier Suggested-by: Sughosh Ganu --- Changes in v3: - store_block() [tftp]: add Sphinx-like documentation net/lwip/tftp.c | 56 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/net/lwip/tftp.c b/net/lwip/tftp.c index 123d66b5dba..c7f1420ca0f 100644 --- a/net/lwip/tftp.c +++ b/net/lwip/tftp.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,47 @@ struct tftp_ctx { enum done_state done; }; +/** + * store_block() - copy received data + * + * This function is called by the receive callback to copy a block of data + * into its final location (ctx->daddr). Before doing so, it checks if the copy + * is allowed. + * + * @ctx: the context for the current transfer + * @src: the data received from the TCP stack + * @len: the length of the data + */ +static int store_block(struct tftp_ctx *ctx, void *src, u16_t len) +{ + ulong store_addr = ctx->daddr; + void *ptr; + + if (CONFIG_IS_ENABLED(LMB)) { + if (store_addr + len < store_addr || + lmb_read_check(store_addr, len)) { + puts("\nTFTP error: "); + puts("trying to overwrite reserved memory...\n"); + return -1; + } + } + + ptr = map_sysmem(store_addr, len); + memcpy(ptr, src, len); + unmap_sysmem(ptr); + + ctx->daddr += len; + ctx->size += len; + ctx->block_count++; + if (ctx->block_count % 10 == 0) { + putc('#'); + if (ctx->block_count % (65 * 10) == 0) + puts("\n\t "); + } + + return 0; +} + static void *tftp_open(const char *fname, const char *mode, u8_t is_write) { return NULL; @@ -71,17 +113,9 @@ static int tftp_write(void *handle, struct pbuf *p) struct tftp_ctx *ctx = handle; struct pbuf *q; - for (q = p; q; q = q->next) { - memcpy((void *)ctx->daddr, q->payload, q->len); - ctx->daddr += q->len; - ctx->size += q->len; - ctx->block_count++; - if (ctx->block_count % 10 == 0) { - putc('#'); - if (ctx->block_count % (65 * 10) == 0) - puts("\n\t "); - } - } + for (q = p; q; q = q->next) + if (store_block(ctx, q->payload, q->len) < 0) + return -1; return 0; }