From patchwork Thu Aug 22 09:50:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 821318 Delivered-To: patch@linaro.org Received: by 2002:adf:e98a:0:b0:367:895a:4699 with SMTP id h10csp1095578wrm; Thu, 22 Aug 2024 02:51:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUcIFsgnPUmQvNDCnTlBPYcaUJg9bYmvJT5vt6qAvERsZrpXUxSC0cbCzzmicy0cjZyzyElsQ==@linaro.org X-Google-Smtp-Source: AGHT+IHI8oVxhI0IrkfM4ZdCa113iZ7He10gxTd8Bses63e8ZSNfi343dy5FG5AgKaTAOvO80LXp X-Received: by 2002:a05:6214:5349:b0:6bf:6fd4:75c3 with SMTP id 6a1803df08f44-6c16472a35bmr12868406d6.17.1724320300188; Thu, 22 Aug 2024 02:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1724320300; cv=none; d=google.com; s=arc-20160816; b=KxOJvdVtV0ydFme6Gh7ULN0DdlShWKX3wDrKlQeNttwUfjAwsWOuDIUiYr/XDcRUYB tv5dPgHHwCBbCvr46nKuT11F2/zV2nxSue+RM5DNLMsb0duqFwqzkhWNCM33oc/HmNRX LJxVBZ+DPBUEb63BehdpKmf8TTp3lb06zyZN+YFEGPexx3hy0MOUjYsK45c9y3NkqsDD zqrZ5z+Xv9ZNbdmUHrKzTo0YO04A4DDGaZhsGg/HqpeTczmpLqUKL81xmcQENXKaiak6 yNlaokkfuZK8ARvJEtlO9lNZRnRrmKVzi0vCINv6/CmdY+KBI7SHvsjxSmEWqr2eQUZU C1vQ== 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=jQnk0OGW+ME2/AwCx9SVTlqQyyVvO6CjKhuRITvFw3A=; fh=3qYx52jRLUaUIj3+ofA0Zfhodbg6LdyfHIXEb6Qp/x8=; b=p/K5b2Ar+wC5198wl8/3nO949p7lf1DmwcG1MfzdyOmzPXBcQDgiDdPaB/dAcj83jr O+kH1cKxmVQKiOOOflO4n7UH2CPVEqrSXgDyCYaW0mL2Zc8i23YxqU5qCEzG229+U8f2 zt2ZeKbndx1NqZpnSsDBF23MgFIC2671mRR0LwPJwOWAyJ3zrbBVcEonRryfTbyw4DqG BD2Tx/Y6Xe0pzU6wSXLQqGnfRl4PKjFENoMJV8EWpAIZYnbdnqbEEAGv4TZa41V/igdw srwJyBR4m6kFH/aXN72kbJP2+wfb7wsKSLiC1ld+ctYx9w58XYnwITgieYedx/31he65 4tJw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qZKgagxg; 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 6a1803df08f44-6c162e508c7si13842246d6.588.2024.08.22.02.51.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Aug 2024 02:51:40 -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=qZKgagxg; 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 1sh4TC-0007K2-Hv; Thu, 22 Aug 2024 05:51:06 -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 1sh4TA-0007D3-BA for qemu-devel@nongnu.org; Thu, 22 Aug 2024 05:51:04 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sh4T8-0001xz-LM for qemu-devel@nongnu.org; Thu, 22 Aug 2024 05:51:04 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-42812945633so3987225e9.0 for ; Thu, 22 Aug 2024 02:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724320260; x=1724925060; 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=jQnk0OGW+ME2/AwCx9SVTlqQyyVvO6CjKhuRITvFw3A=; b=qZKgagxgYPqCoM3S436bR5J/XBuvvazpWJDY9WJvXAtafmvUE5voSDcRSO5SzneC7J LThl3RwcoyW7owTyVrCWPTyRMnmA29B+jTu6nEN+lJU+pROfwNsxQ+PxVYpQDugLPB5X /b4KkE7V8ZxamfVuW7KYpb/ts0mOEX/hIOpRq/B4O2P4DbJl8phVdOAsPr4g3dq4aFeJ zO1HpbsKSOGzJpOAz2rXO5PJ6miQ4QwkZIptktsMl3BXLrYrsuanIGY9vjdhdvdeHWAv FnNpnepQcSU7Ns/idGLDmIrb6yglrqO4QZRh/XP9uVwIpazxetLisg0x/bmSSD7j4YyO jB3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724320260; x=1724925060; 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=jQnk0OGW+ME2/AwCx9SVTlqQyyVvO6CjKhuRITvFw3A=; b=VWj9WhzBYHkKoUrf3ZrDKNBmyohssywUlvzW1KC4GS0aRx3UxJfa6XH0CfsiQMWlJX QclxueZLwiNprCk3szDjQSXKBWQ3UnM/m0iX/FlO3+6oZpW+NhGbZ6FSNpyK4caBvpzy N3cld5iLz8Wa3bP1AG2963Di867wWuzgyuu5CaZRYoGqFQfmYLB9vB9Wut0K8swppyTO aWOWMPNplVlfKAUickRMm4TNEvifI659RUWS3OOkBnqaJbuQoXWJ/l7VjX2SKeJx/HDx /We+3Fw7ZnZayYL2noGoVv5Li8P4uTIM1+HTv7RI6lPr97oWmTZY/NS3YnlujGaPSgfX xKFg== X-Gm-Message-State: AOJu0YzyLQyURM1LD/wx8/oRVTEClK0VY+QKjSJkzfUPo5dJl43uBIui i2I1mSJbyB4xtyRxkIcdkLQDMChBHruZRqbP2EqlegOD/uUWXx+z1Cte9r4mF8/ks4mzqr8MM9L u X-Received: by 2002:a5d:650b:0:b0:371:9362:c286 with SMTP id ffacd0b85a97d-372fd577056mr2924619f8f.4.1724320260355; Thu, 22 Aug 2024 02:51:00 -0700 (PDT) Received: from m1x-phil.lan ([176.187.206.153]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3730821a92csm1232696f8f.93.2024.08.22.02.50.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 22 Aug 2024 02:50:59 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Beraldo Leal , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Riku Voipio , Laurent Vivier , Cleber Rosa , Paolo Bonzini , Wainer dos Santos Moschetta Subject: [PATCH v2 2/4] linux-user/flatload: Take mmap_lock in load_flt_binary() Date: Thu, 22 Aug 2024 11:50:43 +0200 Message-ID: <20240822095045.72643-3-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240822095045.72643-1-philmd@linaro.org> References: <20240822095045.72643-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.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, T_SCC_BODY_TEXT_LINE=-0.01 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 load_flt_binary() calls load_flat_file() -> page_set_flags(). page_set_flags() must be called with the mmap_lock held, otherwise it aborts: $ qemu-arm -L stm32/lib/ stm32/bin/busybox qemu-arm: ../accel/tcg/user-exec.c:505: page_set_flags: Assertion `have_mmap_lock()' failed. Aborted (core dumped) Fix by taking the lock in load_flt_binary(). Fixes: fbd3c4cff6 ("linux-user/arm: Mark the commpage executable") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2525 Suggested-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daudé --- linux-user/flatload.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 04d8138d12..0e4be5bf44 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -487,7 +487,10 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info) stack_len += (bprm->envc + 1) * 4; /* the envp array */ + mmap_lock(); res = load_flat_file(bprm, libinfo, 0, &stack_len); + mmap_unlock(); + if (is_error(res)) { return res; }