From patchwork Tue Jul 30 01:12:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 815267 Delivered-To: patch@linaro.org Received: by 2002:a5d:4acf:0:b0:367:895a:4699 with SMTP id y15csp110381wrs; Mon, 29 Jul 2024 19:18:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX7jpYM10w8nc8ZwFEfMvZgqf+k0YHV2kmnFFRPQpaB8zswBQ8USy0XQnDXZZremY3jHvYGEmVVZpJCy+HdzlKv X-Google-Smtp-Source: AGHT+IGa4eTabE9HW2Wpxsq34EcMjVTUPvxhjzC5ZDz7uNZTJKMdziU6H2bT0ShHdkGvaTyVqyTc X-Received: by 2002:a05:620a:269a:b0:79d:7ae3:4560 with SMTP id af79cd13be357-7a1e52e8affmr1390629585a.55.1722305936833; Mon, 29 Jul 2024 19:18:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1722305936; cv=none; d=google.com; s=arc-20160816; b=n2lwrg5kQHrlgDO9446zGWeo6T/1WRanm/YvYItv+zFvz5O5f0DKK8G1LKejbNCShJ 50fDWb9cOgqf3ohh3aouYjouLkFpl9puqp7lzh66QF/NOvPopNcRMFxbT8OKfvcW6PMX QuyJOQY4HUQP8VDyjqaPEE6B+j+PMtodW/IEkHUj13XnSYWoYpKpr6fU+ezP9GkfvZBQ NSo3g2d2D9qXfpgFWntk6vuCEkSLqzChQJ17xsCACzHEt5oQqlMIRJ0KIlxPt0kZcigt g3AUKH+ETDrC/t960/KRtQaPTcs/C5XdcwBauTyFEcll935YCTcAPrPZPcJli3zLCG9A GsVQ== 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=qdOOXlcI2pXCHd0E8nwCuiMDshNmFFas8R7dthZK29c=; fh=WIjd+0h1SobnuEy/kH18NIQe0QDM2lQAvclk18gpCHA=; b=TmYE7kvCl7PvfK9zw3p+CqRLMYlqqZJ68/7drc9ZZgIc9SVzNJvnN+Zj8+fU7LA7NG oul5voQKcobu9vYzL122ZJ0t+S+W8PprrsNrYicVxVC+4PVt7dhXu92RT7xClGAcEKLy f0mKDMi4/80kKfvaA+XHu3XNlXOBL26dm1c6gmZHQ1DiWEzvgbxV4POMoXenkOp9reWu 71WjmRmtCAAOVO6CHF1NMH+YPVTjQkoWJSqt1V6LBz1ZEEefeb79tvG1inKCH3gykpy2 UjDb9beWrLNYjxXkdhg5Us6s2u5fpGlZSJNXhwCwO5RZI2lS5Frt2fw+8GErnEZKitrB EVVA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hp7qOB5k; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7a1d7444cc6si1195885285a.258.2024.07.29.19.18.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jul 2024 19:18:56 -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=Hp7qOB5k; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sYcRb-00078H-EF; Mon, 29 Jul 2024 22:18:31 -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 1sYcRZ-00077d-OM for qemu-devel@nongnu.org; Mon, 29 Jul 2024 22:18:29 -0400 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sYcRY-0005zx-8X for qemu-devel@nongnu.org; Mon, 29 Jul 2024 22:18:29 -0400 Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-44fded90c41so22050061cf.3 for ; Mon, 29 Jul 2024 19:18:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1722305907; x=1722910707; 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=qdOOXlcI2pXCHd0E8nwCuiMDshNmFFas8R7dthZK29c=; b=Hp7qOB5ktSXtjnD9sAfQL7RU+ERmZ/Ugbqnrqg1WrTHnQSUiP97H/FrAszL37LzP3m pX9cDHoJ3CY+ePiU5AuX7sYYKdS9Rho7pKaMKMF8vh50iMkFiEBLYpjxKgyA168x0ocC sGQ7xy2g4Ry+SRSpaCiQGSTjQq/o2iygbfsrVl5T4TD3S86jZUGf7kldrtTCpkZjA/cB AERP6miH09vC3ulOgGA+n5uyqs+MW4Uh084CMk2RhsgeSPsVBMFW65IW3wD5+33oZ8u5 ExebmW97LhR8ZfiH04CwamDoKo6b7gO/EYe1Z+uf1cO5gez/qV1LlpzImVWxs95EZEOQ CVag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722305907; x=1722910707; 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=qdOOXlcI2pXCHd0E8nwCuiMDshNmFFas8R7dthZK29c=; b=kWguF16IST25mYBj1rGgjwDmAbPsD/y9x99seqdObWwXRikxQU7iUOYP74l9KswTeI WzQBLJ4S6lNiH/11cKGw7iAOMDQ31n9n99c/Mt1qcZYkLudcIkmzxvml7GlLgQgCIPVw EfXxUy5hGuatgTT7J13haUCmAA3X6v+f9gK2OVu0cOTCMbs9A1vjINbE5F7bMj2XJsjm rX+Huf1yZi/6b0Wd8QA//sa8/qqraOjbQeyGqsk905R1U13vL+T35YODz2IbPwO4waQI 1yDl5kDQMuGNU3IofmC/3g2nLHjrxPnqPHtn8Jhai/6O6Xgpq+TUibkoDMuBb+IW8FQM 13XQ== X-Gm-Message-State: AOJu0Yzm260h2QfW7fK/UdyQewHzw2U+rUHRoYdDlM20BqbuNoaGZJ0d sekhW15hXgzZULGSClNMU8A4FAG8Q2AdFk3ovUqPfeYKzNECwQkxhnTzGBLGBuATB1hS2j1cKzf OwvA= X-Received: by 2002:a05:6e02:178d:b0:397:3045:9dc2 with SMTP id e9e14a558f8ab-39aec4236a0mr123455735ab.27.1722301937280; Mon, 29 Jul 2024 18:12:17 -0700 (PDT) Received: from stoup.. ([203.56.128.103]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7a9f7c6ff4bsm6750206a12.4.2024.07.29.18.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 18:12:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Vivian Wang Subject: [PULL 3/5] linux-user/main: Check errno when getting AT_EXECFD Date: Tue, 30 Jul 2024 11:12:00 +1000 Message-ID: <20240730011202.480829-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240730011202.480829-1-richard.henderson@linaro.org> References: <20240730011202.480829-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::833; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x833.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 From: Vivian Wang It's possible for AT_EXECFD to end up with a valid value of 0. Check errno when using qemu_getauxval instead of return value to handle this case. Not handling this case leads to a confusing condition where the executable ends up as fd 0, i.e. stdin. Signed-off-by: Vivian Wang Reviewed-by: Richard Henderson Fixes: 0b959cf5e4cc ("linux-user: Use qemu_getauxval for AT_EXECFD") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2448 Message-ID: <20240723100545.405476-3-uwu@dram.page> Signed-off-by: Richard Henderson --- linux-user/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/main.c b/linux-user/main.c index 7d3cf45fa9..8143a0d4b0 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -755,8 +755,9 @@ int main(int argc, char **argv, char **envp) /* * Manage binfmt-misc open-binary flag */ + errno = 0; execfd = qemu_getauxval(AT_EXECFD); - if (execfd == 0) { + if (errno != 0) { execfd = open(exec_path, O_RDONLY); if (execfd < 0) { printf("Error while loading %s: %s\n", exec_path, strerror(errno));