From patchwork Fri Aug 11 16:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 712604 Delivered-To: patch@linaro.org Received: by 2002:adf:a390:0:b0:317:ecd7:513f with SMTP id l16csp1482152wrb; Fri, 11 Aug 2023 09:52:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESsamJUara1e5K5BLiNkUZ4JA48CctKUZB4Z7wVwPXRAy4m9B7gI0wIsHjra0LYuowNrdK X-Received: by 2002:ac8:7f95:0:b0:40f:f435:1af7 with SMTP id z21-20020ac87f95000000b0040ff4351af7mr3323565qtj.19.1691772733222; Fri, 11 Aug 2023 09:52:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691772733; cv=none; d=google.com; s=arc-20160816; b=GS/8NuwpElMM8kaSRkx5Q47bXnoZvsKfp8cpZrWHbJO1pdG7MwYibG5AX7067ml/lA 0g8eh8Giocj1I7Z32XNzloBSS2WYBSVXlgaa93xMegFkp0rwczoTQGC5fJHYBnKg5zVJ EAq6+y02zK2QVwE8AEaWzlMTY7P6Dpmtr1ESA2ZeMVZTFKvtPzArfGbrsnvcZ1ZMn7VI 2pXy8iOsWHPxcyBOFo3gILcI1rX6YcnEA4AS6HGkkg5eeYfYW1/rLkk/jxACdvxgdQCC VKnCqdYNeVhcIVEhsjiHHoNZbkbFZllhrDxswavW8udk38ElbrOSgC1iMUWekE9bMrn5 iiIw== 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=kNJidqFjxQIJ5KuZrzJozBZzMcjrUTD9AQ28ALCLCZM=; b=bAXcn0XPpdr6DW2xFOEgmUl+9dZa8oMDZgvJIojEfqVcrDQH+v1V1kxvk6pppKAqFf b/kPL6Jtv8rGwCv07Ghr09FmwxYYeno6a628ZbyGhkol5sP1DbjV0q8/27uJ85iyPXK/ V9+5bzpEvUdX+HMGV3l6OaEBbRbd4Am0gNh5iTgVGVcmzVttcWyBV+VopXe1gA9+TWRD pTTYtXqEswBWTqc1Eez4YEyHatr6nznpMuOPec3vLNJObNjBoKF4vPdqG8L/TcjDD859 uPRDa9i+RHZZraGVGtBlx4Qyzj7s6jrB14gaJAcnqqE73t3bPNl19HcrzO8YYunenfbU 8F3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QsKlJln/"; 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 n4-20020ac85b44000000b00403e8a6a4cfsi2528114qtw.333.2023.08.11.09.52.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Aug 2023 09:52:13 -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="QsKlJln/"; 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 1qUVLs-0005kC-6v; Fri, 11 Aug 2023 12:51:04 -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 1qUVLn-0005ip-Iu for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:50:59 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUVLl-0001Le-Ui for qemu-devel@nongnu.org; Fri, 11 Aug 2023 12:50:59 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bc83a96067so16148305ad.0 for ; Fri, 11 Aug 2023 09:50:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691772656; x=1692377456; 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=QsKlJln/1tTBPB5wpY0CMcxDjuYE3SYt1z6TF7b2RKj8BpD38A8CIPv+RtJjakYznV bCpG18PRps215iekak1X2REf7FuLKdJLp4LbXd64+dj/cd51f7xAX551cUCSwAGQbyvw KbO+tb1cmY7yM1zGNMXibNm2GysVemE4IKD+FX6g3sE3uznHObcIezIHOZ5dXGidVf1e VOogD2B5l0UM6Vt0GYAGjV0LvqsS23KU9qhWBAmhKX+V0ZPtSFsUfVO3d5o40xx44VMl OhfR0wypaVbsWx1kaqncTzOh7B8gUlzGRZTqZkWwMMqcp/rJJU3I7DbDdp+VxmBLqV/6 JReg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691772656; x=1692377456; 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=OeCoKvx4v/GbwNzr+mYjpDX3TsgkxopAerqVsiVJgmlNS+gdLqb8MSnz1F6RUbM6EN DcgMSR1++uruhgO8QftJV2pONpUVGWBHYQSuUQIYtr7to26khKaPOCybMcB4QQ6XqMZi jC4eR14zUN174uqR34yU+7mLk70frJyPy0EXhxahrFkfZOcq1NBs6FsdNZHtg1QOHKX9 wimRSUU3tHM36yMJQtGddSN8K+yAPhcyBDS22buUkVKXu043SUpSxxFuky9JU8pDaj5m W5UMZ/dDEakJRXc1+PdvhrTKMz/F9LOJXkyHBoRCm5QBsBufyBv9gjDYXeNvaqxRJB00 PdQg== X-Gm-Message-State: AOJu0Yznm02zuCgwbphyntK6X2JZbbogqyMnhKN4elUsIhRX/0rWcGp8 uYIg1ATUP3012JHneLONCi0r5o6AP2IPPPxzUf8= X-Received: by 2002:a17:903:11d0:b0:1bc:844:5831 with SMTP id q16-20020a17090311d000b001bc08445831mr2231945plh.57.1691772655802; Fri, 11 Aug 2023 09:50:55 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:e773:351d:2db2:8a8a]) by smtp.gmail.com with ESMTPSA id 22-20020a17090a19d600b00263d3448141sm3803713pjj.8.2023.08.11.09.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 09:50:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, pbonzini@redhat.com, philmd@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v3 02/15] linux-user: Tidy loader_exec Date: Fri, 11 Aug 2023 09:50:39 -0700 Message-Id: <20230811165052.161080-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811165052.161080-1-richard.henderson@linaro.org> References: <20230811165052.161080-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.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,