From patchwork Tue Jul 6 23:49:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 470568 Delivered-To: patch@linaro.org Received: by 2002:a17:906:971a:0:0:0:0 with SMTP id k26csp5546277ejx; Tue, 6 Jul 2021 16:53:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8+kSsd89CqBD7LRpkbGVtNtXzIp8j58kZ7T8sDUTkJmhlIARNruK8X5eT+lO9mBuSL/MH X-Received: by 2002:ac8:5806:: with SMTP id g6mr19633781qtg.112.1625615601626; Tue, 06 Jul 2021 16:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625615601; cv=none; d=google.com; s=arc-20160816; b=c3ZnK51HdQQqeLn++i8AoJt+jpkcfMz+Y6VyMkDI7grM0lccfhP8JohaA9VcqD29CE wZRtgi7wJKBuS9R1/UqlJrsc5EMwTQap9ObemQX+TM+gluHDU1B3iKvIpprndB/PQhgp gnEPzw8Or+afy2QRBYUGHOM7yJFIN+mkhc8Qk8V8LJHcNcMjY66A6Wq6Bzi3Q+a7MQ+v Py2mYxeVQKArBOTUkjbK6BQu64uBizP+vWgk4FMn8oWVFzQRACNUeF7RCQZoVZKIcjmJ Z114yHUzLsFO5ADAU8JSYKTmUNfQ587ov1o3v0775CF++WUzvvZMCydIUUFcqkrLd3+l NSIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=wioVJQ/qJN1JlStivyXRtbsJrj3TcKHRu6e6gkEsf2amZdUt4ChEuAzqh9JO23J1Pq 7BG142JMSE5AhnI7BCrgG72K5PeG4Tlj41hb9BKRfu8JHAqA7A8iZ7FI8IgYRqWYprte KKl0bMTAbN6VL+xKo1V68zl7dZVTlStwOvb8FVK/279+aHXpiUxgO44iJs7MFKct3qj5 EO2FpqGzLKCGZxleMWkv3gi5rZntVwngx7/OkgSIJFdc3h7W3OMYxgN5+OMBhKa9IK3w /gSNMfq2441ZkmmmFaesqJJujn2CryxQl7XB6/PskjaiohU4KHdKBwDqsBnO1poxYdOC 5Wxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WpSFoxlf; 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=fail (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 p23si7353386qtn.52.2021.07.06.16.53.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Jul 2021 16:53:21 -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=fail header.i=@linaro.org header.s=google header.b=WpSFoxlf; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0usS-0006TP-UM for patch@linaro.org; Tue, 06 Jul 2021 19:53:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0uot-0000iK-5F for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:39 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:39927) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m0uor-0006b9-DT for qemu-devel@nongnu.org; Tue, 06 Jul 2021 19:49:38 -0400 Received: by mail-pg1-x52e.google.com with SMTP id a2so402734pgi.6 for ; Tue, 06 Jul 2021 16:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=WpSFoxlfzzIrc6qgT2OGQuRqAfSdzz4uAIuOgSIFmrguCwTGC+5rTefv5ailwYid2e OnW0G0HvJJ3+cbewcNf9P1+uAE/K6Kv7aOgEsOqROShxIMghCZyKdo103D9izV/bFSZz 6aYZ5NHDmNUd3TZLZ5qJ2MkQt0SjQe33g5dtF7uIrSWTCwiGWCOrp1YUuXI5QCnsl8D5 gtpPGB1v1S6u82HEW85+aALz7r34ACUJ5RkA2HbJqwWNbseNsiHQ7x8JSgcvuQfe83k+ feVbf5/N0FlJg4CcdYJ9mjKYGu4MNJn+WGqm+44APrq/eiTgA0J4emzY5aGrxNWLKyaC MQ8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=cDm2A1qCT2fFfjp+Fuq3+AvTcCqUS3c/9Sd37WSBsp66rKau5LDSSK4Z7zrQ+t0arf AAQVgjvjcJ2zVOH5vyUk8jX05/Fmas0auKditPXf74/s/Dy71mbnrCv4AOUDSImxul9r jYzHBqMoWzOss9Quc7TGHcGoKdLsTQyUUGVchSOSreiH+fBMkGhKpi62LMg7Ucg5OJAZ s+XYJdl2jLODTTA+qUcMphlosY5O6ryev/1Yxrmo+apzXAn/dpsirtw+DrM8PkNz1yH4 0ojn+U4yDi9QmAIIoP55IChQxhCwOJGVVzousEiyqAiFJXOIVabWThTxS+LZQjYFsVvu gIBw== X-Gm-Message-State: AOAM533xqRsLZeFqyPrNS6doF1/e3XGvtc0BJDzmBmqXlN61uq43jc9R dkHFlnBnm9/Zo00BnwWuNiFVREgfNwjQUw== X-Received: by 2002:a63:d612:: with SMTP id q18mr23365770pgg.77.1625615375948; Tue, 06 Jul 2021 16:49:35 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id b3sm18058114pfi.179.2021.07.06.16.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 16:49:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/36] linux-user: Tidy loader_exec Date: Tue, 6 Jul 2021 16:49:00 -0700 Message-Id: <20210706234932.356913-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210706234932.356913-1-richard.henderson@linaro.org> References: <20210706234932.356913-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reorg the if cases to reduce indentation. Test for 4 bytes in the file before checking the signatures. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/linuxload.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) -- 2.25.1 diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 3b0bafc490..8b93b9704c 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -143,31 +143,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,