From patchwork Sat Sep 30 02:15:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728080 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp740663wrt; Fri, 29 Sep 2023 19:17:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG57wM8PC3oOTTqg/4Pc0ZDz/Kewk/Cm/yqL3kqk/CAlho/ivyiVa523ENOto4Zg+VttVzC X-Received: by 2002:a05:622a:8c:b0:40f:ce6d:775e with SMTP id o12-20020a05622a008c00b0040fce6d775emr7592803qtw.42.1696040258053; Fri, 29 Sep 2023 19:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696040258; cv=none; d=google.com; s=arc-20160816; b=EQ0fxHATddKugkUHv3UDxQwAp44VbRh1X2S2vBwzHixXjRJBlvk5Ave9lmub6OSvdo YO0OWHCSAPEk3hQb33QiI5NTytwxfEFeH59CtG76EUSvvBenl9fQotZO2e4Z2fcpI1Bm nX2K+p0jCw7OrNbUG6piqUA5aSSmHddAoFXU7BlS1oWtmhrCpXKfrbd58JSJz9MLdJFS hDxVGATf/2hdKcW3Z5iHmDxMeJF2GLAXqIMkgu7z2P+tr3LCGm46R0EDCFjn+ED+OVSD pDLFYS8GWU4jpxMPbxEJ/WWsb6OSGX+Mbe0we5SEBe5tLoSP9eGpHY26q7chZ6vvbf8h 4i6g== 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=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; fh=CQVgvEA797/6AHlvAuip4Dfdeigp3YyNGto1GCMbIo4=; b=BvlhbAgHszvyjos/ZcPVGdfzn42rFA3DUJFRu198iQIZqJnzYpr+oVulKdArYZeG4p agKQqrLG33XPo9/cfu07kxn7yJcYIrb3s8vPUE09SN8+Yd4zLx8dFXK3gTBj78/PvYXS pcVkxXECQuni312FvEaab3HTdrOAtZ8xQj8LE074YASF9oh6nMFeWAamgYTVIrhWe9lX 5ReZ5p7p5QsEP6r+rOy/glykywkHG2kNNnYhSpYBNlU6e+QWxbdSzADNM0U4i9kDDwsx E2hXk8ymYlsaIWUrUC7pNCrzXjmInEIsiAIxpBZT2xzCefMhVREhzXewIDlml6MZhGq8 arxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lTSXnsti; 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 k7-20020a05622a03c700b004151d26bdc9si3765710qtx.568.2023.09.29.19.17.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Sep 2023 19:17:38 -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=lTSXnsti; 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 1qmPWN-0000G5-7P; Fri, 29 Sep 2023 22:15:55 -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 1qmPWB-0000C0-3l for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:43 -0400 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW3-0001yh-Eq for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:42 -0400 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-57d086365f7so3244352eaf.0 for ; Fri, 29 Sep 2023 19:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040133; x=1696644933; 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=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; b=lTSXnstiUUa+YvcwiwLyH46SpdnYn0WvLHWje1DuMdehoHYom+kmGWkyoh6uNtySPn fP1/gwZddyqQkR6lwntvXyL4IGpQvUxECTifiA8yLViA5iAsmhqSOBh8kEqcKEtwkzix Baj0PV469geaN6p49h9drlc4kpLQ63yLD4oyBnjO+GpEm7ckgbbm8ySXYNvUS9d9sRrw NECr0yKqM/N9lgyHlz8ZL2O7iz22WpXvFVeVIpfBBRY/O0rJRqdJ9wQgBmA563dSGO9e 93Q26vlExSNehRz+bi/uhp20YTOuQ79dX5Zq6SkWHtCBWbJDl48H+t/VsafCHfUmLV8E OWWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040133; x=1696644933; 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=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; b=NzcujD7FTO36+F/IC5DFrWq43ZTrzOsnQ67oWQDqyYXn3domD9YNpvzLf/yfajMMoE YS7yiQRof5Du7klYtTs1UkHPYTAS2PCE/2yfPKqrdZJ+us3JqAXJ3HB0X1WQBYjpoFz9 mjP05LgujFblbJuSXuev2+M0yPJQS/q9mIrMR9kchNDWb+adfuAN5Z/k5CSk+DubmScy PunuTmJ0jqzCxkYIRUmeYCoBjEL18t7xcZR1xdaPDUUKWEq/H7P+eemXMtR63K3YZckg at1AcC4jI8cM/WUtLoM/lOWN3qAZRnU+wgq1Lf2cHAlTmEP3ipDPR3izifrS6N+A5aQl 5+sA== X-Gm-Message-State: AOJu0YwtaJeqsBbAzzOvxkiR+jL06JMgR2rbzmFgmKBpBVvncs47Ez3P FI6o239bJViaDudOpitv56d8AKGDB9x2n9fu8+o= X-Received: by 2002:a05:6358:7e49:b0:142:dfc2:a441 with SMTP id p9-20020a0563587e4900b00142dfc2a441mr6732370rwm.8.1696040133172; Fri, 29 Sep 2023 19:15:33 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15: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 v6 02/19] linux-user: Tidy loader_exec Date: Fri, 29 Sep 2023 19:15:12 -0700 Message-Id: <20230930021529.987950-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c30; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc30.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: Alex Bennée 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,