Received: from list by lists.gnu.org with archive (Exim 4.71) id 1gHTqE-0006SP-Hv for mharc-grub-devel@gnu.org; Tue, 30 Oct 2018 09:13:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHTq9-0006NW-Dw for grub-devel@gnu.org; Tue, 30 Oct 2018 09:13:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHTq4-0006cI-8x for grub-devel@gnu.org; Tue, 30 Oct 2018 09:13:49 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:48314) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHTq3-0006a4-W2 for grub-devel@gnu.org; Tue, 30 Oct 2018 09:13:44 -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 w9UD9l2u056604; Tue, 30 Oct 2018 13:13:39 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=cmL617+RtCMTn88shRzjjXhzO6AMYRBwCu1w5cl0OcuaO4vCqrXCX2BBrRMGK/kXZ0d9 vHoH7G4y1w/mlKQ2b8ij+Y28y44qtnwDhKGpstf/VSkmhNwyY5OARdINmvl1AZ9XIwCW veiTdePfRK4Bhh0D2ch+4NvRidq7F74X7b9NEtNNcJA7BlzPgy7SgipPdmk8QoCgL5gF 47GSkO3omqwGgM/KIqWRD3AWhL0FCYvaVzkM4L09B9SI0UMYEP3MO8UIUGDO0Eb4X77N /t1N76DrY/MKKs/R65pIM4xl5Y7YtykTjUlX07DkJadPGJvxAfmC0+Ftw/SOcK+7NBmr 1w== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2ncfypv3ta-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Oct 2018 13:13:39 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9UDDcGC017181 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Oct 2018 13:13:38 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9UDDbAR022386; Tue, 30 Oct 2018 13:13:37 GMT Received: from olila.i.net-space.pl (/10.175.193.238) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 30 Oct 2018 06:13:37 -0700 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 v4 8/9] dl: Add support for persistent modules Date: Tue, 30 Oct 2018 14:12:57 +0100 Message-Id: <1540905178-28655-9-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1540905178-28655-1-git-send-email-daniel.kiper@oracle.com> References: <1540905178-28655-1-git-send-email-daniel.kiper@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9061 signatures=668683 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-1810300115 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: Tue, 30 Oct 2018 13:13:52 -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