From patchwork Wed Aug 16 18:03:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 714037 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp2490879wrp; Wed, 16 Aug 2023 11:04:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqdG5CPIjtRnn9+5JBvZho8VdDxpCh1XRh/LMWIFo5wvcvELs/Hv/Yre8rA7MhLFawhRTU X-Received: by 2002:a05:6870:9a28:b0:1bf:4a66:d54f with SMTP id fo40-20020a0568709a2800b001bf4a66d54fmr3466626oab.56.1692209092734; Wed, 16 Aug 2023 11:04:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692209092; cv=none; d=google.com; s=arc-20160816; b=MhYz5sFlZkt3VfKsnTX1QUBiqqw4SCt5u22Z6Rd0GlhoNo6Ibtm46sJtUHDRFRavVN uaVgX0CUdJDaThRVKu2j9H06Ng6AK7ikuduc0yVhVBufLKpmRV/BJUkTEYvPcaULNNix t8IfSzsJ9HXPuIRay+zWdFL99xc1VfyzK4aitPlz9vtqueQhpsaIUEwpHuNPHjEFh8k/ dwYhZ8+2iGzQ9LYKtXprmPWrNlktiRXk4u4gjJfioWLIogBYVJKGw9HHFeXwS6b7tKiX kOtGnP1KO1XImfKAsMskePwC2Dcdb9WSftq8bVzP7Jpfh0nGV6DmtGqH1ZqZeBDWamQF vStg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=BbPoiA4hDTDe4hGu5oLPJ3b2yV0sQkSxEUBuznSGCYM=; fh=25Ln9sh8VotgD1xnu+bd6t7GyKFtMqim5b1vs4Czlso=; b=A6VTjLeimk6X05WCTfagH4ybT92kRQUiW8Gii/z2v1qqxTozaFb30uWalj2UuPUjB6 yUgWIVmzhcU9Yh2/sptXAS1RRyzRgWWBOno7QD/ABIwFeKq247rqVnmxzzdFDgGYsjhO 0SnjxKg4C/FjUKbo64TdLz74JG9hoS0Tfmsgga51U1uxgnYP/uoVEcE4debpY8m5H/8t YFt+yVA+Xz0CeQ1fjv1QSudz42hixfyD/SebD2rV93FgnEjANGVzi15EmNNfiYE/tvMd iuUZMp4XTV54NHP9rRU4or7AJVJXGBd7WkO783Y8VXW0wZwFhFjTXfbnN9FPUUJy0FB2 N4Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zw+dwHlC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a17-20020a05622a02d100b0040549989585si9054048qtx.53.2023.08.16.11.04.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Aug 2023 11:04:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zw+dwHlC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWKrz-00026A-86; Wed, 16 Aug 2023 14:03:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWKrx-00024h-JZ for qemu-devel@nongnu.org; Wed, 16 Aug 2023 14:03:45 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWKru-0001J6-FA for qemu-devel@nongnu.org; Wed, 16 Aug 2023 14:03:45 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1bb84194bf3so43519525ad.3 for ; Wed, 16 Aug 2023 11:03:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692209021; x=1692813821; 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=BbPoiA4hDTDe4hGu5oLPJ3b2yV0sQkSxEUBuznSGCYM=; b=zw+dwHlCnf29iPqZKw64+5+ren92LHt0qfYE+wBM/DINK76rLtniDSfwqVvyk6vhmC 3Rzqz68IsZH3u/Br1aZEAN+69Xy3Cz2ZKAK9q5939gV6rCsc9OlqZvMN3VBXgJ6xcsaD 7335nYyn5eTs3y3NoLbI153fvXQxULbGRzS7o+TVJqPEnvirxFQI15jJP9KEGij+1/4x AjlSdaAuju8Y3Ys8dcf2TF1V/aeRm4oN0OxrFSCBwFzH+/eSR4zFoWVlV/W7Jif/6fRn Vjvppfuqx5kwp4rSoVStxq+0OZYWnRaKJ0yhrcunlbrQRpPkSarymd5zbQMa2vFYKCTN I9eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692209021; x=1692813821; 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=BbPoiA4hDTDe4hGu5oLPJ3b2yV0sQkSxEUBuznSGCYM=; b=dpVsrZiOYr3dY57GmTFPZoLJNeSjX2JrJ6TZ1gO7nNlDzFQ8xHyg5h3XHB5X2XHZwx p3gBCBNdDDEywrZB5+IUI25L4kaPRL7gE596MYLkK0WNZiFIvQTO6dcRphIJq9X9qRmH 4cbJuyvyrCQl6JkXVZl1Q/uxZfxLV/tQrjEpO97nW9mMNbNGomyvJ4QhP1aXS2HGXgjS s4qgi9fombWHGHDLcXM40meaRp4GzUaizAnLdtV8wDnw8r4WK3gfDkvjx23OA+nR164R oNxKdpljrA6G9rfudW5xLbUHu//uF2w/g2VcdFNctmxCCiJuOvh9nTcjUNhkf0pVfm9z NmkA== X-Gm-Message-State: AOJu0YwKrHEl8fupHiFCTQNnqK+Nma/Aht62fPYxIX6N1jtLx343t3mU AOiwGi+97vLRaeZkFtYUPlieBsI/8A5YUTGsUAQ= X-Received: by 2002:a17:903:48c:b0:1be:1a2:8a85 with SMTP id jj12-20020a170903048c00b001be01a28a85mr2002807plb.0.1692209021128; Wed, 16 Aug 2023 11:03:41 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:a064:e3f9:a812:973b]) by smtp.gmail.com with ESMTPSA id g14-20020a170902868e00b001bc2831e1a9sm13446584plo.90.2023.08.16.11.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 11:03:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v4 02/18] linux-user: Tidy loader_exec Date: Wed, 16 Aug 2023 11:03:22 -0700 Message-Id: <20230816180338.572576-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230816180338.572576-1-richard.henderson@linaro.org> References: <20230816180338.572576-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Reorg the if cases to reduce indentation. Test for 4 bytes in the file before checking the signatures. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/linuxload.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 3536dd8104..5b7e9ab983 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -154,31 +154,31 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, retval = prepare_binprm(bprm); - if (retval >= 0) { - if (bprm->buf[0] == 0x7f - && bprm->buf[1] == 'E' - && bprm->buf[2] == 'L' - && bprm->buf[3] == 'F') { - retval = load_elf_binary(bprm, infop); -#if defined(TARGET_HAS_BFLT) - } else if (bprm->buf[0] == 'b' - && bprm->buf[1] == 'F' - && bprm->buf[2] == 'L' - && bprm->buf[3] == 'T') { - retval = load_flt_binary(bprm, infop); -#endif - } else { - return -ENOEXEC; - } + if (retval < 4) { + return -ENOEXEC; } - - if (retval >= 0) { - /* success. Initialize important registers */ - do_init_thread(regs, infop); + if (bprm->buf[0] == 0x7f + && bprm->buf[1] == 'E' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'F') { + retval = load_elf_binary(bprm, infop); +#if defined(TARGET_HAS_BFLT) + } else if (bprm->buf[0] == 'b' + && bprm->buf[1] == 'F' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'T') { + retval = load_flt_binary(bprm, infop); +#endif + } else { + return -ENOEXEC; + } + if (retval < 0) { return retval; } - return retval; + /* Success. Initialize important registers. */ + do_init_thread(regs, infop); + return 0; } bool imgsrc_read(void *dst, off_t offset, size_t len,