Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5321032rdb; Wed, 13 Dec 2023 05:41:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEP4rqZOUAkRKBqDcGeRCNkRqzVTMluxKc3xlUGox3yHj824UUGvLFbuettD4tgNtLVe+d5 X-Received: by 2002:a17:903:1c4:b0:1d0:6eae:8e78 with SMTP id e4-20020a17090301c400b001d06eae8e78mr4680295plh.18.1702474912817; Wed, 13 Dec 2023 05:41:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702474912; cv=none; d=google.com; s=arc-20160816; b=lPaemwyu5mI1YN8/oJjvqemO/WgVGBpp/Hd9A3GBUsuK+ieLI3HRD42VvcpQ2eCJpx GsubLhjGvU/5z2UWu8yMCMKO36dRZ6U1lHxFtuwriMDs3GnBX6vdF+k4ZamNW4w73pdq N+pdhigPhbkrFXMNDLukk383QWoQT4yh139mPOshP1nwdqfBktSYGzvqZ/KN+ohJDPVC 45u+1P1fBIHJE9IlPQ38Mh4yB7cxekzCDwgNe0+qbaGUU9aO4BU2dcf7w4wW0aOygSOI xSq+uhqZ9Um8VqVlQqaLkGJlaZUZBiCaCCFark5E7qj2/JA1EgqrPieIBPLQqYyTFcEU 1SHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YQ49MRAnZaoKSqZNsnflibhrI2GDBa//jCKbcK+lB+o=; fh=RgqxsqY9ZqOlmURAWdfBjrEjJW7RWbnj6JWJVJqXgtM=; b=NDDsqmp62XxdmrGwaoCs+nAx/uauAxbbNn6ZF3Oi/Soko+eYR7QxpO0jxTQ9yttTsh u8sIz80fZGzgYOMBEysPXz/scqUx4uON7F02vOuptudtwBLGFGsq5W6qOjC5oZ56Qc8S K2SCVPRsQVYuBhFNSXps/ini1VU2G2b/EFLs87p1to5T0hQgFW2Bm/m8X5Uxli7IH4xF P5CKVRoq/J0xyCDlq5jIG/5Vo0Jx6flkyQKVComWuR2bgFvH3xSalmHP87oDlrcLXXJm ftOGzpc5tYLikddfYSWU8tymVszr8hxQ8jnA8n9ynqVCVYHtCA+9Qn9SNa2QCMnnRdZ2 YB0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=eZ6eGpEu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id x10-20020a170902ec8a00b001d1ccbe983asi9767093plg.383.2023.12.13.05.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 05:41:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=eZ6eGpEu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 6CB7882217B8; Wed, 13 Dec 2023 05:41:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233560AbjLMNlh (ORCPT + 99 others); Wed, 13 Dec 2023 08:41:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233511AbjLMNld (ORCPT ); Wed, 13 Dec 2023 08:41:33 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E88EF5 for ; Wed, 13 Dec 2023 05:41:39 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3363ebb277bso372257f8f.2 for ; Wed, 13 Dec 2023 05:41:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1702474898; x=1703079698; darn=vger.kernel.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=YQ49MRAnZaoKSqZNsnflibhrI2GDBa//jCKbcK+lB+o=; b=eZ6eGpEurp11HPKzhLqCy/FIwIvrgmvRNkqTxnNllZt0+89VSoYQ9hmtkcJeH+eezp KkNopDSGu7/Olrr3OgKy5Ys1X1vCszIWDIYR8uF3X2SDuzU4y9dglBBF9RlopNAx/ZKB 3+y7MKVlCKSwPhXKWsuu0KzvwpKn32+/kQ5topk09kApy/Rp5fyrusJqUzysiY5o0tdl 0r47XK0NKRQDK7u4fWFBW2RH7OiCi1ZeFY7wjmBXuMYUqbMQhtS811WPvbgQU6U8Hvg0 swZzQq1D3dl9OM0cVgyHGGLgrbAOA8VGLlz46+9MoQMqCVsGkfDgHQFC//gzj9RdqD7H 5vpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702474898; x=1703079698; 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=YQ49MRAnZaoKSqZNsnflibhrI2GDBa//jCKbcK+lB+o=; b=vJnWroRjVkS+lyAnPPprFgEI+qZtTvPtWiTRVbsS2mgJlo5C2qThK9m6689kKRKFxM mwZ75c/himJ7kTte2QQQIDp11V97qkYnfuBMF3jIBZUpAUtycd8AVsXwdV1TEazqLIuk FMIUkgLBoADv6ylyyBLe1usMcpgYs+3mecjKSPmD/cKwnGPQ41tbTM2QmC2g6q8CrhU2 AoJABghQIvHHV/VRiEUpNusEBfliUOsRmENp8ia088/P3Wxyf5Ww/l1ulPg+gc2vdg0P sNsyqHi0GWI3ceC04f7q263BuiXbiNzQvFDawiMVzaEr270EctG/xFeJCYdex/Y0/Dnq zTCg== X-Gm-Message-State: AOJu0YxFlHXCNSn3g4Z3F7SGn8/PG51gIEd+wfG22QKfgK3NMMJQrEyY bHQUbnXtDBYQQqj5BHRUb6MICgEb/jUDuAfW10w= X-Received: by 2002:a7b:c4ca:0:b0:40c:386b:9356 with SMTP id g10-20020a7bc4ca000000b0040c386b9356mr3819421wmk.72.1702474897639; Wed, 13 Dec 2023 05:41:37 -0800 (PST) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id bd21-20020a05600c1f1500b0040c25abd724sm23043332wmb.9.2023.12.13.05.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 05:41:37 -0800 (PST) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Vincent Chen , Zong Li , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Ghiti Subject: [PATCH -fixes 1/2] riscv: Fix module_alloc() that did not reset the linear mapping permissions Date: Wed, 13 Dec 2023 14:40:26 +0100 Message-Id: <20231213134027.155327-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231213134027.155327-1-alexghiti@rivosinc.com> References: <20231213134027.155327-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 13 Dec 2023 05:41:50 -0800 (PST) After unloading a module, we must reset the linear mapping permissions, see the example below: Before unloading a module: 0xffffaf809d65d000-0xffffaf809d6dc000 0x000000011d65d000 508K PTE . .. .. D A G . . W R V 0xffffaf809d6dc000-0xffffaf809d6dd000 0x000000011d6dc000 4K PTE . .. .. D A G . . . R V 0xffffaf809d6dd000-0xffffaf809d6e1000 0x000000011d6dd000 16K PTE . .. .. D A G . . W R V 0xffffaf809d6e1000-0xffffaf809d6e7000 0x000000011d6e1000 24K PTE . .. .. D A G . X . R V After unloading a module: 0xffffaf809d65d000-0xffffaf809d6e1000 0x000000011d65d000 528K PTE . .. .. D A G . . W R V 0xffffaf809d6e1000-0xffffaf809d6e7000 0x000000011d6e1000 24K PTE . .. .. D A G . X W R V The last mapping is not reset and we end up with WX mappings in the linear mapping. So add VM_FLUSH_RESET_PERMS to our module_alloc() definition. Fixes: 0cff8bff7af8 ("riscv: avoid the PIC offset of static percpu data in module beyond 2G limits") Signed-off-by: Alexandre Ghiti --- arch/riscv/kernel/module.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index aac019ed63b1..862834bb1d64 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -894,7 +894,8 @@ void *module_alloc(unsigned long size) { return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END, GFP_KERNEL, - PAGE_KERNEL, 0, NUMA_NO_NODE, + PAGE_KERNEL, VM_FLUSH_RESET_PERMS, + NUMA_NO_NODE, __builtin_return_address(0)); } #endif -- 2.39.2