Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9673713ybi; Wed, 24 Jul 2019 08:05:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLfDLMj487kYECMS4rRBdRQNWPKQKS1geiiXT6u7NObv18qm3yRH5dIeDSTFdxZMmtjHf/ X-Received: by 2002:a63:dd17:: with SMTP id t23mr54480825pgg.295.1563980717275; Wed, 24 Jul 2019 08:05:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563980717; cv=none; d=google.com; s=arc-20160816; b=sRolzZNGPrTIpapmtX7V0DqP0OaJbDJ83ddIZ6IN/IWfCj99i4liTC7PxWA6mU9b6c qgCwdb6mDeUbhQcW0rbNlvdpxEKPdZpIOph8iW0/gJc8EU71v2o5+82nR3qY0XirEdDE 5/yA+FJ/GZFb4G2goGw3nUWoEVEZktcP+VkLJ8r5NqfxbPui3y2z5syDrjf9S4kJh2IM 3feNGWyYQPnkyxok8yT/JEHDokI66L+GnuKSIh1F2B8UnWPel5ytoctOeJ2ZbYqSdyxM D6pJWZjN2GEalzjoGiy9LKWFYkYiHXgqMOYIR0PbjJ70BdOCAQ1QWVdrHAJ0jaIpZyBW c7tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=b5XeckDD1Sg0C498ItoWiGhPm+Xys+D8QfeQZliaCNs=; b=K5kzgFkO2C9t8s3lXKqSGNp/eRN1B1zla7s2b3+tTF/7TTJWrIvutu7N6nQFFpjDps NnqbaXLQRm6xlxxHnXgfV72rCXVdGZCESjJbZAXsQsHzX4oX/8tbeALEYEhPUQelBybS mh+rvxvXx+k1bDcrSkf+4+CA2Kt5F4AGiFa79aqyEWxtd1DpD8TIvnHd8LyZS/A8R318 z31V9NQHXb3TyLxt3FOtiGu8QxT24XBINx0CxdFtzRO2iOa5nbFVdKHkpMapJPpRO/vA PF6rey+c1I1rHcwg2okBByIPgEfifGQRclJpbR+vJZF7ckhpOYgyj/kye2uDx8Pgksph gwTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qqIVutvK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si17749867pla.44.2019.07.24.08.05.01; Wed, 24 Jul 2019 08:05:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qqIVutvK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387560AbfGXPCZ (ORCPT + 99 others); Wed, 24 Jul 2019 11:02:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:48962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387479AbfGXPCY (ORCPT ); Wed, 24 Jul 2019 11:02:24 -0400 Received: from linux-8ccs.suse.de (ip5f5ade6a.dynamic.kabel-deutschland.de [95.90.222.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9289B2173E; Wed, 24 Jul 2019 15:02:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563980543; bh=uc0KLI43+qaPJJDJFF/rpo4gKsEd8bljVh/ZIiawjNA=; h=From:To:Cc:Subject:Date:From; b=qqIVutvKPwM9hGOWtAPH91Lb0nSEZKUv+tBHb/WMm3Yy0HE6YOf5d+xdKr1OW8YI5 uo+NEDsUCxyqm7gr4S5UX3tuuPBCHmR/Y5mJuCHH0/aT+9Xo42wCrqpiNPIywIGhOt XQUoWQ6efQtyk9yFoUF23rxgEz1Y+b3Nd28H/idI= From: Jessica Yu To: linux-kernel@vger.kernel.org Cc: Bartosz Golaszewski , Yang Yingliang , Jian Cheng , Nadav Amit , Sekhar Nori , Kevin Hilman , David Lechner , Adam Ford , Martin Kaiser , Jessica Yu Subject: [PATCH] modules: always page-align module section allocations Date: Wed, 24 Jul 2019 17:01:56 +0200 Message-Id: <20190724150156.28526-1-jeyu@kernel.org> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some arches (e.g., arm64, x86) have moved towards non-executable module_alloc() allocations for security hardening reasons. That means that the module loader will need to set the text section of a module to executable, regardless of whether or not CONFIG_STRICT_MODULE_RWX is set. When CONFIG_STRICT_MODULE_RWX=y, module section allocations are always page-aligned to handle memory rwx permissions. On some arches with CONFIG_STRICT_MODULE_RWX=n however, when setting the module text to executable, the BUG_ON() in frob_text() gets triggered since module section allocations are not page-aligned when CONFIG_STRICT_MODULE_RWX=n. Since the set_memory_* API works with pages, and since we need to call set_memory_x() regardless of whether CONFIG_STRICT_MODULE_RWX is set, we might as well page-align all module section allocations for ease of managing rwx permissions of module sections (text, rodata, etc). Fixes: 2eef1399a866 ("modules: fix BUG when load module with rodata=n") Reported-by: Martin Kaiser Reported-by: Bartosz Golaszewski Tested-by: David Lechner Tested-by: Martin Kaiser Signed-off-by: Jessica Yu --- kernel/module.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kernel/module.c b/kernel/module.c index 5933395af9a0..cd8df516666d 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -64,14 +64,9 @@ /* * Modules' sections will be aligned on page boundaries - * to ensure complete separation of code and data, but - * only when CONFIG_STRICT_MODULE_RWX=y + * to ensure complete separation of code and data */ -#ifdef CONFIG_STRICT_MODULE_RWX # define debug_align(X) ALIGN(X, PAGE_SIZE) -#else -# define debug_align(X) (X) -#endif /* If this is set, the section belongs in the init part of the module */ #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) -- 2.16.4