From patchwork Tue Aug 23 22:05:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 599490 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp2741085mae; Tue, 23 Aug 2022 15:15:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR4UT6ua12iGusnCxVf2IfwgXRHTp8D1Vt3va2m0RBJvgs9JQdKuCTjvebjMUL3gtAaAQtxi X-Received: by 2002:a05:6214:1c87:b0:46b:c547:543d with SMTP id ib7-20020a0562141c8700b0046bc547543dmr22482537qvb.52.1661292958554; Tue, 23 Aug 2022 15:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661292958; cv=none; d=google.com; s=arc-20160816; b=yOQvc9D0NRE+npOvICk2gaKSUt1sviB8I7XPg2pOazIpsUBEaco4rbij+XTlpSp+EY 1YfcOyMWb0rL4EPBqCNrztY32E6lpgMGxLss7pWBliu7nkMAC6c7PoStOLn2lZcGcGfA MN3IeWwDzB5RDgsMJ1+OI1F0gdubEfjaToehssWTcHjS7Yzii6TNUbrLWxRp1PDsxCJc Gk+mOvDvCh5ndPH6MXRsY8Yr/r9A4Z6UZhZikkeRQp7L0Thgwje3+7FtGo8qNQR2j66k d82YZTljUcyNmfbFsRpFwwh2hnMWetYGtAdbJUGVtb4u6dgD0h00jUeu/jp/pya13LLO KFpw== 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=mJbPfVNUzEC2twD2g02EAHj57nKEYqjpuPLLVGphZY4=; b=ewlZ6kHdnywH+Q+qL/11KfgIJ1q844ilbKLU9byYAM4yP2JjiD0NCKOEaV3J4+nwLc niqlXYIuUTqm3mCoxAh+lA1/UxM5zUFj+FOPTN7WS/2cFkwdmup05nQNYvFLwpV7uvku U4xXr9rvGbS4MscQKVGqJ7t0vzeKdi6EXaLsE5WucznXKLe1fNOsCLMomEtd9ghZdzwE P6nLqCaTj6x6jw2cmzHiU9Xu32LMarxli/pXO5oOBK5UEi/qoTCfA6gyIuMGmBQF1NLt mSe5et1N/YM5hpSTL8/yv0a4z0z55YjEtsBZfxAsBYMGisuCRTL/DLuiOyPhkvkdA6Yl opAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nNnzBMcq; 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 v2-20020a37dc02000000b006bc542f160fsi569478qki.189.2022.08.23.15.15.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Aug 2022 15:15:58 -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=nNnzBMcq; 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]:53054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQcBi-00007F-3e for patch@linaro.org; Tue, 23 Aug 2022 18:15:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQc22-0008Tu-Ul for qemu-devel@nongnu.org; Tue, 23 Aug 2022 18:05:58 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:46025) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQc1w-0001QH-TX for qemu-devel@nongnu.org; Tue, 23 Aug 2022 18:05:58 -0400 Received: by mail-pf1-x42f.google.com with SMTP id z187so14704396pfb.12 for ; Tue, 23 Aug 2022 15:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=mJbPfVNUzEC2twD2g02EAHj57nKEYqjpuPLLVGphZY4=; b=nNnzBMcqqEqesYv5MBMcs7ZKhGfaeIAbI0u0D80LNn/A2awibI2/VAbw6gjV5KJFVW +iNzcrShUnqQ4L1RiDceryFMYGnaou/D0W2qgZG0wwH7BoBdaLLBJ3plngqfr2xt3A7V Iy1TeFTu+IMtC4l12yMntT6I7RHvYcDLLecSG/06hR599qTta0Zui6xNyp1OPy4gCvCQ tQQcu1uZoo5sCW++oxzNdHPIQtTjp9syLccgano/HO9xoZEQYdNJalfxXU5uw4D2tUZg 6hq4l7/HpPYoqewDtg+oVRUN37WtylzKvJC3PDWNa0zgOMKP5WgCGyK9YgZSoZMP9AUh QWzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=mJbPfVNUzEC2twD2g02EAHj57nKEYqjpuPLLVGphZY4=; b=cCPS+6jvIWNLLzOp27AdnMK0na7y0ROAF2wVjeZMnqlmGkiBP1EqXKEfBqGw80GLdQ yVbb+tLZ3R31vuEMgmo7eLAIIeGsaqGtbq0OYg7vMN/Ykv8Skx+mYght8kEu3hx5kwsl iYW65rcMalGx2dHxzltDax8O4qhnRwp89tjyZHYaqZ8Hm6ceqti0/Pn9d7pBaktlROHy H0oLKYWNA8J5TqB8NxCSyscY0Po80tAkPZCn8d5MeOX/qgFLgkQVRjrVo6643DWfht/B nrQdeg1/+D8ZmTzs9AiEtYWXhCqMPAJXIfm26HuAdmcfOJzPAkSzWrfzk39oCKuPAYvg ItsA== X-Gm-Message-State: ACgBeo1IPapq5o1Mm2dXJ0EHKtpZjMApT+w782vPqP7Nw1heynGC6uIq HP9jux+peoidTmarHmwPlH4dspwQqK+Wmg== X-Received: by 2002:a05:6a00:1a0c:b0:528:6baa:a2e3 with SMTP id g12-20020a056a001a0c00b005286baaa2e3mr27201936pfv.27.1661292350500; Tue, 23 Aug 2022 15:05:50 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:46f9:77b4:ec0a:c2d9]) by smtp.gmail.com with ESMTPSA id n12-20020a170902f60c00b0017292073839sm11020974plg.178.2022.08.23.15.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 15:05:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: iii@linux.ibm.com, laurent@vivier.eu, alex.bennee@linaro.org Subject: [PATCH v7 05/20] linux-user: Clear translations and tb_jmp_cache on mprotect() Date: Tue, 23 Aug 2022 15:05:27 -0700 Message-Id: <20220823220542.1993395-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220823220542.1993395-1-richard.henderson@linaro.org> References: <20220823220542.1993395-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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" From: Ilya Leoshkevich Currently it's possible to execute pages that do not have PAGE_EXEC if there is an existing translation block. Fix by clearing tb_jmp_cache and invalidating TBs, which forces recheck of permission bits. Signed-off-by: Ilya Leoshkevich Message-Id: <20220817150506.592862-2-iii@linux.ibm.com> [rth: Invalidate is required -- e.g. riscv fallthrough cross test] Signed-off-by: Richard Henderson fixup mprotect --- linux-user/mmap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 048c4135af..e9dc8848be 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -115,6 +115,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) { abi_ulong end, host_start, host_end, addr; int prot1, ret, page_flags, host_prot; + CPUState *cpu; trace_target_mprotect(start, len, target_prot); @@ -177,7 +178,14 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) goto error; } } + page_set_flags(start, start + len, page_flags); + tb_invalidate_phys_range(start, start + len); + + CPU_FOREACH(cpu) { + cpu_tb_jmp_cache_clear(cpu); + } + mmap_unlock(); return 0; error: