From patchwork Tue Aug 29 22:02:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 718249 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp242344wrh; Tue, 29 Aug 2023 16:21:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKVfog722ssSAr79PSMLYyNKujS1klQ+YeimsZfwkJroH/V9BRxBPuZstdFzSmJnDZdixc X-Received: by 2002:a05:620a:4149:b0:76d:93e1:99f4 with SMTP id k9-20020a05620a414900b0076d93e199f4mr590486qko.8.1693351318700; Tue, 29 Aug 2023 16:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693351318; cv=none; d=google.com; s=arc-20160816; b=W0lEiQc7dZtLPwrIQpROmRbrEXlkn+3GH7GblbMvKqJHJxukXXDDSnU6b05jnyIbrP A7pgedrXwNMMSohtg5udvvf742oShDzz2T3mOV4Dq0QPFUPDmQZTYTB36NjiSYG6V1cn 4W6O7QhYy7hcF5QPXZYaTVLRYhyBYAhQo+QbwuWg5FN/Y/+vSXUbMjhFrINJTPFKagZ/ bffTvXyhKZjW5lBA4yYyp+ApVA1+jz0+umK0zS4XtwmASpWfvGgq4zsJmy3jcbr4WOar 2JC+cUklARXW6HLJh+M0sVuXFdYsOWmBA2qvQ2m62ZIfl0goFk8/ZyAwZM8zxqAG9Nkf uwBg== 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=CQVgvEA797/6AHlvAuip4Dfdeigp3YyNGto1GCMbIo4=; b=DKewEWzphn6Bh2pbszHC8+cuXRYjjB0U3Ti2S0+VD+KR9+7/BZToxrC55luqCzdKDZ RNBB17JF7MPygI7GZBrUVkpytUPf1heRo39DA9mFmG5prMCP9cO562ERkRFDLhZmFnRe AOG1vXnEFRrszBmzmWn5fmvcXoniVEYDzpPKZqf/t8j0EwNEmgqTPaHQKLax3vVm0e58 6lnesnt30yvTjakrwmR/HBTEI09/kXTwhl+tNTYviWs/Yb4shpnfV6fnYRKA8FFlUTIO WWHfEGPJR2/8sb45qAmfFgYR593R7x4BAeciJXwhKHhH6UlhZXbd4PX62FQ4zg5oi+b0 oOGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="hG3z/rGT"; 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 a7-20020a05620a438700b0076ef0254161si6752492qkp.465.2023.08.29.16.21.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Aug 2023 16:21:58 -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="hG3z/rGT"; 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 1qb7n5-0000sZ-WB; Tue, 29 Aug 2023 19:06:32 -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 1qb6nE-0002NI-UO for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:37 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qb6nC-000484-3m for qemu-devel@nongnu.org; Tue, 29 Aug 2023 18:02:36 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68bed2c786eso3439161b3a.0 for ; Tue, 29 Aug 2023 15:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693346553; x=1693951353; darn=nongnu.org; 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=hG3z/rGTj/ci7t6TQvuaJGHAr6QayQo+7l5XjCD+b/Ie0tKkeJicDt27J/ehvBGh7W hth4a28z7N5omYH14ZH+0HM+V6H/RFUv2mLxdiIfWY0XoTngFXGG3qg2kJvLZNafQ0hb xJDWbq8mBhyLKLtDTZpZrZkTrajVL8TdthXtZZpBCDbuuugRAKsbwCQ0TGIGOjcvh/Bq alRiXFWirF5ghlNgVMcDlL/Ri63i25mIGRWPD74mzWZaBOdFvis+muc1kAey2KK5/Cb/ /0KSUpgtf1eDG0zp21eAPmjij1QPZAVuZCG/Le5bPr0kwQ7OhFMxXaFMM29ovwssXV51 UgzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693346553; x=1693951353; 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=LKyMGcdvHTaGIVWu9O4RwWR3nJRCLP1Nb/pni6zU7rhJuH6UmGk3JtChEmbOFhhT+Z C3lbwRGWnfbZ2hoI/0iCqsCS//wdljbR0rgzyJjAqQLz7daZ1MeBG8s976r92ezGLGSB e3az0Tn/5a3MaXoqS1ka1wqkEkFKZ6MT3J5f/fLDiiJr9DWNRN3zb++8FUOYL/SjcO+c oM/4xaNvV8ha9Oc3yQEzZbr9Tq9DCq9q0GRVKE1rCK71o+y6IuTXM6MyudfRhcZ01gfe pSKEVU4zrI8Q25cCNPDCRw5kJkQkAYMR2h09qNFxnoZS4yNHR34N6YjifymNnxjRzPJy uU4g== X-Gm-Message-State: AOJu0YyhhdjJlQQkkijvM/rp+qG8GRhUZJynCTnoXgBAvy1sqm3BYaW/ oEGPyeF0NxA7/0I5CEzKW4ZPZMxzP5IoLx0mhEA= X-Received: by 2002:a05:6a00:170d:b0:68b:e29c:b61 with SMTP id h13-20020a056a00170d00b0068be29c0b61mr447946pfc.19.1693346552720; Tue, 29 Aug 2023 15:02:32 -0700 (PDT) Received: from stoup.. ([71.212.131.115]) by smtp.gmail.com with ESMTPSA id b28-20020a63715c000000b0056606274e54sm9538196pgn.31.2023.08.29.15.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 15:02:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Subject: [PATCH v5 03/20] linux-user: Tidy loader_exec Date: Tue, 29 Aug 2023 15:02:11 -0700 Message-Id: <20230829220228.928506-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230829220228.928506-1-richard.henderson@linaro.org> References: <20230829220228.928506-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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 Reviewed-by: Alex Bennée --- 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,