From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1g7db9-0003Sm-7E for mharc-grub-devel@gnu.org; Wed, 03 Oct 2018 05:37:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7db7-0003Rz-9Y for grub-devel@gnu.org; Wed, 03 Oct 2018 05:37:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7db4-0007xy-Db for grub-devel@gnu.org; Wed, 03 Oct 2018 05:37:37 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:39948) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7db4-0007vp-4L for grub-devel@gnu.org; Wed, 03 Oct 2018 05:37:34 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w939Suuv030441; Wed, 3 Oct 2018 09:37:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=hK7RadqB43OICoMCY7FIdIAgwYtyi/kcfMQLh5qUdZM=; b=QyGMk8iM9dqOsw4YfqfFmKIFZR6zf/2ElRT9vOAQYELBJGgg77KxiiW8U0hI03OAQAXs VFLz/44IZoTqmGECHNPHHSk9itriJkasWreSZIlMi3HGEhQxvvc1n2tFhR2Z0tmdHB/N 8mID6XPaMjeZMK9V5v4V7g1hgyDWX0n/aNa7GAehqvOYpoOJJJLqX/mNPtYP71mQmsyQ V5g9BQSiKH4d2cyrt19yGSxbUvBsEDlc+4Ka7nMTgVrqUTmpj3Hbt4luerF2oEhK0Fo5 F1PX1ObMaICmjYQW48dqwZtcj9cOA3Dy8rJL6Vkb14DCtGw5F9ze/Ry3PrPu6eD1AlpC +Q== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2mt1bq2rnb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 03 Oct 2018 09:37:32 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w939bVWo022349 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 3 Oct 2018 09:37:32 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w939bVTQ030303; Wed, 3 Oct 2018 09:37:31 GMT Received: from olila.i.net-space.pl (/10.175.216.132) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 03 Oct 2018 09:37:31 +0000 From: Daniel Kiper To: grub-devel@gnu.org Cc: dpsmith.dev@gmail.com, eric.snowberg@oracle.com, javierm@redhat.com, jonmccune@google.com, kanth.ghatraju@oracle.com, keng-yu.lin@hpe.com, konrad.wilk@oracle.com, leif.lindholm@linaro.org, mjg59@srcf.ucam.org, phcoder@gmail.com, philip.b.tricca@intel.com, ross.philipson@oracle.com Subject: [PATCH v3 7/8] dl: Add support for persistent modules Date: Wed, 3 Oct 2018 11:36:54 +0200 Message-Id: <1538559415-6233-8-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1538559415-6233-1-git-send-email-daniel.kiper@oracle.com> References: <1538559415-6233-1-git-send-email-daniel.kiper@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9034 signatures=668707 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810030096 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.78 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Oct 2018 09:37:38 -0000 This type of modules cannot be unloaded. This is useful if a given functionality, e.g. UEFI secure boot shim signature verification, should not be disabled if it was enabled at some point in time. Somebody may say that we can use standalone GRUB2 here. That is true. However, the code is not so big nor complicated hence it make sense to support modularized configs too. Signed-off-by: Daniel Kiper --- grub-core/commands/minicmd.c | 3 +++ include/grub/dl.h | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/grub-core/commands/minicmd.c b/grub-core/commands/minicmd.c index fc20c65..6bbce31 100644 --- a/grub-core/commands/minicmd.c +++ b/grub-core/commands/minicmd.c @@ -137,6 +137,9 @@ grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)), if (! mod) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module"); + if (grub_dl_is_persistent (mod)) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "cannot unload persistent module"); + if (grub_dl_unref (mod) <= 0) grub_dl_unload (mod); diff --git a/include/grub/dl.h b/include/grub/dl.h index 2bca56c..fee27a1 100644 --- a/include/grub/dl.h +++ b/include/grub/dl.h @@ -175,6 +175,7 @@ struct grub_dl { char *name; int ref_count; + int persistent; grub_dl_dep_t dep; grub_dl_segment_t segment; Elf_Sym *symtab; @@ -240,6 +241,18 @@ grub_dl_get (const char *name) return 0; } +static inline void +grub_dl_set_persistent (grub_dl_t mod) +{ + mod->persistent = 1; +} + +static inline int +grub_dl_is_persistent (grub_dl_t mod) +{ + return mod->persistent; +} + #endif grub_err_t grub_dl_register_symbol (const char *name, void *addr, -- 1.7.10.4