| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/15 11:54 | flow | patch-triage |
6mArgs:null Results: {
"EnableConfigs": [
"KEXEC_HANDOVER",
"LIVEUPDATE",
"LIVEUPDATE_MEMFD",
"MEMFD_CREATE",
"SHMEM"
],
"FocusSymbols": [
"luo_session_freeze",
"luo_preserve_file",
"luo_retrieve_file",
"liveupdate_claim_file",
"liveupdate_unclaim_file",
"memfd_luo_get_tmpfs_file",
"memfd_luo_preserve",
"memfd_luo_retrieve"
],
"KMSANReasoning": "The patch series extends the Live Update Orchestrator (LUO) and memfd/tmpfs preservation mechanism by adding early session freeze support, a user argument passing mechanism for file handlers (with support for preserving/restoring generic linked tmpfs files), and retryable retrieve error handling.\n\nAn evaluation of memory initialization and leak risks shows:\n1. Kernel-to-user copies: The ioctl handlers (LIVEUPDATE_SESSION_PRESERVE_FD, LIVEUPDATE_SESSION_RETRIEVE_FD, LIVEUPDATE_SESSION_FREEZE) use copy_struct_from_user() into the stack buffer and luo_ucmd_respond() to copy back data. The relevant structures (struct liveupdate_session_preserve_fd, struct liveupdate_session_retrieve_fd, struct liveupdate_session_freeze) have naturally aligned 32-bit and 64-bit members with zero padding holes. copy_struct_from_user() explicitly zero-fills any trailing bytes when user-space provides a smaller structure.\n2. Handler arguments: In luo_copy_user_arg(), the kernel buffer is populated via copy_struct_from_user(), ensuring all bytes up to spec-\u003esize are initialized before being passed into handler callbacks.\n3. Heap/KHO allocations: luo_session is allocated with kzalloc_obj(), and the preserved serialization structure struct memfd_luo_ser is allocated using kho_alloc_preserve() which uses __GFP_ZERO. All local liveupdate_file_op_args instances are zero-initialized with '= {0}'.\n4. Folio operations: The restored tmpfs folio handling relies on page cache and KHO folio handover, operating on existing folios without introducing uninitialized reads or uninitialized page exposures.\n\nThe potential issues introduced by this patch involve concurrency, locking order (inode_lock vs session mutex), reference counting (fget/fput, get_file), and resource tracking (xarray insert/erase, unclaim cleanup on failure). These failure modes fall squarely into the domains of KASAN (use-after-free, memory corruption) and LOCKDEP (locking bugs, deadlocks), and do not present uninitialized memory risks. Therefore, a dedicated KMSAN session is not justified.",
"NeedsKMSAN": false,
"Reasoning": "The patch introduces the LIVEUPDATE_SESSION_FREEZE ioctl command, support for user-supplied arguments during file preservation and retrieval in the Live Update Orchestrator (LUO), and extends memfd preservation to arbitrary tmpfs files. These paths are exposed to userspace via /dev/liveupdate and session file descriptors, modifying core state management, file descriptor validation, and tmpfs folio handling. Fuzzing is warranted to test early freeze state transitions, user argument parsing, and tmpfs retrieval error recovery.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/15 11:54 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 73221d66de0cb87d5537af6ff35cba50bed7c783\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Thu Oct 15 11:54:43 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/include/linux/kho/abi/memfd.h b/include/linux/kho/abi/memfd.h\nindex 08b10fea2afc8..47ff5ab967501 100644\n--- a/include/linux/kho/abi/memfd.h\n+++ b/include/linux/kho/abi/memfd.h\n@@ -68,7 +68,18 @@ struct memfd_luo_folio_ser {\n \t\t\t F_SEAL_EXEC)\n \n /**\n- * struct memfd_luo_ser - Main serialization structure for a memfd.\n+ * MEMFD_LUO_FLAG_TMPFS - The preserved file is a tmpfs file.\n+ *\n+ * Indicates the file was preserved from a linked tmpfs file rather than an\n+ * anonymous memfd, and must be retrieved to an empty tmpfs file.\n+ */\n+#define MEMFD_LUO_FLAG_TMPFS\t\tBIT(0)\n+\n+/* The set of flags this version supports preserving. */\n+#define MEMFD_LUO_ALL_FLAGS\t\tMEMFD_LUO_FLAG_TMPFS\n+\n+/**\n+ * struct memfd_luo_ser - Main serialization structure for a memfd or tmpfs file.\n * @pos: The file's current position (f_pos).\n * @size: The total size of the file in bytes (i_size).\n * @seals: The seals present on the memfd. The seals are uABI so it is safe\ndiff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h\nindex 63ea5417de849..4e1f0f4cbd6fb 100644\n--- a/include/linux/liveupdate.h\n+++ b/include/linux/liveupdate.h\n@@ -22,14 +22,48 @@ struct liveupdate_flb;\n struct liveupdate_session;\n struct file;\n \n+/**\n+ * struct liveupdate_arg_spec - Specification of a file handler user argument.\n+ * @size: Full size of the argument structure in the current kernel.\n+ * @min_size: Minimum valid user-supplied size (offsetofend of the last\n+ * required field).\n+ */\n+struct liveupdate_arg_spec {\n+\tsize_t size;\n+\tsize_t min_size;\n+};\n+\n+/**\n+ * LIVEUPDATE_ARG - Validated specification of a file handler argument struct.\n+ * @_struct: The argument structure type.\n+ * @_min_last: The last required member in @_struct.\n+ *\n+ * All file handler argument structures passed via\n+ * \u0026liveupdate_session_preserve_fd.arg or \u0026liveupdate_session_retrieve_fd.arg\n+ * must begin with a 32-bit @size field so they can be extended compatibly.\n+ * Use this macro to initialize \u0026liveupdate_file_ops.parg and\n+ * \u0026liveupdate_file_ops.rarg.\n+ */\n+#define LIVEUPDATE_ARG(_struct, _min_last)\t\t\t\t\\\n+\t{\t\t\t\t\t\t\t\t\\\n+\t\t.size = sizeof(_struct) +\t\t\t\t\\\n+\t\t\tBUILD_BUG_ON_ZERO(offsetof(_struct, size) != 0) + \\\n+\t\t\tBUILD_BUG_ON_ZERO(sizeof_field(_struct, size) != sizeof(u32)), \\\n+\t\t.min_size = offsetofend(_struct, _min_last),\t\t\\\n+\t}\n+\n /**\n * struct liveupdate_file_op_args - Arguments for file operation callbacks.\n * @handler: The file handler being called.\n * @retrieve_status: The retrieve status for the 'can_finish / finish'\n * operation. A value of 0 means the retrieve has not been\n- * attempted, a positive value means the retrieve was\n- * successful, and a negative value means the retrieve failed,\n- * and the value is the error code of the call.\n+ * attempted (or only failed with a retryable error), a\n+ * positive value means the retrieve was successful, and a\n+ * negative value means the retrieve permanently failed, and\n+ * the value is the error code of the call.\n+ * @retryable: For .retrieve(): [OUT] Set to true by the callback on\n+ * error when the preserved state has not been consumed and\n+ * retrieval may be retried.\n * @file: The file object. For retrieve: [OUT] The callback sets\n * this to the new file. For other ops: [IN] The caller sets\n * this to the file being operated on.\n@@ -39,6 +73,11 @@ struct file;\n * is not preserved. Set by the handler's .preserve()\n * callback, and must be freed in the handler's\n * .unpreserve() callback.\n+ * @arg: Kernel copy of the user-provided argument for .preserve()\n+ * and .retrieve(), or %NULL if none was provided. Allocated\n+ * to the handler's expected argument size with any trailing\n+ * bytes beyond the user-supplied size zero-filled. Valid\n+ * only for the duration of the callback.\n *\n * This structure bundles all parameters for the file operation callbacks.\n * The 'data' and 'file' fields are used for both input and output.\n@@ -46,9 +85,11 @@ struct file;\n struct liveupdate_file_op_args {\n \tstruct liveupdate_file_handler *handler;\n \tint retrieve_status;\n+\tbool retryable;\n \tstruct file *file;\n \tu64 serialized_data;\n \tvoid *private_data;\n+\tconst void *arg;\n };\n \n /**\n@@ -57,7 +98,8 @@ struct liveupdate_file_op_args {\n * compatible with the given file.\n * @preserve: Required. Performs state-saving for the file.\n * @unpreserve: Required. Cleans up any resources allocated by @preserve.\n- * @freeze: Optional. Final actions just before kernel transition.\n+ * @freeze: Optional. Prepares final state before kexec (via\n+ * LIVEUPDATE_SESSION_FREEZE or during reboot).\n * @unfreeze: Optional. Undo freeze operations.\n * @retrieve: Required. Restores the file in the new kernel.\n * @can_finish: Optional. Check if this FD can finish, i.e. all restoration\n@@ -66,6 +108,12 @@ struct liveupdate_file_op_args {\n * resources in the session.\n * @finish: Required. Final cleanup in the new kernel.\n * @get_id: Optional. Returns a unique identifier for the file.\n+ * @parg: Optional. Specification of the user argument structure\n+ * accepted by @preserve, initialized via LIVEUPDATE_ARG(). If\n+ * unset, non-zero user arguments are rejected with -EOPNOTSUPP.\n+ * @rarg: Optional. Specification of the user argument structure\n+ * accepted by @retrieve, initialized via LIVEUPDATE_ARG(). If\n+ * unset, non-zero user arguments are rejected with -EOPNOTSUPP.\n * @owner: Module reference\n *\n * All operations (except can_preserve) receive a pointer to a\n@@ -82,6 +130,8 @@ struct liveupdate_file_ops {\n \tbool (*can_finish)(struct liveupdate_file_op_args *args);\n \tvoid (*finish)(struct liveupdate_file_op_args *args);\n \tunsigned long (*get_id)(struct file *file);\n+\tstruct liveupdate_arg_spec parg;\n+\tstruct liveupdate_arg_spec rarg;\n \tstruct module *owner;\n };\n \n@@ -236,6 +286,11 @@ int liveupdate_reboot(void);\n int liveupdate_register_file_handler(struct liveupdate_file_handler *fh);\n void liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh);\n \n+int liveupdate_claim_file(struct liveupdate_file_handler *fh,\n+\t\t\t struct file *file);\n+void liveupdate_unclaim_file(struct liveupdate_file_handler *fh,\n+\t\t\t struct file *file);\n+\n int liveupdate_register_flb(struct liveupdate_file_handler *fh,\n \t\t\t struct liveupdate_flb *flb);\n void liveupdate_unregister_flb(struct liveupdate_file_handler *fh,\n@@ -268,6 +323,17 @@ static inline void liveupdate_unregister_file_handler(struct liveupdate_file_han\n {\n }\n \n+static inline int liveupdate_claim_file(struct liveupdate_file_handler *fh,\n+\t\t\t\t\tstruct file *file)\n+{\n+\treturn -EOPNOTSUPP;\n+}\n+\n+static inline void liveupdate_unclaim_file(struct liveupdate_file_handler *fh,\n+\t\t\t\t\t struct file *file)\n+{\n+}\n+\n static inline int liveupdate_register_flb(struct liveupdate_file_handler *fh,\n \t\t\t\t\t struct liveupdate_flb *flb)\n {\ndiff --git a/include/uapi/linux/liveupdate.h b/include/uapi/linux/liveupdate.h\nindex 4043d40387125..24e938d91392c 100644\n--- a/include/uapi/linux/liveupdate.h\n+++ b/include/uapi/linux/liveupdate.h\n@@ -60,6 +60,7 @@ enum {\n \tLIVEUPDATE_CMD_SESSION_RETRIEVE_FD = 0x41,\n \tLIVEUPDATE_CMD_SESSION_FINISH = 0x42,\n \tLIVEUPDATE_CMD_SESSION_GET_NAME = 0x43,\n+\tLIVEUPDATE_CMD_SESSION_FREEZE = 0x44,\n };\n \n /**\n@@ -126,6 +127,8 @@ struct liveupdate_ioctl_retrieve_session {\n * @size: Input; sizeof(struct liveupdate_session_preserve_fd)\n * @fd: Input; The user-space file descriptor to be preserved.\n * @token: Input; An opaque, unique token for preserved resource.\n+ * @arg: Input; User-space pointer to a file-handler-specific argument\n+ * structure starting with a 32-bit size field, or 0 if unused.\n *\n * Holds parameters for preserving a file descriptor.\n *\n@@ -149,6 +152,7 @@ struct liveupdate_session_preserve_fd {\n \t__u32\t\tsize;\n \t__s32\t\tfd;\n \t__aligned_u64\ttoken;\n+\t__aligned_u64\targ;\n };\n \n #define LIVEUPDATE_SESSION_PRESERVE_FD\t\t\t\t\t\\\n@@ -160,6 +164,8 @@ struct liveupdate_session_preserve_fd {\n * @fd: Output; The new file descriptor representing the fully restored\n * kernel resource.\n * @token: Input; An opaque, token that was used to preserve the resource.\n+ * @arg: Input; User-space pointer to a file-handler-specific argument\n+ * structure starting with a 32-bit size field, or 0 if unused.\n *\n * Retrieve a previously preserved file descriptor.\n *\n@@ -169,9 +175,10 @@ struct liveupdate_session_preserve_fd {\n * associated with the token and populates the @fd field with a new file\n * descriptor referencing the restored resource in the current (new) kernel.\n * This operation must be performed *before* signaling completion via\n- * %LIVEUPDATE_IOCTL_FINISH. If a retrieve of a token fails, subsequent\n- * attempts to retrieve the token fail with the same error code. Failed\n- * retrieves are not retried.\n+ * %LIVEUPDATE_IOCTL_FINISH. If a retrieve of a token fails after consuming\n+ * preserved state, subsequent attempts to retrieve the token fail with the\n+ * same error code. Early argument or target validation errors before\n+ * preserved state is consumed leave the token intact and may be retried.\n *\n * Return: 0 on success, negative error code on failure (e.g., invalid token).\n */\n@@ -179,6 +186,7 @@ struct liveupdate_session_retrieve_fd {\n \t__u32\t\tsize;\n \t__s32\t\tfd;\n \t__aligned_u64\ttoken;\n+\t__aligned_u64\targ;\n };\n \n #define LIVEUPDATE_SESSION_RETRIEVE_FD\t\t\t\t\t\\\n@@ -236,4 +244,49 @@ struct liveupdate_session_get_name {\n #define LIVEUPDATE_SESSION_GET_NAME\t\t\t\t\t\\\n \t_IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_GET_NAME)\n \n+/**\n+ * struct liveupdate_session_freeze - ioctl(LIVEUPDATE_SESSION_FREEZE)\n+ * @size: Input; sizeof(struct liveupdate_session_freeze)\n+ * @reserved: Input; Must be zero. Reserved for future use.\n+ *\n+ * Freezes the session early from userspace before the reboot kexec phase.\n+ *\n+ * When this ioctl is called, the kernel executes the .freeze() callback on all\n+ * preserved files in the session and serializes their metadata. Once frozen,\n+ * no further files can be preserved in the session.\n+ *\n+ * During the subsequent reboot kexec, this session is recognized as already\n+ * frozen and is skipped from the late auto freeze.\n+ *\n+ * Return: 0 on success, negative error code on failure.\n+ */\n+struct liveupdate_session_freeze {\n+\t__u32\t\tsize;\n+\t__u32\t\treserved;\n+};\n+\n+#define LIVEUPDATE_SESSION_FREEZE\t\t\t\t\t\\\n+\t_IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_FREEZE)\n+\n+/**\n+ * struct liveupdate_memfd_retrieve_arg - Argument for tmpfs file retrieval\n+ * @size: Input; sizeof(struct liveupdate_memfd_retrieve_arg)\n+ * @fd: Input; Writable, empty, linked tmpfs file descriptor to restore into.\n+ *\n+ * Passed via \u0026struct liveupdate_session_retrieve_fd.arg on\n+ * %LIVEUPDATE_SESSION_RETRIEVE_FD. This argument is required when retrieving\n+ * a preserved linked tmpfs file and is rejected with -EINVAL when retrieving\n+ * an anonymous memfd.\n+ *\n+ * @fd must refer to a writable, empty, linked tmpfs file that is not already\n+ * claimed by LUO. On success, the file is populated with the preserved folios,\n+ * its size and f_pos are restored, and the file descriptor returned in\n+ * \u0026struct liveupdate_session_retrieve_fd.fd references the same underlying open\n+ * file description as @fd.\n+ */\n+struct liveupdate_memfd_retrieve_arg {\n+\t__u32\t\tsize;\n+\t__s32\t\tfd;\n+};\n+\n #endif /* _UAPI_LIVEUPDATE_H */\ndiff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c\nindex c39f96961a85b..5c2ffec696885 100644\n--- a/kernel/liveupdate/luo_file.c\n+++ b/kernel/liveupdate/luo_file.c\n@@ -31,9 +31,9 @@\n * - unpreserve(): Cleans up any resources allocated by .preserve(), called\n * if the preservation process is aborted before the reboot (i.e. session is\n * closed).\n- * - freeze(): A final pre-reboot opportunity to prepare the state for kexec.\n- * We are already in reboot syscall, and therefore userspace cannot mutate\n- * the file anymore.\n+ * - freeze(): Prepares the final state for kexec. Invoked either early via\n+ * the LIVEUPDATE_SESSION_FREEZE ioctl once userspace is done modifying\n+ * the session's files, or during the reboot() syscall.\n * - unfreeze(): Undoes the actions of .freeze(), called if the live update\n * is aborted after the freeze phase.\n * - retrieve(): Reconstructs the file in the new kernel from the preserved\n@@ -48,7 +48,8 @@\n * handler, calls its .preserve() operation, and creates an internal \u0026struct\n * luo_file to track the live state.\n *\n- * 2. Freeze (Pre-Reboot): Just before the kexec, luo_file_freeze() is called.\n+ * 2. Freeze (Pre-Reboot): Either explicitly via LIVEUPDATE_SESSION_FREEZE or\n+ * just before the kexec during reboot(), luo_file_freeze() is called.\n * It iterates through all preserved files, calls their respective .freeze()\n * operation, and serializes their final metadata (compatible string, token,\n * and data handle) into a contiguous memory block for KHO.\n@@ -111,6 +112,7 @@\n #include \u003clinux/xarray.h\u003e\n #include \u003clinux/slab.h\u003e\n #include \u003clinux/string.h\u003e\n+#include \u003clinux/uaccess.h\u003e\n #include \"luo_internal.h\"\n \n static LIST_HEAD(luo_file_handler_list);\n@@ -136,9 +138,10 @@ static DEFINE_XARRAY(luo_preserved_files);\n * @retrieve_status: Status code indicating whether a user/kernel in the new kernel has\n * successfully called retrieve() on this file. This prevents\n * multiple retrieval attempts. A value of 0 means a retrieve()\n- * has not been attempted, a positive value means the retrieve()\n- * was successful, and a negative value means the retrieve()\n- * failed, and the value is the error code of the call.\n+ * has not been attempted (or only failed with a retryable\n+ * error), a positive value means the retrieve() was successful,\n+ * and a negative value means the retrieve() permanently failed,\n+ * and the value is the error code of the call.\n * @mutex: A mutex that protects the fields of this specific instance\n * (e.g., @retrieved, @file), ensuring that operations like\n * retrieving or finishing a file are atomic.\n@@ -175,6 +178,36 @@ static unsigned long luo_get_id(struct liveupdate_file_handler *fh,\n \treturn fh-\u003eops-\u003eget_id ? fh-\u003eops-\u003eget_id(file) : (unsigned long)file;\n }\n \n+/**\n+ * liveupdate_claim_file - Claim a file in the LUO preserved files table.\n+ * @fh: The file handler claiming @file.\n+ * @file: The file to claim.\n+ *\n+ * File handlers whose .retrieve() callback restores state into an existing\n+ * user-supplied \u0026struct file (rather than allocating a new one) should call\n+ * this before modifying @file to ensure @file is not already managed by LUO.\n+ *\n+ * Return: 0 on success, -EBUSY if @file is already managed by LUO, or a\n+ * negative errno on allocation failure.\n+ */\n+int liveupdate_claim_file(struct liveupdate_file_handler *fh,\n+\t\t\t struct file *file)\n+{\n+\treturn xa_insert(\u0026luo_preserved_files, luo_get_id(fh, file),\n+\t\t\t file, GFP_KERNEL);\n+}\n+\n+/**\n+ * liveupdate_unclaim_file - Release a claimed file from the LUO preserved files table.\n+ * @fh: The file handler that claimed @file.\n+ * @file: The file to release.\n+ */\n+void liveupdate_unclaim_file(struct liveupdate_file_handler *fh,\n+\t\t\t struct file *file)\n+{\n+\txa_erase(\u0026luo_preserved_files, luo_get_id(fh, file));\n+}\n+\n static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)\n {\n \tstruct luo_file *iter;\n@@ -187,11 +220,45 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)\n \treturn false;\n }\n \n+static int luo_copy_user_arg(u64 user_arg, const void **argp,\n+\t\t\t const struct liveupdate_arg_spec *spec)\n+{\n+\tvoid *karg __free(kfree) = NULL;\n+\tvoid __user *uptr;\n+\tu32 user_size;\n+\tint err;\n+\n+\tif (!user_arg)\n+\t\treturn 0;\n+\tif (!spec-\u003esize)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tuptr = u64_to_user_ptr(user_arg);\n+\tif (get_user(user_size, (u32 __user *)uptr))\n+\t\treturn -EFAULT;\n+\tif (user_size \u003c spec-\u003emin_size)\n+\t\treturn -EINVAL;\n+\tif (user_size \u003e PAGE_SIZE)\n+\t\treturn -E2BIG;\n+\n+\tkarg = kmalloc(spec-\u003esize, GFP_KERNEL);\n+\tif (!karg)\n+\t\treturn -ENOMEM;\n+\n+\terr = copy_struct_from_user(karg, spec-\u003esize, uptr, user_size);\n+\tif (err)\n+\t\treturn err;\n+\n+\t*argp = no_free_ptr(karg);\n+\treturn 0;\n+}\n+\n /**\n * luo_preserve_file - Initiate the preservation of a file descriptor.\n * @file_set: The file_set to which the preserved file will be added.\n * @token: A unique, user-provided identifier for the file.\n * @fd: The file descriptor to be preserved.\n+ * @arg: User-space pointer to the handler argument structure, or 0.\n *\n * This function orchestrates the first phase of preserving a file. Upon entry,\n * it takes a reference to the 'struct file' via fget(), effectively making LUO\n@@ -207,9 +274,11 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)\n * (allocates if needed).\n * 3. Iterates through registered handlers, calling can_preserve() to find one\n * compatible with the given @fd.\n- * 4. Calls the handler's .preserve() operation, which saves the file's state\n+ * 4. Copies the user argument structure (if @arg is non-zero) according to the\n+ * handler's parg specification.\n+ * 5. Calls the handler's .preserve() operation, which saves the file's state\n * and returns an opaque private data handle.\n- * 5. Adds the new instance to the file_set's internal list.\n+ * 6. Adds the new instance to the file_set's internal list.\n *\n * On success, LUO takes a reference to the 'struct file' and considers it\n * under its management until it is unpreserved or finished.\n@@ -224,10 +293,12 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)\n * -EBADF if the file descriptor is invalid.\n * -ENOSPC if the file_set is full.\n * -ENOENT if no compatible handler is found.\n+ * -EOPNOTSUPP if @arg is non-zero and the handler does not accept an arg.\n * -ENOMEM on memory allocation failure.\n * Other erros might be returned by .preserve().\n */\n-int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)\n+int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd,\n+\t\t u64 arg)\n {\n \tstruct liveupdate_file_op_args args = {0};\n \tstruct liveupdate_file_handler *fh;\n@@ -263,10 +334,14 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)\n \tif (err)\n \t\tgoto err_fput;\n \n+\terr = luo_copy_user_arg(arg, \u0026args.arg, \u0026fh-\u003eops-\u003eparg);\n+\tif (err)\n+\t\tgoto err_module_put;\n+\n \terr = xa_insert(\u0026luo_preserved_files, luo_get_id(fh, file),\n \t\t\tfile, GFP_KERNEL);\n \tif (err)\n-\t\tgoto err_module_put;\n+\t\tgoto err_free_arg;\n \n \terr = luo_flb_file_preserve(fh);\n \tif (err)\n@@ -289,6 +364,7 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)\n \tif (err)\n \t\tgoto err_kfree;\n \n+\tkfree(args.arg);\n \tluo_file-\u003eserialized_data = args.serialized_data;\n \tluo_file-\u003eprivate_data = args.private_data;\n \tlist_add_tail(\u0026luo_file-\u003elist, \u0026file_set-\u003efiles_list);\n@@ -302,6 +378,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)\n \tluo_flb_file_unpreserve(fh);\n err_erase_xa:\n \txa_erase(\u0026luo_preserved_files, luo_get_id(fh, file));\n+err_free_arg:\n+\tkfree(args.arg);\n err_module_put:\n \tmodule_put(fh-\u003eops-\u003eowner);\n err_fput:\n@@ -422,11 +500,11 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,\n /**\n * luo_file_freeze - Freezes all preserved files and serializes their metadata.\n * @file_set: The file_set whose files are to be frozen.\n- * @file_set_ser: Where to put the serialized file_set.\n+ * @file_set_ser: Where to put the serialized file_set, or %NULL if freezing early.\n *\n- * This function is called from the reboot() syscall path, just before the\n- * kernel transitions to the new image via kexec. Its purpose is to perform the\n- * final preparation and serialization of all preserved files in the file_set.\n+ * This function is called from the reboot() syscall path or from\n+ * LIVEUPDATE_SESSION_FREEZE. Its purpose is to perform the preparation and\n+ * serialization of all preserved files in the file_set.\n *\n * It iterates through each preserved file in FIFO order (the order of\n * preservation) and performs two main actions:\n@@ -449,7 +527,7 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,\n * running state. The function then returns an error, causing the reboot()\n * syscall to fail.\n *\n- * Context: Called only from the liveupdate_reboot() path.\n+ * Context: Called from the liveupdate_reboot() path or LIVEUPDATE_SESSION_FREEZE.\n * Return: 0 on success, or a negative errno on failure.\n */\n int luo_file_freeze(struct luo_file_set *file_set,\n@@ -487,8 +565,10 @@ int luo_file_freeze(struct luo_file_set *file_set,\n \t\tfile_ser-\u003etoken = luo_file-\u003etoken;\n \t}\n \n-\tfile_set_ser-\u003ecount = file_set-\u003ecount;\n-\tfile_set_ser-\u003efiles = kho_block_set_head_pa(\u0026file_set-\u003eblock_set);\n+\tif (file_set_ser) {\n+\t\tfile_set_ser-\u003ecount = file_set-\u003ecount;\n+\t\tfile_set_ser-\u003efiles = kho_block_set_head_pa(\u0026file_set-\u003eblock_set);\n+\t}\n \n \treturn 0;\n \n@@ -501,7 +581,7 @@ int luo_file_freeze(struct luo_file_set *file_set,\n /**\n * luo_file_unfreeze - Unfreezes all files in a file_set and clear serialization\n * @file_set: The file_set whose files are to be unfrozen.\n- * @file_set_ser: Serialized file_set.\n+ * @file_set_ser: Serialized file_set, or %NULL if not serialized yet.\n *\n * This function rolls back the state of all files in a file_set after the\n * freeze phase has begun but must be aborted. It is the counterpart to\n@@ -512,7 +592,8 @@ int luo_file_freeze(struct luo_file_set *file_set,\n * their respective .unfreeze() handler callbacks.\n *\n * Context: This is called when the live update is aborted during\n- * the reboot() syscall, after luo_file_freeze() has been called.\n+ * the reboot() syscall, after luo_file_freeze() has been called,\n+ * or when an early-frozen session is released before kexec.\n */\n void luo_file_unfreeze(struct luo_file_set *file_set,\n \t\t struct luo_file_set_ser *file_set_ser)\n@@ -521,13 +602,15 @@ void luo_file_unfreeze(struct luo_file_set *file_set,\n \t\treturn;\n \n \t__luo_file_unfreeze(file_set, NULL);\n-\tmemset(file_set_ser, 0, sizeof(*file_set_ser));\n+\tif (file_set_ser)\n+\t\tmemset(file_set_ser, 0, sizeof(*file_set_ser));\n }\n \n /**\n * luo_retrieve_file - Restores a preserved file from a file_set by its token.\n * @file_set: The file_set from which to retrieve the file.\n * @token: The unique token identifying the file to be restored.\n+ * @arg: User-space pointer to the handler argument structure, or 0.\n * @filep: Output parameter; on success, this is populated with a pointer\n * to the newly retrieved 'struct file'.\n *\n@@ -538,7 +621,9 @@ void luo_file_unfreeze(struct luo_file_set *file_set,\n * The operation is idempotent: if a file has already been successfully\n * retrieved, this function will simply return a pointer to the existing\n * 'struct file' and report success without re-executing the retrieve\n- * operation. This is handled by checking the 'retrieved' flag under a lock.\n+ * operation. If a previous retrieve failed permanently, it returns that\n+ * saved error code; if a previous retrieve failed with a retryable error\n+ * before consuming preserved state, the retrieve operation is re-attempted.\n *\n * File retrieval can happen in any order; it is not bound by the order of\n * preservation.\n@@ -547,9 +632,10 @@ void luo_file_unfreeze(struct luo_file_set *file_set,\n * kernel.\n * Return: 0 on success. Returns a negative errno on failure:\n * -ENOENT if no file with the matching token is found.\n+ * -EOPNOTSUPP if @arg is non-zero and the handler does not accept an arg.\n * Any error code returned by the handler's .retrieve() op.\n */\n-int luo_retrieve_file(struct luo_file_set *file_set, u64 token,\n+int luo_retrieve_file(struct luo_file_set *file_set, u64 token, u64 arg,\n \t\t struct file **filep)\n {\n \tstruct liveupdate_file_op_args args = {0};\n@@ -586,12 +672,22 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token,\n \t\treturn 0;\n \t}\n \n+\terr = luo_copy_user_arg(arg, \u0026args.arg, \u0026luo_file-\u003efh-\u003eops-\u003erarg);\n+\tif (err)\n+\t\treturn err;\n+\n \targs.handler = luo_file-\u003efh;\n \targs.serialized_data = luo_file-\u003eserialized_data;\n \terr = luo_file-\u003efh-\u003eops-\u003eretrieve(\u0026args);\n+\tkfree(args.arg);\n \tif (err) {\n-\t\t/* Keep the error code for later use. */\n-\t\tluo_file-\u003eretrieve_status = err;\n+\t\t/*\n+\t\t * Keep the error code for later use unless the handler marked\n+\t\t * the failure as retryable (e.g. invalid user argument before\n+\t\t * preserved state was consumed).\n+\t\t */\n+\t\tif (!args.retryable)\n+\t\t\tluo_file-\u003eretrieve_status = err;\n \t\treturn err;\n \t}\n \n@@ -599,9 +695,9 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token,\n \t/* Get reference so we can keep this file in LUO until finish */\n \tget_file(luo_file-\u003efile);\n \n-\tWARN_ON(xa_insert(\u0026luo_preserved_files,\n-\t\t\t luo_get_id(luo_file-\u003efh, luo_file-\u003efile),\n-\t\t\t luo_file-\u003efile, GFP_KERNEL));\n+\tif (xa_load(\u0026luo_preserved_files,\n+\t\t luo_get_id(luo_file-\u003efh, luo_file-\u003efile)) != luo_file-\u003efile)\n+\t\tWARN_ON(liveupdate_claim_file(luo_file-\u003efh, luo_file-\u003efile));\n \n \t*filep = luo_file-\u003efile;\n \tluo_file-\u003eretrieve_status = 1;\ndiff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h\nindex 64879ffe73781..3bd9ef442934e 100644\n--- a/kernel/liveupdate/luo_internal.h\n+++ b/kernel/liveupdate/luo_internal.h\n@@ -64,6 +64,8 @@ struct luo_file_set {\n * previous kernel) sessions.\n * @retrieved: A boolean flag indicating whether this session has been\n * retrieved by a consumer in the new kernel.\n+ * @frozen: A boolean flag indicating whether this session has been\n+ * frozen early from userspace.\n * @file_set: A set of files that belong to this session.\n * @mutex: protects fields in the luo_session.\n */\n@@ -71,6 +73,7 @@ struct luo_session {\n \tchar name[LIVEUPDATE_SESSION_NAME_LENGTH];\n \tstruct list_head list;\n \tbool retrieved;\n+\tbool frozen;\n \tstruct luo_file_set file_set;\n \tstruct mutex mutex;\n };\n@@ -84,13 +87,14 @@ int __init luo_session_setup_incoming(u64 sessions_pa);\n int luo_session_serialize(void);\n int luo_session_deserialize(void);\n \n-int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd);\n+int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd,\n+\t\t u64 arg);\n void luo_file_unpreserve_files(struct luo_file_set *file_set);\n int luo_file_freeze(struct luo_file_set *file_set,\n \t\t struct luo_file_set_ser *file_set_ser);\n void luo_file_unfreeze(struct luo_file_set *file_set,\n \t\t struct luo_file_set_ser *file_set_ser);\n-int luo_retrieve_file(struct luo_file_set *file_set, u64 token,\n+int luo_retrieve_file(struct luo_file_set *file_set, u64 token, u64 arg,\n \t\t struct file **filep);\n int luo_file_finish(struct luo_file_set *file_set);\n int luo_file_deserialize(struct luo_file_set *file_set,\ndiff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c\nindex f48e9a4185f97..74f8a1bf1da8c 100644\n--- a/kernel/liveupdate/luo_session.c\n+++ b/kernel/liveupdate/luo_session.c\n@@ -34,10 +34,11 @@\n * 1. Creation: A userspace agent calls `luo_session_create()` to create a\n * new, empty session and receives a file descriptor for it.\n *\n- * 2. Serialization: When the `reboot(LINUX_REBOOT_CMD_KEXEC)` syscall is\n- * made, `luo_session_serialize()` is called. It iterates through all\n- * active sessions and writes their metadata into a memory area preserved\n- * by KHO.\n+ * 2. Freeze / Serialization: Sessions may be frozen early from userspace\n+ * via `LIVEUPDATE_SESSION_FREEZE`. When the `reboot(LINUX_REBOOT_CMD_KEXEC)`\n+ * syscall is made, `luo_session_serialize()` is called to freeze any\n+ * remaining active sessions and write all session metadata into a memory\n+ * area preserved by KHO.\n *\n * 3. Deserialization (in new kernel): After kexec, `luo_session_deserialize()`\n * runs, reading the serialized data and creating a list of `struct\n@@ -222,6 +223,10 @@ static void luo_session_unfreeze_one(struct luo_session *session,\n \t\t\t\t struct luo_session_ser *ser)\n {\n \tguard(mutex)(\u0026session-\u003emutex);\n+\tif (session-\u003efrozen) {\n+\t\tmemset(\u0026ser-\u003efile_set_ser, 0, sizeof(ser-\u003efile_set_ser));\n+\t\treturn;\n+\t}\n \tluo_file_unfreeze(\u0026session-\u003efile_set, \u0026ser-\u003efile_set_ser);\n }\n \n@@ -229,6 +234,12 @@ static int luo_session_freeze_one(struct luo_session *session,\n \t\t\t\t struct luo_session_ser *ser)\n {\n \tguard(mutex)(\u0026session-\u003emutex);\n+\tif (session-\u003efrozen) {\n+\t\tser-\u003efile_set_ser.count = session-\u003efile_set.count;\n+\t\tser-\u003efile_set_ser.files =\n+\t\t\tkho_block_set_head_pa(\u0026session-\u003efile_set.block_set);\n+\t\treturn 0;\n+\t}\n \treturn luo_file_freeze(\u0026session-\u003efile_set, \u0026ser-\u003efile_set_ser);\n }\n \n@@ -249,8 +260,11 @@ static int luo_session_release(struct inode *inodep, struct file *filep)\n \t\t}\n \t\tsh = \u0026luo_session_global.incoming;\n \t} else {\n-\t\tscoped_guard(mutex, \u0026session-\u003emutex)\n+\t\tscoped_guard(mutex, \u0026session-\u003emutex) {\n+\t\t\tif (session-\u003efrozen)\n+\t\t\t\tluo_file_unfreeze(\u0026session-\u003efile_set, NULL);\n \t\t\tluo_file_unpreserve_files(\u0026session-\u003efile_set);\n+\t\t}\n \t\tsh = \u0026luo_session_global.outgoing;\n \t}\n \n@@ -267,7 +281,11 @@ static int luo_session_preserve_fd(struct luo_session *session,\n \tint err;\n \n \tguard(mutex)(\u0026session-\u003emutex);\n-\terr = luo_preserve_file(\u0026session-\u003efile_set, argp-\u003etoken, argp-\u003efd);\n+\tif (session-\u003efrozen)\n+\t\treturn -EBUSY;\n+\n+\terr = luo_preserve_file(\u0026session-\u003efile_set, argp-\u003etoken, argp-\u003efd,\n+\t\t\t\targp-\u003earg);\n \tif (err)\n \t\treturn err;\n \n@@ -290,7 +308,8 @@ static int luo_session_retrieve_fd(struct luo_session *session,\n \t\treturn argp-\u003efd;\n \n \tmutex_lock(\u0026session-\u003emutex);\n-\terr = luo_retrieve_file(\u0026session-\u003efile_set, argp-\u003etoken, \u0026file);\n+\terr = luo_retrieve_file(\u0026session-\u003efile_set, argp-\u003etoken, argp-\u003earg,\n+\t\t\t\t\u0026file);\n \tmutex_unlock(\u0026session-\u003emutex);\n \tif (err \u003c 0)\n \t\tgoto err_put_fd;\n@@ -340,11 +359,34 @@ static int luo_session_get_name(struct luo_session *session,\n \treturn luo_ucmd_respond(ucmd, sizeof(*argp));\n }\n \n+static int luo_session_freeze(struct luo_session *session,\n+\t\t\t struct luo_ucmd *ucmd)\n+{\n+\tstruct liveupdate_session_freeze *argp = ucmd-\u003ecmd;\n+\tint err;\n+\n+\tif (argp-\u003ereserved)\n+\t\treturn -EINVAL;\n+\n+\tguard(mutex)(\u0026session-\u003emutex);\n+\tif (session-\u003efrozen)\n+\t\treturn -EBUSY;\n+\n+\terr = luo_file_freeze(\u0026session-\u003efile_set, NULL);\n+\tif (err)\n+\t\treturn err;\n+\n+\tsession-\u003efrozen = true;\n+\n+\treturn luo_ucmd_respond(ucmd, sizeof(*argp));\n+}\n+\n union ucmd_buffer {\n \tstruct liveupdate_session_finish finish;\n \tstruct liveupdate_session_preserve_fd preserve;\n \tstruct liveupdate_session_retrieve_fd retrieve;\n \tstruct liveupdate_session_get_name get_name;\n+\tstruct liveupdate_session_freeze freeze;\n };\n \n /* Type of sessions the ioctl applies to. */\n@@ -382,6 +424,8 @@ static const struct luo_ioctl_op luo_session_ioctl_ops[] = {\n \t\t struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),\n \tIOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,\n \t\t struct liveupdate_session_get_name, name, LUO_IOCTL_ALL),\n+\tIOCTL_OP(LIVEUPDATE_SESSION_FREEZE, luo_session_freeze,\n+\t\t struct liveupdate_session_freeze, reserved, LUO_IOCTL_OUTGOING),\n };\n \n static bool luo_ioctl_type_valid(struct luo_session *session,\ndiff --git a/mm/memfd_luo.c b/mm/memfd_luo.c\nindex 59de210bee5f9..9d18f01191c07 100644\n--- a/mm/memfd_luo.c\n+++ b/mm/memfd_luo.c\n@@ -9,14 +9,14 @@\n */\n \n /**\n- * DOC: Memfd Preservation via LUO\n+ * DOC: Memfd and Tmpfs Preservation via LUO\n *\n * Overview\n * ========\n *\n- * Memory file descriptors (memfd) can be preserved over a kexec using the Live\n- * Update Orchestrator (LUO) file preservation. This allows userspace to\n- * transfer its memory contents to the next kernel after a kexec.\n+ * Memory file descriptors and generic tmpfs files can be preserved over a\n+ * kexec using the LUO file preservation. This allows userspace to transfer its\n+ * memory contents to the next kernel after a kexec.\n *\n * The preservation is not intended to be transparent. Only select properties of\n * the file are preserved. All others are reset to default. The preserved\n@@ -24,16 +24,17 @@\n *\n * .. note::\n * The LUO API is not stabilized yet, so the preserved properties of a memfd\n- * are also not stable and are subject to backwards incompatible changes.\n+ * or tmpfs file are also not stable and are subject to backwards\n+ * incompatible changes.\n *\n * .. note::\n- * Currently a memfd backed by Hugetlb is not supported. Memfds created\n+ * Currently a file backed by Hugetlb is not supported. Memfds created\n * with ``MFD_HUGETLB`` will be rejected.\n *\n * Preserved Properties\n * ====================\n *\n- * The following properties of the memfd are preserved across kexec:\n+ * The following properties of the memfd/tmpfs file are preserved across kexec:\n *\n * File Contents\n * All data stored in the file is preserved.\n@@ -43,8 +44,9 @@\n * allocating pages for them during preservation.\n *\n * File Position\n- * The current file position is preserved, allowing applications to continue\n- * reading/writing from their last position.\n+ * The file position at the time the session is frozen is preserved,\n+ * allowing applications to continue reading/writing from their last\n+ * position.\n *\n * File Status Flags\n * memfds are always opened with ``O_RDWR`` and ``O_LARGEFILE``. This property\n@@ -299,6 +301,8 @@ static int memfd_luo_preserve(struct liveupdate_file_op_args *args)\n \n \tser-\u003esize = inode_size;\n \tser-\u003eseals = seals;\n+\tif (inode-\u003ei_nlink)\n+\t\tser-\u003eflags |= MEMFD_LUO_FLAG_TMPFS;\n \n \terr = memfd_luo_preserve_folios(args-\u003efile, \u0026ser-\u003efolios,\n \t\t\t\t\t\u0026folios_ser, \u0026nr_folios);\n@@ -515,10 +519,60 @@ static int memfd_luo_retrieve_folios(struct file *file,\n \treturn err;\n }\n \n+static struct file *memfd_luo_get_tmpfs_file(struct liveupdate_file_op_args *args)\n+{\n+\tconst struct liveupdate_memfd_retrieve_arg *rarg = args-\u003earg;\n+\tstruct inode *inode;\n+\tstruct file *file;\n+\tint err;\n+\n+\tif (!rarg)\n+\t\treturn ERR_PTR(-EINVAL);\n+\n+\tfile = fget(rarg-\u003efd);\n+\tif (!file)\n+\t\treturn ERR_PTR(-EBADF);\n+\n+\tif (!(file-\u003ef_mode \u0026 FMODE_WRITE)) {\n+\t\terr = -EACCES;\n+\t\tgoto put_file;\n+\t}\n+\n+\tif (!shmem_file(file)) {\n+\t\terr = -EINVAL;\n+\t\tgoto put_file;\n+\t}\n+\n+\tinode = file_inode(file);\n+\tinode_lock(inode);\n+\tif (!inode-\u003ei_nlink) {\n+\t\terr = -EINVAL;\n+\t\tgoto unlock_inode;\n+\t}\n+\n+\tif (i_size_read(inode) != 0 || !mapping_empty(inode-\u003ei_mapping)) {\n+\t\terr = -EBUSY;\n+\t\tgoto unlock_inode;\n+\t}\n+\n+\terr = liveupdate_claim_file(args-\u003ehandler, file);\n+\tif (err)\n+\t\tgoto unlock_inode;\n+\n+\treturn file;\n+\n+unlock_inode:\n+\tinode_unlock(inode);\n+put_file:\n+\tfput(file);\n+\treturn ERR_PTR(err);\n+}\n+\n static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)\n {\n \tstruct memfd_luo_folio_ser *folios_ser;\n \tstruct memfd_luo_ser *ser;\n+\tstruct inode *inode;\n \tstruct file *file;\n \tint err;\n \n@@ -526,50 +580,75 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)\n \tif (!ser)\n \t\treturn -EINVAL;\n \n-\t/* Make sure the file only has seals supported by this version. */\n-\tif (ser-\u003eseals \u0026 ~MEMFD_LUO_ALL_SEALS) {\n+\t/* Make sure the file only has seals and flags supported by this version. */\n+\tif ((ser-\u003eseals \u0026 ~MEMFD_LUO_ALL_SEALS) ||\n+\t (ser-\u003eflags \u0026 ~MEMFD_LUO_ALL_FLAGS)) {\n \t\terr = -EOPNOTSUPP;\n \t\tgoto free_ser;\n \t}\n \n-\t/*\n-\t * The seals are preserved. Allow sealing here so they can be added\n-\t * later.\n-\t */\n-\tfile = memfd_alloc_file(\"\", MFD_ALLOW_SEALING);\n-\tif (IS_ERR(file)) {\n-\t\tpr_err(\"failed to setup file: %pe\\n\", file);\n-\t\terr = PTR_ERR(file);\n-\t\tgoto free_ser;\n-\t}\n+\tif (ser-\u003eflags \u0026 MEMFD_LUO_FLAG_TMPFS) {\n+\t\tfile = memfd_luo_get_tmpfs_file(args);\n+\t\tif (IS_ERR(file)) {\n+\t\t\targs-\u003eretryable = true;\n+\t\t\treturn PTR_ERR(file);\n+\t\t}\n+\t\tinode = file_inode(file);\n+\t} else {\n+\t\tif (args-\u003earg) {\n+\t\t\targs-\u003eretryable = true;\n+\t\t\treturn -EINVAL;\n+\t\t}\n \n-\terr = memfd_add_seals(file, ser-\u003eseals);\n-\tif (err) {\n-\t\tpr_err(\"failed to add seals: %pe\\n\", ERR_PTR(err));\n-\t\tgoto put_file;\n-\t}\n+\t\t/*\n+\t\t * The seals are preserved. Allow sealing here so they can be\n+\t\t * added later.\n+\t\t */\n+\t\tfile = memfd_alloc_file(\"\", MFD_ALLOW_SEALING);\n+\t\tif (IS_ERR(file)) {\n+\t\t\tpr_err(\"failed to setup file: %pe\\n\", file);\n+\t\t\terr = PTR_ERR(file);\n+\t\t\tgoto free_ser;\n+\t\t}\n \n-\tvfs_setpos(file, ser-\u003epos, MAX_LFS_FILESIZE);\n-\ti_size_write(file_inode(file), ser-\u003esize);\n+\t\terr = memfd_add_seals(file, ser-\u003eseals);\n+\t\tif (err) {\n+\t\t\tpr_err(\"failed to add seals: %pe\\n\", ERR_PTR(err));\n+\t\t\tgoto put_file;\n+\t\t}\n+\n+\t\tinode = file_inode(file);\n+\t\tinode_lock(inode);\n+\t}\n \n \tif (ser-\u003enr_folios) {\n \t\tfolios_ser = kho_restore_vmalloc(\u0026ser-\u003efolios);\n \t\tif (!folios_ser) {\n \t\t\terr = -EINVAL;\n-\t\t\tgoto put_file;\n+\t\t\tgoto unclaim_file;\n \t\t}\n \n \t\terr = memfd_luo_retrieve_folios(file, folios_ser, ser-\u003enr_folios);\n \t\tvfree(folios_ser);\n \t\tif (err)\n-\t\t\tgoto put_file;\n+\t\t\tgoto unclaim_file;\n \t}\n \n+\tvfs_setpos(file, ser-\u003epos, MAX_LFS_FILESIZE);\n+\ti_size_write(inode, ser-\u003esize);\n+\tinode_unlock(inode);\n+\n \targs-\u003efile = file;\n \tkho_restore_free(ser);\n \n \treturn 0;\n \n+unclaim_file:\n+\tif (ser-\u003eflags \u0026 MEMFD_LUO_FLAG_TMPFS) {\n+\t\tshmem_truncate_range(inode, 0, (loff_t)-1);\n+\t\tliveupdate_unclaim_file(args-\u003ehandler, file);\n+\t}\n+\tinode_unlock(inode);\n put_file:\n \tfput(file);\n free_ser:\n@@ -580,9 +659,7 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)\n static bool memfd_luo_can_preserve(struct liveupdate_file_handler *handler,\n \t\t\t\t struct file *file)\n {\n-\tstruct inode *inode = file_inode(file);\n-\n-\treturn shmem_file(file) \u0026\u0026 !inode-\u003ei_nlink;\n+\treturn shmem_file(file);\n }\n \n static unsigned long memfd_luo_get_id(struct file *file)\n@@ -598,6 +675,7 @@ static const struct liveupdate_file_ops memfd_luo_file_ops = {\n \t.unpreserve = memfd_luo_unpreserve,\n \t.can_preserve = memfd_luo_can_preserve,\n \t.get_id = memfd_luo_get_id,\n+\t.rarg = LIVEUPDATE_ARG(struct liveupdate_memfd_retrieve_arg, fd),\n \t.owner = THIS_MODULE,\n };\n \ndiff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h\nindex fa07fed083646..dc5c01408462d 100644\n--- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h\n+++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h\n@@ -26,13 +26,19 @@ int luo_create_session(int luo_fd, const char *name);\n int luo_retrieve_session(int luo_fd, const char *name);\n int luo_session_finish(int session_fd);\n int luo_get_session_name(int session_fd, char *name, size_t name_len);\n+int luo_session_freeze(int session_fd);\n \n int luo_ensure_nofile_limit(long min_limit);\n int luo_session_preserve_fd(int session_fd, int fd, __u64 token);\n+int luo_session_preserve_fd_arg(int session_fd, int fd, __u64 token,\n+\t\t\t\t__u64 user_arg);\n int luo_session_retrieve_fd(int session_fd, __u64 token);\n+int luo_session_retrieve_fd_arg(int session_fd, __u64 token, __u64 user_arg);\n \n int create_and_preserve_memfd(int session_fd, int token, const char *data);\n int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);\n+int restore_and_verify_tmpfs(int session_fd, int token, int fd,\n+\t\t\t const char *expected_data);\n \n void create_state_file(int luo_fd, const char *session_name, int token,\n \t\t int next_stage);\ndiff --git a/tools/testing/selftests/liveupdate/lib/lu_utils.c b/tools/testing/selftests/liveupdate/lib/lu_utils.c\nindex 74d41115c2815..1b1a556287d3a 100644\n--- a/tools/testing/selftests/liveupdate/lib/lu_utils.c\n+++ b/tools/testing/selftests/liveupdate/lib/lu_utils.c\n@@ -79,12 +79,14 @@ int luo_retrieve_session(int luo_fd, const char *name)\n \treturn arg.fd;\n }\n \n-int luo_session_preserve_fd(int session_fd, int fd, __u64 token)\n+int luo_session_preserve_fd_arg(int session_fd, int fd, __u64 token,\n+\t\t\t\t__u64 user_arg)\n {\n \tstruct liveupdate_session_preserve_fd arg = {\n \t\t.size = sizeof(arg),\n \t\t.fd = fd,\n \t\t.token = token,\n+\t\t.arg = user_arg,\n \t};\n \n \tif (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, \u0026arg))\n@@ -93,11 +95,17 @@ int luo_session_preserve_fd(int session_fd, int fd, __u64 token)\n \treturn 0;\n }\n \n-int luo_session_retrieve_fd(int session_fd, __u64 token)\n+int luo_session_preserve_fd(int session_fd, int fd, __u64 token)\n+{\n+\treturn luo_session_preserve_fd_arg(session_fd, fd, token, 0);\n+}\n+\n+int luo_session_retrieve_fd_arg(int session_fd, __u64 token, __u64 user_arg)\n {\n \tstruct liveupdate_session_retrieve_fd arg = {\n \t\t.size = sizeof(arg),\n \t\t.token = token,\n+\t\t.arg = user_arg,\n \t};\n \n \tif (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, \u0026arg))\n@@ -106,6 +114,11 @@ int luo_session_retrieve_fd(int session_fd, __u64 token)\n \treturn arg.fd;\n }\n \n+int luo_session_retrieve_fd(int session_fd, __u64 token)\n+{\n+\treturn luo_session_retrieve_fd_arg(session_fd, token, 0);\n+}\n+\n /* Helper function to get a session name via ioctl. */\n int luo_get_session_name(int session_fd, char *name, size_t name_len)\n {\n@@ -198,6 +211,16 @@ int luo_session_finish(int session_fd)\n \treturn 0;\n }\n \n+int luo_session_freeze(int session_fd)\n+{\n+\tstruct liveupdate_session_freeze arg = { .size = sizeof(arg) };\n+\n+\tif (ioctl(session_fd, LIVEUPDATE_SESSION_FREEZE, \u0026arg) \u003c 0)\n+\t\treturn -errno;\n+\n+\treturn 0;\n+}\n+\n void create_state_file(int luo_fd, const char *session_name, int token,\n \t\t int next_stage)\n {\n@@ -324,3 +347,47 @@ int luo_test(int argc, char *argv[],\n \n \treturn 0;\n }\n+\n+int restore_and_verify_tmpfs(int session_fd, int token, int fd,\n+\t\t\t const char *expected_data)\n+{\n+\tstruct liveupdate_memfd_retrieve_arg rarg = {\n+\t\t.size = sizeof(rarg),\n+\t\t.fd = fd,\n+\t};\n+\tlong page_size = getpagesize();\n+\tvoid *map = MAP_FAILED;\n+\tstruct stat st;\n+\tint ret_fd;\n+\n+\tret_fd = luo_session_retrieve_fd_arg(session_fd, token,\n+\t\t\t\t\t (unsigned long)\u0026rarg);\n+\tif (ret_fd \u003c 0) {\n+\t\tksft_print_msg(\"luo_session_retrieve_fd_arg failed: %d\\n\",\n+\t\t\t ret_fd);\n+\t\treturn ret_fd;\n+\t}\n+\tclose(ret_fd);\n+\n+\tif (fstat(fd, \u0026st) \u003c 0)\n+\t\treturn -errno;\n+\tif (st.st_size != page_size) {\n+\t\tksft_print_msg(\"Size mismatch! Expected %ld, Got %lld\\n\",\n+\t\t\t page_size, (long long)st.st_size);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tmap = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);\n+\tif (map == MAP_FAILED)\n+\t\treturn -errno;\n+\n+\tif (expected_data \u0026\u0026 strcmp(expected_data, map) != 0) {\n+\t\tksft_print_msg(\"Data mismatch! Expected '%s', Got '%s'\\n\",\n+\t\t\t expected_data, (char *)map);\n+\t\tmunmap(map, page_size);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tmunmap(map, page_size);\n+\treturn 0;\n+}\ndiff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c\nindex 2dedd5fc2534f..83e0978f3818d 100644\n--- a/tools/testing/selftests/liveupdate/liveupdate.c\n+++ b/tools/testing/selftests/liveupdate/liveupdate.c\n@@ -20,6 +20,7 @@\n \n #include \u003cerrno.h\u003e\n #include \u003cfcntl.h\u003e\n+#include \u003cstddef.h\u003e\n #include \u003cstring.h\u003e\n #include \u003csys/ioctl.h\u003e\n #include \u003cunistd.h\u003e\n@@ -530,4 +531,87 @@ TEST_F(liveupdate_device, preserve_many_files)\n \tASSERT_EQ(close(session_fd), 0);\n }\n \n+/*\n+ * Test Case: Session Freeze\n+ *\n+ * Verifies that an outgoing session can be frozen early via\n+ * LIVEUPDATE_SESSION_FREEZE, that subsequent freeze attempts return -EBUSY,\n+ * and that attempting to preserve an additional file descriptor into a frozen\n+ * session fails with -EBUSY.\n+ */\n+TEST_F(liveupdate_device, session_freeze)\n+{\n+\tint session_fd, mem_fd1, mem_fd2;\n+\n+\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\n+\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\n+\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\n+\tASSERT_GE(self-\u003efd1, 0);\n+\n+\tsession_fd = luo_create_session(self-\u003efd1, \"session-freeze-test\");\n+\tASSERT_GE(session_fd, 0);\n+\n+\tmem_fd1 = memfd_create(\"freeze-memfd-1\", 0);\n+\tASSERT_GE(mem_fd1, 0);\n+\tASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fd1, 0x1111), 0);\n+\n+\t/* Freeze the session early */\n+\tASSERT_EQ(luo_session_freeze(session_fd), 0);\n+\n+\t/* Subsequent freeze attempt on an already frozen session must fail with -EBUSY */\n+\tEXPECT_EQ(luo_session_freeze(session_fd), -EBUSY);\n+\n+\t/* Preserving a file after freeze must fail with -EBUSY */\n+\tmem_fd2 = memfd_create(\"freeze-memfd-2\", 0);\n+\tASSERT_GE(mem_fd2, 0);\n+\tEXPECT_EQ(luo_session_preserve_fd(session_fd, mem_fd2, 0x2222), -EBUSY);\n+\n+\tASSERT_EQ(close(session_fd), 0);\n+\tASSERT_EQ(close(mem_fd1), 0);\n+\tASSERT_EQ(close(mem_fd2), 0);\n+}\n+\n+/*\n+ * Test Case: Preserve MemFD with User Argument\n+ *\n+ * Verifies that passing a non-zero user argument to memfd preservation fails\n+ * with -EOPNOTSUPP, while passing a zero argument or using the minimum struct\n+ * size without the arg field succeeds.\n+ */\n+TEST_F(liveupdate_device, preserve_memfd_with_arg)\n+{\n+\tstruct liveupdate_session_preserve_fd min_arg = {};\n+\tint session_fd, mem_fd1, mem_fd2;\n+\n+\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\n+\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\n+\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\n+\tASSERT_GE(self-\u003efd1, 0);\n+\n+\tsession_fd = luo_create_session(self-\u003efd1, \"preserve-arg-test\");\n+\tASSERT_GE(session_fd, 0);\n+\n+\tmem_fd1 = memfd_create(\"arg-memfd-1\", 0);\n+\tASSERT_GE(mem_fd1, 0);\n+\n+\t/* Non-zero arg is not supported by memfd handler */\n+\tEXPECT_EQ(luo_session_preserve_fd_arg(session_fd, mem_fd1, 0x1111, 1),\n+\t\t -EOPNOTSUPP);\n+\n+\t/* Legacy struct size (up to token) should zero-fill arg and succeed */\n+\tmin_arg.size = offsetof(struct liveupdate_session_preserve_fd, arg);\n+\tmin_arg.fd = mem_fd1;\n+\tmin_arg.token = 0x1111;\n+\tASSERT_EQ(ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, \u0026min_arg), 0);\n+\n+\t/* Explicit zero arg with full struct size should also succeed */\n+\tmem_fd2 = memfd_create(\"arg-memfd-2\", 0);\n+\tASSERT_GE(mem_fd2, 0);\n+\tASSERT_EQ(luo_session_preserve_fd_arg(session_fd, mem_fd2, 0x2222, 0), 0);\n+\n+\tASSERT_EQ(close(session_fd), 0);\n+\tASSERT_EQ(close(mem_fd1), 0);\n+\tASSERT_EQ(close(mem_fd2), 0);\n+}\n+\n TEST_HARNESS_MAIN\ndiff --git a/tools/testing/selftests/liveupdate/luo_kexec_simple.c b/tools/testing/selftests/liveupdate/luo_kexec_simple.c\nindex 786ac93b9ae38..ab108c7f1d855 100644\n--- a/tools/testing/selftests/liveupdate/luo_kexec_simple.c\n+++ b/tools/testing/selftests/liveupdate/luo_kexec_simple.c\n@@ -40,6 +40,11 @@ static void run_stage_1(int luo_fd)\n \t\t\t TEST_MEMFD_TOKEN);\n \t}\n \n+\tksft_print_msg(\"[STAGE 1] Freezing session '%s' early...\\n\",\n+\t\t TEST_SESSION_NAME);\n+\tif (luo_session_freeze(session_fd) \u003c 0)\n+\t\tfail_exit(\"luo_session_freeze for '%s'\", TEST_SESSION_NAME);\n+\n \tclose(luo_fd);\n \tdaemonize_and_wait();\n }\ndiff --git a/tools/testing/selftests/liveupdate/luo_multi_session.c b/tools/testing/selftests/liveupdate/luo_multi_session.c\nindex aac24a5f5ce3c..46889676d9f52 100644\n--- a/tools/testing/selftests/liveupdate/luo_multi_session.c\n+++ b/tools/testing/selftests/liveupdate/luo_multi_session.c\n@@ -9,7 +9,15 @@\n * files.\n */\n \n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003csys/mman.h\u003e\n+#include \u003csys/mount.h\u003e\n+#include \u003csys/stat.h\u003e\n+#include \u003cunistd.h\u003e\n+\n #include \u003clibliveupdate.h\u003e\n+#include \u003clinux/liveupdate.h\u003e\n \n #define SESSION_EMPTY_1 \"multi-test-empty-1\"\n #define SESSION_EMPTY_2 \"multi-test-empty-2\"\n@@ -23,6 +31,7 @@\n #define MFD1_DATA \"Data for session files 1\"\n #define MFD2_DATA \"First file for session files 2\"\n #define MFD3_DATA \"Second file for session files 2\"\n+#define MFD3_POS 42\n \n #define STATE_SESSION_NAME \"kexec_multi_state\"\n #define STATE_MEMFD_TOKEN 998\n@@ -31,6 +40,8 @@\n static void run_stage_1(int luo_fd)\n {\n \tint s_empty1_fd, s_empty2_fd, s_files1_fd, s_files2_fd;\n+\tint tmpfs_fd;\n+\tvoid *map;\n \n \tksft_print_msg(\"[STAGE 1] Starting pre-kexec setup for multi-session test...\\n\");\n \n@@ -53,25 +64,50 @@ static void run_stage_1(int luo_fd)\n \ts_files1_fd = luo_create_session(luo_fd, SESSION_FILES_1);\n \tif (s_files1_fd \u003c 0)\n \t\tfail_exit(\"luo_create_session for '%s'\", SESSION_FILES_1);\n+\tksft_print_msg(\" -\u003e Preserving memfd (token %#x, content: \\\"%s\\\")\\n\",\n+\t\t MFD1_TOKEN, MFD1_DATA);\n \tif (create_and_preserve_memfd(s_files1_fd, MFD1_TOKEN, MFD1_DATA) \u003c 0) {\n \t\tfail_exit(\"create_and_preserve_memfd for token %#x\",\n \t\t\t MFD1_TOKEN);\n \t}\n \n-\tksft_print_msg(\"[STAGE 1] Creating session '%s' with two memfds...\\n\",\n+\tksft_print_msg(\"[STAGE 1] Creating session '%s' with memfd and tmpfs file...\\n\",\n \t\t SESSION_FILES_2);\n \n \ts_files2_fd = luo_create_session(luo_fd, SESSION_FILES_2);\n \tif (s_files2_fd \u003c 0)\n \t\tfail_exit(\"luo_create_session for '%s'\", SESSION_FILES_2);\n+\tksft_print_msg(\" -\u003e Preserving memfd (token %#x, content: \\\"%s\\\")\\n\",\n+\t\t MFD2_TOKEN, MFD2_DATA);\n \tif (create_and_preserve_memfd(s_files2_fd, MFD2_TOKEN, MFD2_DATA) \u003c 0) {\n \t\tfail_exit(\"create_and_preserve_memfd for token %#x\",\n \t\t\t MFD2_TOKEN);\n \t}\n-\tif (create_and_preserve_memfd(s_files2_fd, MFD3_TOKEN, MFD3_DATA) \u003c 0) {\n-\t\tfail_exit(\"create_and_preserve_memfd for token %#x\",\n-\t\t\t MFD3_TOKEN);\n-\t}\n+\n+\tksft_print_msg(\" -\u003e Populating tmpfs file at /mnt/mfd3...\\n\");\n+\tif (mkdir(\"/mnt\", 0777) \u003c 0 \u0026\u0026 errno != EEXIST)\n+\t\tfail_exit(\"mkdir /mnt\");\n+\tif (mount(\"tmpfs\", \"/mnt\", \"tmpfs\", 0, NULL) \u003c 0)\n+\t\tfail_exit(\"mount tmpfs\");\n+\ttmpfs_fd = open(\"/mnt/mfd3\", O_CREAT | O_RDWR, 0666);\n+\tif (tmpfs_fd \u003c 0)\n+\t\tfail_exit(\"failed to open tmpfs_fd\");\n+\tksft_print_msg(\" -\u003e Preserving generic tmpfs file (token %#x, content: \\\"%s\\\")\\n\",\n+\t\t MFD3_TOKEN, MFD3_DATA);\n+\tif (ftruncate(tmpfs_fd, getpagesize()) \u003c 0)\n+\t\tfail_exit(\"ftruncate tmpfs_fd\");\n+\tmap = mmap(NULL, getpagesize(), PROT_WRITE, MAP_SHARED, tmpfs_fd, 0);\n+\tif (map == MAP_FAILED)\n+\t\tfail_exit(\"mmap tmpfs_fd\");\n+\tstrcpy(map, MFD3_DATA);\n+\tmunmap(map, getpagesize());\n+\tif (lseek(tmpfs_fd, MFD3_POS, SEEK_SET) != MFD3_POS)\n+\t\tfail_exit(\"lseek tmpfs_fd\");\n+\n+\tif (luo_session_preserve_fd(s_files2_fd, tmpfs_fd, MFD3_TOKEN) \u003c 0)\n+\t\tfail_exit(\"preserve tmpfs fd\");\n+\n+\tclose(tmpfs_fd);\n \n \tclose(luo_fd);\n \tdaemonize_and_wait();\n@@ -81,7 +117,10 @@ static void run_stage_1(int luo_fd)\n static void run_stage_2(int luo_fd, int state_session_fd)\n {\n \tint s_empty1_fd, s_empty2_fd, s_files1_fd, s_files2_fd;\n-\tint mfd1, mfd2, mfd3, stage;\n+\tstruct liveupdate_memfd_retrieve_arg rarg = {\n+\t\t.size = sizeof(rarg),\n+\t};\n+\tint mfd1, mfd2, mfd3, ro_fd, ret, stage;\n \n \tksft_print_msg(\"[STAGE 2] Starting post-kexec verification...\\n\");\n \n@@ -110,6 +149,8 @@ static void run_stage_2(int luo_fd, int state_session_fd)\n \n \tksft_print_msg(\"[STAGE 2] Verifying contents of session '%s'...\\n\",\n \t\t SESSION_FILES_1);\n+\tksft_print_msg(\" -\u003e Retrieving memfd (token %#x) from session...\\n\",\n+\t\t MFD1_TOKEN);\n \tmfd1 = restore_and_verify_memfd(s_files1_fd, MFD1_TOKEN, MFD1_DATA);\n \tif (mfd1 \u003c 0)\n \t\tfail_exit(\"restore_and_verify_memfd for token %#x\", MFD1_TOKEN);\n@@ -118,14 +159,65 @@ static void run_stage_2(int luo_fd, int state_session_fd)\n \tksft_print_msg(\"[STAGE 2] Verifying contents of session '%s'...\\n\",\n \t\t SESSION_FILES_2);\n \n+\tksft_print_msg(\" -\u003e Creating empty tmpfs file at /mnt/mfd3...\\n\");\n+\tif (mkdir(\"/mnt\", 0777) \u003c 0 \u0026\u0026 errno != EEXIST)\n+\t\tfail_exit(\"mkdir /mnt\");\n+\tif (mount(\"tmpfs\", \"/mnt\", \"tmpfs\", 0, NULL) \u003c 0)\n+\t\tfail_exit(\"mount tmpfs\");\n+\tmfd3 = open(\"/mnt/mfd3\", O_CREAT | O_RDWR, 0666);\n+\tif (mfd3 \u003c 0)\n+\t\tfail_exit(\"open tmpfs file\");\n+\tro_fd = open(\"/mnt/mfd3\", O_RDONLY);\n+\tif (ro_fd \u003c 0)\n+\t\tfail_exit(\"open read-only tmpfs file\");\n+\n+\tksft_print_msg(\" -\u003e Verifying retryable retrieve errors for memfd and tmpfs...\\n\");\n+\trarg.fd = mfd3;\n+\tret = luo_session_retrieve_fd_arg(s_files2_fd, MFD2_TOKEN,\n+\t\t\t\t\t (uintptr_t)\u0026rarg);\n+\tif (ret != -EINVAL)\n+\t\tfail_exit(\"expected -EINVAL when passing arg to memfd retrieve, got %d\",\n+\t\t\t ret);\n+\n+\tksft_print_msg(\" -\u003e Retrieving memfd (token %#x) from session...\\n\",\n+\t\t MFD2_TOKEN);\n \tmfd2 = restore_and_verify_memfd(s_files2_fd, MFD2_TOKEN, MFD2_DATA);\n \tif (mfd2 \u003c 0)\n \t\tfail_exit(\"restore_and_verify_memfd for token %#x\", MFD2_TOKEN);\n \tclose(mfd2);\n \n-\tmfd3 = restore_and_verify_memfd(s_files2_fd, MFD3_TOKEN, MFD3_DATA);\n-\tif (mfd3 \u003c 0)\n-\t\tfail_exit(\"restore_and_verify_memfd for token %#x\", MFD3_TOKEN);\n+\tret = luo_session_retrieve_fd(s_files2_fd, MFD3_TOKEN);\n+\tif (ret != -EINVAL)\n+\t\tfail_exit(\"expected -EINVAL when retrieving tmpfs without arg, got %d\",\n+\t\t\t ret);\n+\n+\trarg.fd = ro_fd;\n+\tret = luo_session_retrieve_fd_arg(s_files2_fd, MFD3_TOKEN,\n+\t\t\t\t\t (uintptr_t)\u0026rarg);\n+\tif (ret != -EACCES)\n+\t\tfail_exit(\"expected -EACCES when retrieving tmpfs into read-only fd, got %d\",\n+\t\t\t ret);\n+\tclose(ro_fd);\n+\n+\tif (ftruncate(mfd3, 1) \u003c 0)\n+\t\tfail_exit(\"ftruncate non-empty tmpfs file\");\n+\trarg.fd = mfd3;\n+\tret = luo_session_retrieve_fd_arg(s_files2_fd, MFD3_TOKEN,\n+\t\t\t\t\t (uintptr_t)\u0026rarg);\n+\tif (ret != -EBUSY)\n+\t\tfail_exit(\"expected -EBUSY when retrieving tmpfs into non-empty fd, got %d\",\n+\t\t\t ret);\n+\tif (ftruncate(mfd3, 0) \u003c 0)\n+\t\tfail_exit(\"ftruncate empty tmpfs file\");\n+\n+\tksft_print_msg(\" -\u003e Retrieving tmpfs file (token %#x) from session...\\n\",\n+\t\t MFD3_TOKEN);\n+\tif (restore_and_verify_tmpfs(s_files2_fd, MFD3_TOKEN, mfd3,\n+\t\t\t\t MFD3_DATA) \u003c 0)\n+\t\tfail_exit(\"restore_and_verify_tmpfs for token %#x\",\n+\t\t\t MFD3_TOKEN);\n+\tif (lseek(mfd3, 0, SEEK_CUR) != MFD3_POS)\n+\t\tfail_exit(\"expected f_pos %d on restored tmpfs file\", MFD3_POS);\n \tclose(mfd3);\n \n \tksft_print_msg(\"[STAGE 2] Test data verified successfully.\\n\");\n"
} |
| 2/1 | 2026/10/15 11:54 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"KEXEC_HANDOVER",
"LIVEUPDATE",
"LIVEUPDATE_MEMFD",
"MEMFD_CREATE",
"SHMEM"
],
"FocusSymbols": [
"luo_session_freeze",
"luo_preserve_file",
"luo_retrieve_file",
"liveupdate_claim_file",
"liveupdate_unclaim_file",
"memfd_luo_get_tmpfs_file",
"memfd_luo_preserve",
"memfd_luo_retrieve"
],
"Reasoning": "The patch introduces the LIVEUPDATE_SESSION_FREEZE ioctl command, support for user-supplied arguments during file preservation and retrieval in the Live Update Orchestrator (LUO), and extends memfd preservation to arbitrary tmpfs files. These paths are exposed to userspace via /dev/liveupdate and session file descriptors, modifying core state management, file descriptor validation, and tmpfs folio handling. Fuzzing is warranted to test early freeze state transitions, user argument parsing, and tmpfs retrieval error recovery.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 73221d66de0cb87d5537af6ff35cba50bed7c783
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Oct 15 11:54:43 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/kho/abi/memfd.h b/include/linux/kho/abi/memfd.h
index 08b10fea2afc8..47ff5ab967501 100644
--- a/include/linux/kho/abi/memfd.h
+++ b/include/linux/kho/abi/memfd.h
@@ -68,7 +68,18 @@ struct memfd_luo_folio_ser {
F_SEAL_EXEC)
/**
- * struct memfd_luo_ser - Main serialization structure for a memfd.
+ * MEMFD_LUO_FLAG_TMPFS - The preserved file is a tmpfs file.
+ *
+ * Indicates the file was preserved from a linked tmpfs file rather than an
+ * anonymous memfd, and must be retrieved to an empty tmpfs file.
+ */
+#define MEMFD_LUO_FLAG_TMPFS BIT(0)
+
+/* The set of flags this version supports preserving. */
+#define MEMFD_LUO_ALL_FLAGS MEMFD_LUO_FLAG_TMPFS
+
+/**
+ * struct memfd_luo_ser - Main serialization structure for a memfd or tmpfs file.
* @pos: The file's current position (f_pos).
* @size: The total size of the file in bytes (i_size).
* @seals: The seals present on the memfd. The seals are uABI so it is safe
diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h
index 63ea5417de849..4e1f0f4cbd6fb 100644
--- a/include/linux/liveupdate.h
+++ b/include/linux/liveupdate.h
@@ -22,14 +22,48 @@ struct liveupdate_flb;
struct liveupdate_session;
struct file;
+/**
+ * struct liveupdate_arg_spec - Specification of a file handler user argument.
+ * @size: Full size of the argument structure in the current kernel.
+ * @min_size: Minimum valid user-supplied size (offsetofend of the last
+ * required field).
+ */
+struct liveupdate_arg_spec {
+ size_t size;
+ size_t min_size;
+};
+
+/**
+ * LIVEUPDATE_ARG - Validated specification of a file handler argument struct.
+ * @_struct: The argument structure type.
+ * @_min_last: The last required member in @_struct.
+ *
+ * All file handler argument structures passed via
+ * &liveupdate_session_preserve_fd.arg or &liveupdate_session_retrieve_fd.arg
+ * must begin with a 32-bit @size field so they can be extended compatibly.
+ * Use this macro to initialize &liveupdate_file_ops.parg and
+ * &liveupdate_file_ops.rarg.
+ */
+#define LIVEUPDATE_ARG(_struct, _min_last) \
+ { \
+ .size = sizeof(_struct) + \
+ BUILD_BUG_ON_ZERO(offsetof(_struct, size) != 0) + \
+ BUILD_BUG_ON_ZERO(sizeof_field(_struct, size) != sizeof(u32)), \
+ .min_size = offsetofend(_struct, _min_last), \
+ }
+
/**
* struct liveupdate_file_op_args - Arguments for file operation callbacks.
* @handler: The file handler being called.
* @retrieve_status: The retrieve status for the 'can_finish / finish'
* operation. A value of 0 means the retrieve has not been
- * attempted, a positive value means the retrieve was
- * successful, and a negative value means the retrieve failed,
- * and the value is the error code of the call.
+ * attempted (or only failed with a retryable error), a
+ * positive value means the retrieve was successful, and a
+ * negative value means the retrieve permanently failed, and
+ * the value is the error code of the call.
+ * @retryable: For .retrieve(): [OUT] Set to true by the callback on
+ * error when the preserved state has not been consumed and
+ * retrieval may be retried.
* @file: The file object. For retrieve: [OUT] The callback sets
* this to the new file. For other ops: [IN] The caller sets
* this to the file being operated on.
@@ -39,6 +73,11 @@ struct file;
* is not preserved. Set by the handler's .preserve()
* callback, and must be freed in the handler's
* .unpreserve() callback.
+ * @arg: Kernel copy of the user-provided argument for .preserve()
+ * and .retrieve(), or %NULL if none was provided. Allocated
+ * to the handler's expected argument size with any trailing
+ * bytes beyond the user-supplied size zero-filled. Valid
+ * only for the duration of the callback.
*
* This structure bundles all parameters for the file operation callbacks.
* The 'data' and 'file' fields are used for both input and output.
@@ -46,9 +85,11 @@ struct file;
struct liveupdate_file_op_args {
struct liveupdate_file_handler *handler;
int retrieve_status;
+ bool retryable;
struct file *file;
u64 serialized_data;
void *private_data;
+ const void *arg;
};
/**
@@ -57,7 +98,8 @@ struct liveupdate_file_op_args {
* compatible with the given file.
* @preserve: Required. Performs state-saving for the file.
* @unpreserve: Required. Cleans up any resources allocated by @preserve.
- * @freeze: Optional. Final actions just before kernel transition.
+ * @freeze: Optional. Prepares final state before kexec (via
+ * LIVEUPDATE_SESSION_FREEZE or during reboot).
* @unfreeze: Optional. Undo freeze operations.
* @retrieve: Required. Restores the file in the new kernel.
* @can_finish: Optional. Check if this FD can finish, i.e. all restoration
@@ -66,6 +108,12 @@ struct liveupdate_file_op_args {
* resources in the session.
* @finish: Required. Final cleanup in the new kernel.
* @get_id: Optional. Returns a unique identifier for the file.
+ * @parg: Optional. Specification of the user argument structure
+ * accepted by @preserve, initialized via LIVEUPDATE_ARG(). If
+ * unset, non-zero user arguments are rejected with -EOPNOTSUPP.
+ * @rarg: Optional. Specification of the user argument structure
+ * accepted by @retrieve, initialized via LIVEUPDATE_ARG(). If
+ * unset, non-zero user arguments are rejected with -EOPNOTSUPP.
* @owner: Module reference
*
* All operations (except can_preserve) receive a pointer to a
@@ -82,6 +130,8 @@ struct liveupdate_file_ops {
bool (*can_finish)(struct liveupdate_file_op_args *args);
void (*finish)(struct liveupdate_file_op_args *args);
unsigned long (*get_id)(struct file *file);
+ struct liveupdate_arg_spec parg;
+ struct liveupdate_arg_spec rarg;
struct module *owner;
};
@@ -236,6 +286,11 @@ int liveupdate_reboot(void);
int liveupdate_register_file_handler(struct liveupdate_file_handler *fh);
void liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh);
+int liveupdate_claim_file(struct liveupdate_file_handler *fh,
+ struct file *file);
+void liveupdate_unclaim_file(struct liveupdate_file_handler *fh,
+ struct file *file);
+
int liveupdate_register_flb(struct liveupdate_file_handler *fh,
struct liveupdate_flb *flb);
void liveupdate_unregister_flb(struct liveupdate_file_handler *fh,
@@ -268,6 +323,17 @@ static inline void liveupdate_unregister_file_handler(struct liveupdate_file_han
{
}
+static inline int liveupdate_claim_file(struct liveupdate_file_handler *fh,
+ struct file *file)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline void liveupdate_unclaim_file(struct liveupdate_file_handler *fh,
+ struct file *file)
+{
+}
+
static inline int liveupdate_register_flb(struct liveupdate_file_handler *fh,
struct liveupdate_flb *flb)
{
diff --git a/include/uapi/linux/liveupdate.h b/include/uapi/linux/liveupdate.h
index 4043d40387125..24e938d91392c 100644
--- a/include/uapi/linux/liveupdate.h
+++ b/include/uapi/linux/liveupdate.h
@@ -60,6 +60,7 @@ enum {
LIVEUPDATE_CMD_SESSION_RETRIEVE_FD = 0x41,
LIVEUPDATE_CMD_SESSION_FINISH = 0x42,
LIVEUPDATE_CMD_SESSION_GET_NAME = 0x43,
+ LIVEUPDATE_CMD_SESSION_FREEZE = 0x44,
};
/**
@@ -126,6 +127,8 @@ struct liveupdate_ioctl_retrieve_session {
* @size: Input; sizeof(struct liveupdate_session_preserve_fd)
* @fd: Input; The user-space file descriptor to be preserved.
* @token: Input; An opaque, unique token for preserved resource.
+ * @arg: Input; User-space pointer to a file-handler-specific argument
+ * structure starting with a 32-bit size field, or 0 if unused.
*
* Holds parameters for preserving a file descriptor.
*
@@ -149,6 +152,7 @@ struct liveupdate_session_preserve_fd {
__u32 size;
__s32 fd;
__aligned_u64 token;
+ __aligned_u64 arg;
};
#define LIVEUPDATE_SESSION_PRESERVE_FD \
@@ -160,6 +164,8 @@ struct liveupdate_session_preserve_fd {
* @fd: Output; The new file descriptor representing the fully restored
* kernel resource.
* @token: Input; An opaque, token that was used to preserve the resource.
+ * @arg: Input; User-space pointer to a file-handler-specific argument
+ * structure starting with a 32-bit size field, or 0 if unused.
*
* Retrieve a previously preserved file descriptor.
*
@@ -169,9 +175,10 @@ struct liveupdate_session_preserve_fd {
* associated with the token and populates the @fd field with a new file
* descriptor referencing the restored resource in the current (new) kernel.
* This operation must be performed *before* signaling completion via
- * %LIVEUPDATE_IOCTL_FINISH. If a retrieve of a token fails, subsequent
- * attempts to retrieve the token fail with the same error code. Failed
- * retrieves are not retried.
+ * %LIVEUPDATE_IOCTL_FINISH. If a retrieve of a token fails after consuming
+ * preserved state, subsequent attempts to retrieve the token fail with the
+ * same error code. Early argument or target validation errors before
+ * preserved state is consumed leave the token intact and may be retried.
*
* Return: 0 on success, negative error code on failure (e.g., invalid token).
*/
@@ -179,6 +186,7 @@ struct liveupdate_session_retrieve_fd {
__u32 size;
__s32 fd;
__aligned_u64 token;
+ __aligned_u64 arg;
};
#define LIVEUPDATE_SESSION_RETRIEVE_FD \
@@ -236,4 +244,49 @@ struct liveupdate_session_get_name {
#define LIVEUPDATE_SESSION_GET_NAME \
_IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_GET_NAME)
+/**
+ * struct liveupdate_session_freeze - ioctl(LIVEUPDATE_SESSION_FREEZE)
+ * @size: Input; sizeof(struct liveupdate_session_freeze)
+ * @reserved: Input; Must be zero. Reserved for future use.
+ *
+ * Freezes the session early from userspace before the reboot kexec phase.
+ *
+ * When this ioctl is called, the kernel executes the .freeze() callback on all
+ * preserved files in the session and serializes their metadata. Once frozen,
+ * no further files can be preserved in the session.
+ *
+ * During the subsequent reboot kexec, this session is recognized as already
+ * frozen and is skipped from the late auto freeze.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+struct liveupdate_session_freeze {
+ __u32 size;
+ __u32 reserved;
+};
+
+#define LIVEUPDATE_SESSION_FREEZE \
+ _IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_FREEZE)
+
+/**
+ * struct liveupdate_memfd_retrieve_arg - Argument for tmpfs file retrieval
+ * @size: Input; sizeof(struct liveupdate_memfd_retrieve_arg)
+ * @fd: Input; Writable, empty, linked tmpfs file descriptor to restore into.
+ *
+ * Passed via &struct liveupdate_session_retrieve_fd.arg on
+ * %LIVEUPDATE_SESSION_RETRIEVE_FD. This argument is required when retrieving
+ * a preserved linked tmpfs file and is rejected with -EINVAL when retrieving
+ * an anonymous memfd.
+ *
+ * @fd must refer to a writable, empty, linked tmpfs file that is not already
+ * claimed by LUO. On success, the file is populated with the preserved folios,
+ * its size and f_pos are restored, and the file descriptor returned in
+ * &struct liveupdate_session_retrieve_fd.fd references the same underlying open
+ * file description as @fd.
+ */
+struct liveupdate_memfd_retrieve_arg {
+ __u32 size;
+ __s32 fd;
+};
+
#endif /* _UAPI_LIVEUPDATE_H */
diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index c39f96961a85b..5c2ffec696885 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -31,9 +31,9 @@
* - unpreserve(): Cleans up any resources allocated by .preserve(), called
* if the preservation process is aborted before the reboot (i.e. session is
* closed).
- * - freeze(): A final pre-reboot opportunity to prepare the state for kexec.
- * We are already in reboot syscall, and therefore userspace cannot mutate
- * the file anymore.
+ * - freeze(): Prepares the final state for kexec. Invoked either early via
+ * the LIVEUPDATE_SESSION_FREEZE ioctl once userspace is done modifying
+ * the session's files, or during the reboot() syscall.
* - unfreeze(): Undoes the actions of .freeze(), called if the live update
* is aborted after the freeze phase.
* - retrieve(): Reconstructs the file in the new kernel from the preserved
@@ -48,7 +48,8 @@
* handler, calls its .preserve() operation, and creates an internal &struct
* luo_file to track the live state.
*
- * 2. Freeze (Pre-Reboot): Just before the kexec, luo_file_freeze() is called.
+ * 2. Freeze (Pre-Reboot): Either explicitly via LIVEUPDATE_SESSION_FREEZE or
+ * just before the kexec during reboot(), luo_file_freeze() is called.
* It iterates through all preserved files, calls their respective .freeze()
* operation, and serializes their final metadata (compatible string, token,
* and data handle) into a contiguous memory block for KHO.
@@ -111,6 +112,7 @@
#include <linux/xarray.h>
#include <linux/slab.h>
#include <linux/string.h>
+#include <linux/uaccess.h>
#include "luo_internal.h"
static LIST_HEAD(luo_file_handler_list);
@@ -136,9 +138,10 @@ static DEFINE_XARRAY(luo_preserved_files);
* @retrieve_status: Status code indicating whether a user/kernel in the new kernel has
* successfully called retrieve() on this file. This prevents
* multiple retrieval attempts. A value of 0 means a retrieve()
- * has not been attempted, a positive value means the retrieve()
- * was successful, and a negative value means the retrieve()
- * failed, and the value is the error code of the call.
+ * has not been attempted (or only failed with a retryable
+ * error), a positive value means the retrieve() was successful,
+ * and a negative value means the retrieve() permanently failed,
+ * and the value is the error code of the call.
* @mutex: A mutex that protects the fields of this specific instance
* (e.g., @retrieved, @file), ensuring that operations like
* retrieving or finishing a file are atomic.
@@ -175,6 +178,36 @@ static unsigned long luo_get_id(struct liveupdate_file_handler *fh,
return fh->ops->get_id ? fh->ops->get_id(file) : (unsigned long)file;
}
+/**
+ * liveupdate_claim_file - Claim a file in the LUO preserved files table.
+ * @fh: The file handler claiming @file.
+ * @file: The file to claim.
+ *
+ * File handlers whose .retrieve() callback restores state into an existing
+ * user-supplied &struct file (rather than allocating a new one) should call
+ * this before modifying @file to ensure @file is not already managed by LUO.
+ *
+ * Return: 0 on success, -EBUSY if @file is already managed by LUO, or a
+ * negative errno on allocation failure.
+ */
+int liveupdate_claim_file(struct liveupdate_file_handler *fh,
+ struct file *file)
+{
+ return xa_insert(&luo_preserved_files, luo_get_id(fh, file),
+ file, GFP_KERNEL);
+}
+
+/**
+ * liveupdate_unclaim_file - Release a claimed file from the LUO preserved files table.
+ * @fh: The file handler that claimed @file.
+ * @file: The file to release.
+ */
+void liveupdate_unclaim_file(struct liveupdate_file_handler *fh,
+ struct file *file)
+{
+ xa_erase(&luo_preserved_files, luo_get_id(fh, file));
+}
+
static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
{
struct luo_file *iter;
@@ -187,11 +220,45 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
return false;
}
+static int luo_copy_user_arg(u64 user_arg, const void **argp,
+ const struct liveupdate_arg_spec *spec)
+{
+ void *karg __free(kfree) = NULL;
+ void __user *uptr;
+ u32 user_size;
+ int err;
+
+ if (!user_arg)
+ return 0;
+ if (!spec->size)
+ return -EOPNOTSUPP;
+
+ uptr = u64_to_user_ptr(user_arg);
+ if (get_user(user_size, (u32 __user *)uptr))
+ return -EFAULT;
+ if (user_size < spec->min_size)
+ return -EINVAL;
+ if (user_size > PAGE_SIZE)
+ return -E2BIG;
+
+ karg = kmalloc(spec->size, GFP_KERNEL);
+ if (!karg)
+ return -ENOMEM;
+
+ err = copy_struct_from_user(karg, spec->size, uptr, user_size);
+ if (err)
+ return err;
+
+ *argp = no_free_ptr(karg);
+ return 0;
+}
+
/**
* luo_preserve_file - Initiate the preservation of a file descriptor.
* @file_set: The file_set to which the preserved file will be added.
* @token: A unique, user-provided identifier for the file.
* @fd: The file descriptor to be preserved.
+ * @arg: User-space pointer to the handler argument structure, or 0.
*
* This function orchestrates the first phase of preserving a file. Upon entry,
* it takes a reference to the 'struct file' via fget(), effectively making LUO
@@ -207,9 +274,11 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
* (allocates if needed).
* 3. Iterates through registered handlers, calling can_preserve() to find one
* compatible with the given @fd.
- * 4. Calls the handler's .preserve() operation, which saves the file's state
+ * 4. Copies the user argument structure (if @arg is non-zero) according to the
+ * handler's parg specification.
+ * 5. Calls the handler's .preserve() operation, which saves the file's state
* and returns an opaque private data handle.
- * 5. Adds the new instance to the file_set's internal list.
+ * 6. Adds the new instance to the file_set's internal list.
*
* On success, LUO takes a reference to the 'struct file' and considers it
* under its management until it is unpreserved or finished.
@@ -224,10 +293,12 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
* -EBADF if the file descriptor is invalid.
* -ENOSPC if the file_set is full.
* -ENOENT if no compatible handler is found.
+ * -EOPNOTSUPP if @arg is non-zero and the handler does not accept an arg.
* -ENOMEM on memory allocation failure.
* Other erros might be returned by .preserve().
*/
-int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
+int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd,
+ u64 arg)
{
struct liveupdate_file_op_args args = {0};
struct liveupdate_file_handler *fh;
@@ -263,10 +334,14 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
if (err)
goto err_fput;
+ err = luo_copy_user_arg(arg, &args.arg, &fh->ops->parg);
+ if (err)
+ goto err_module_put;
+
err = xa_insert(&luo_preserved_files, luo_get_id(fh, file),
file, GFP_KERNEL);
if (err)
- goto err_module_put;
+ goto err_free_arg;
err = luo_flb_file_preserve(fh);
if (err)
@@ -289,6 +364,7 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
if (err)
goto err_kfree;
+ kfree(args.arg);
luo_file->serialized_data = args.serialized_data;
luo_file->private_data = args.private_data;
list_add_tail(&luo_file->list, &file_set->files_list);
@@ -302,6 +378,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
luo_flb_file_unpreserve(fh);
err_erase_xa:
xa_erase(&luo_preserved_files, luo_get_id(fh, file));
+err_free_arg:
+ kfree(args.arg);
err_module_put:
module_put(fh->ops->owner);
err_fput:
@@ -422,11 +500,11 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
/**
* luo_file_freeze - Freezes all preserved files and serializes their metadata.
* @file_set: The file_set whose files are to be frozen.
- * @file_set_ser: Where to put the serialized file_set.
+ * @file_set_ser: Where to put the serialized file_set, or %NULL if freezing early.
*
- * This function is called from the reboot() syscall path, just before the
- * kernel transitions to the new image via kexec. Its purpose is to perform the
- * final preparation and serialization of all preserved files in the file_set.
+ * This function is called from the reboot() syscall path or from
+ * LIVEUPDATE_SESSION_FREEZE. Its purpose is to perform the preparation and
+ * serialization of all preserved files in the file_set.
*
* It iterates through each preserved file in FIFO order (the order of
* preservation) and performs two main actions:
@@ -449,7 +527,7 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
* running state. The function then returns an error, causing the reboot()
* syscall to fail.
*
- * Context: Called only from the liveupdate_reboot() path.
+ * Context: Called from the liveupdate_reboot() path or LIVEUPDATE_SESSION_FREEZE.
* Return: 0 on success, or a negative errno on failure.
*/
int luo_file_freeze(struct luo_file_set *file_set,
@@ -487,8 +565,10 @@ int luo_file_freeze(struct luo_file_set *file_set,
file_ser->token = luo_file->token;
}
- file_set_ser->count = file_set->count;
- file_set_ser->files = kho_block_set_head_pa(&file_set->block_set);
+ if (file_set_ser) {
+ file_set_ser->count = file_set->count;
+ file_set_ser->files = kho_block_set_head_pa(&file_set->block_set);
+ }
return 0;
@@ -501,7 +581,7 @@ int luo_file_freeze(struct luo_file_set *file_set,
/**
* luo_file_unfreeze - Unfreezes all files in a file_set and clear serialization
* @file_set: The file_set whose files are to be unfrozen.
- * @file_set_ser: Serialized file_set.
+ * @file_set_ser: Serialized file_set, or %NULL if not serialized yet.
*
* This function rolls back the state of all files in a file_set after the
* freeze phase has begun but must be aborted. It is the counterpart to
@@ -512,7 +592,8 @@ int luo_file_freeze(struct luo_file_set *file_set,
* their respective .unfreeze() handler callbacks.
*
* Context: This is called when the live update is aborted during
- * the reboot() syscall, after luo_file_freeze() has been called.
+ * the reboot() syscall, after luo_file_freeze() has been called,
+ * or when an early-frozen session is released before kexec.
*/
void luo_file_unfreeze(struct luo_file_set *file_set,
struct luo_file_set_ser *file_set_ser)
@@ -521,13 +602,15 @@ void luo_file_unfreeze(struct luo_file_set *file_set,
return;
__luo_file_unfreeze(file_set, NULL);
- memset(file_set_ser, 0, sizeof(*file_set_ser));
+ if (file_set_ser)
+ memset(file_set_ser, 0, sizeof(*file_set_ser));
}
/**
* luo_retrieve_file - Restores a preserved file from a file_set by its token.
* @file_set: The file_set from which to retrieve the file.
* @token: The unique token identifying the file to be restored.
+ * @arg: User-space pointer to the handler argument structure, or 0.
* @filep: Output parameter; on success, this is populated with a pointer
* to the newly retrieved 'struct file'.
*
@@ -538,7 +621,9 @@ void luo_file_unfreeze(struct luo_file_set *file_set,
* The operation is idempotent: if a file has already been successfully
* retrieved, this function will simply return a pointer to the existing
* 'struct file' and report success without re-executing the retrieve
- * operation. This is handled by checking the 'retrieved' flag under a lock.
+ * operation. If a previous retrieve failed permanently, it returns that
+ * saved error code; if a previous retrieve failed with a retryable error
+ * before consuming preserved state, the retrieve operation is re-attempted.
*
* File retrieval can happen in any order; it is not bound by the order of
* preservation.
@@ -547,9 +632,10 @@ void luo_file_unfreeze(struct luo_file_set *file_set,
* kernel.
* Return: 0 on success. Returns a negative errno on failure:
* -ENOENT if no file with the matching token is found.
+ * -EOPNOTSUPP if @arg is non-zero and the handler does not accept an arg.
* Any error code returned by the handler's .retrieve() op.
*/
-int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
+int luo_retrieve_file(struct luo_file_set *file_set, u64 token, u64 arg,
struct file **filep)
{
struct liveupdate_file_op_args args = {0};
@@ -586,12 +672,22 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
return 0;
}
+ err = luo_copy_user_arg(arg, &args.arg, &luo_file->fh->ops->rarg);
+ if (err)
+ return err;
+
args.handler = luo_file->fh;
args.serialized_data = luo_file->serialized_data;
err = luo_file->fh->ops->retrieve(&args);
+ kfree(args.arg);
if (err) {
- /* Keep the error code for later use. */
- luo_file->retrieve_status = err;
+ /*
+ * Keep the error code for later use unless the handler marked
+ * the failure as retryable (e.g. invalid user argument before
+ * preserved state was consumed).
+ */
+ if (!args.retryable)
+ luo_file->retrieve_status = err;
return err;
}
@@ -599,9 +695,9 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
/* Get reference so we can keep this file in LUO until finish */
get_file(luo_file->file);
- WARN_ON(xa_insert(&luo_preserved_files,
- luo_get_id(luo_file->fh, luo_file->file),
- luo_file->file, GFP_KERNEL));
+ if (xa_load(&luo_preserved_files,
+ luo_get_id(luo_file->fh, luo_file->file)) != luo_file->file)
+ WARN_ON(liveupdate_claim_file(luo_file->fh, luo_file->file));
*filep = luo_file->file;
luo_file->retrieve_status = 1;
diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index 64879ffe73781..3bd9ef442934e 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -64,6 +64,8 @@ struct luo_file_set {
* previous kernel) sessions.
* @retrieved: A boolean flag indicating whether this session has been
* retrieved by a consumer in the new kernel.
+ * @frozen: A boolean flag indicating whether this session has been
+ * frozen early from userspace.
* @file_set: A set of files that belong to this session.
* @mutex: protects fields in the luo_session.
*/
@@ -71,6 +73,7 @@ struct luo_session {
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
struct list_head list;
bool retrieved;
+ bool frozen;
struct luo_file_set file_set;
struct mutex mutex;
};
@@ -84,13 +87,14 @@ int __init luo_session_setup_incoming(u64 sessions_pa);
int luo_session_serialize(void);
int luo_session_deserialize(void);
-int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd);
+int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd,
+ u64 arg);
void luo_file_unpreserve_files(struct luo_file_set *file_set);
int luo_file_freeze(struct luo_file_set *file_set,
struct luo_file_set_ser *file_set_ser);
void luo_file_unfreeze(struct luo_file_set *file_set,
struct luo_file_set_ser *file_set_ser);
-int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
+int luo_retrieve_file(struct luo_file_set *file_set, u64 token, u64 arg,
struct file **filep);
int luo_file_finish(struct luo_file_set *file_set);
int luo_file_deserialize(struct luo_file_set *file_set,
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index f48e9a4185f97..74f8a1bf1da8c 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -34,10 +34,11 @@
* 1. Creation: A userspace agent calls `luo_session_create()` to create a
* new, empty session and receives a file descriptor for it.
*
- * 2. Serialization: When the `reboot(LINUX_REBOOT_CMD_KEXEC)` syscall is
- * made, `luo_session_serialize()` is called. It iterates through all
- * active sessions and writes their metadata into a memory area preserved
- * by KHO.
+ * 2. Freeze / Serialization: Sessions may be frozen early from userspace
+ * via `LIVEUPDATE_SESSION_FREEZE`. When the `reboot(LINUX_REBOOT_CMD_KEXEC)`
+ * syscall is made, `luo_session_serialize()` is called to freeze any
+ * remaining active sessions and write all session metadata into a memory
+ * area preserved by KHO.
*
* 3. Deserialization (in new kernel): After kexec, `luo_session_deserialize()`
* runs, reading the serialized data and creating a list of `struct
@@ -222,6 +223,10 @@ static void luo_session_unfreeze_one(struct luo_session *session,
struct luo_session_ser *ser)
{
guard(mutex)(&session->mutex);
+ if (session->frozen) {
+ memset(&ser->file_set_ser, 0, sizeof(ser->file_set_ser));
+ return;
+ }
luo_file_unfreeze(&session->file_set, &ser->file_set_ser);
}
@@ -229,6 +234,12 @@ static int luo_session_freeze_one(struct luo_session *session,
struct luo_session_ser *ser)
{
guard(mutex)(&session->mutex);
+ if (session->frozen) {
+ ser->file_set_ser.count = session->file_set.count;
+ ser->file_set_ser.files =
+ kho_block_set_head_pa(&session->file_set.block_set);
+ return 0;
+ }
return luo_file_freeze(&session->file_set, &ser->file_set_ser);
}
@@ -249,8 +260,11 @@ static int luo_session_release(struct inode *inodep, struct file *filep)
}
sh = &luo_session_global.incoming;
} else {
- scoped_guard(mutex, &session->mutex)
+ scoped_guard(mutex, &session->mutex) {
+ if (session->frozen)
+ luo_file_unfreeze(&session->file_set, NULL);
luo_file_unpreserve_files(&session->file_set);
+ }
sh = &luo_session_global.outgoing;
}
@@ -267,7 +281,11 @@ static int luo_session_preserve_fd(struct luo_session *session,
int err;
guard(mutex)(&session->mutex);
- err = luo_preserve_file(&session->file_set, argp->token, argp->fd);
+ if (session->frozen)
+ return -EBUSY;
+
+ err = luo_preserve_file(&session->file_set, argp->token, argp->fd,
+ argp->arg);
if (err)
return err;
@@ -290,7 +308,8 @@ static int luo_session_retrieve_fd(struct luo_session *session,
return argp->fd;
mutex_lock(&session->mutex);
- err = luo_retrieve_file(&session->file_set, argp->token, &file);
+ err = luo_retrieve_file(&session->file_set, argp->token, argp->arg,
+ &file);
mutex_unlock(&session->mutex);
if (err < 0)
goto err_put_fd;
@@ -340,11 +359,34 @@ static int luo_session_get_name(struct luo_session *session,
return luo_ucmd_respond(ucmd, sizeof(*argp));
}
+static int luo_session_freeze(struct luo_session *session,
+ struct luo_ucmd *ucmd)
+{
+ struct liveupdate_session_freeze *argp = ucmd->cmd;
+ int err;
+
+ if (argp->reserved)
+ return -EINVAL;
+
+ guard(mutex)(&session->mutex);
+ if (session->frozen)
+ return -EBUSY;
+
+ err = luo_file_freeze(&session->file_set, NULL);
+ if (err)
+ return err;
+
+ session->frozen = true;
+
+ return luo_ucmd_respond(ucmd, sizeof(*argp));
+}
+
union ucmd_buffer {
struct liveupdate_session_finish finish;
struct liveupdate_session_preserve_fd preserve;
struct liveupdate_session_retrieve_fd retrieve;
struct liveupdate_session_get_name get_name;
+ struct liveupdate_session_freeze freeze;
};
/* Type of sessions the ioctl applies to. */
@@ -382,6 +424,8 @@ static const struct luo_ioctl_op luo_session_ioctl_ops[] = {
struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),
IOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,
struct liveupdate_session_get_name, name, LUO_IOCTL_ALL),
+ IOCTL_OP(LIVEUPDATE_SESSION_FREEZE, luo_session_freeze,
+ struct liveupdate_session_freeze, reserved, LUO_IOCTL_OUTGOING),
};
static bool luo_ioctl_type_valid(struct luo_session *session,
diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
index 59de210bee5f9..9d18f01191c07 100644
--- a/mm/memfd_luo.c
+++ b/mm/memfd_luo.c
@@ -9,14 +9,14 @@
*/
/**
- * DOC: Memfd Preservation via LUO
+ * DOC: Memfd and Tmpfs Preservation via LUO
*
* Overview
* ========
*
- * Memory file descriptors (memfd) can be preserved over a kexec using the Live
- * Update Orchestrator (LUO) file preservation. This allows userspace to
- * transfer its memory contents to the next kernel after a kexec.
+ * Memory file descriptors and generic tmpfs files can be preserved over a
+ * kexec using the LUO file preservation. This allows userspace to transfer its
+ * memory contents to the next kernel after a kexec.
*
* The preservation is not intended to be transparent. Only select properties of
* the file are preserved. All others are reset to default. The preserved
@@ -24,16 +24,17 @@
*
* .. note::
* The LUO API is not stabilized yet, so the preserved properties of a memfd
- * are also not stable and are subject to backwards incompatible changes.
+ * or tmpfs file are also not stable and are subject to backwards
+ * incompatible changes.
*
* .. note::
- * Currently a memfd backed by Hugetlb is not supported. Memfds created
+ * Currently a file backed by Hugetlb is not supported. Memfds created
* with ``MFD_HUGETLB`` will be rejected.
*
* Preserved Properties
* ====================
*
- * The following properties of the memfd are preserved across kexec:
+ * The following properties of the memfd/tmpfs file are preserved across kexec:
*
* File Contents
* All data stored in the file is preserved.
@@ -43,8 +44,9 @@
* allocating pages for them during preservation.
*
* File Position
- * The current file position is preserved, allowing applications to continue
- * reading/writing from their last position.
+ * The file position at the time the session is frozen is preserved,
+ * allowing applications to continue reading/writing from their last
+ * position.
*
* File Status Flags
* memfds are always opened with ``O_RDWR`` and ``O_LARGEFILE``. This property
@@ -299,6 +301,8 @@ static int memfd_luo_preserve(struct liveupdate_file_op_args *args)
ser->size = inode_size;
ser->seals = seals;
+ if (inode->i_nlink)
+ ser->flags |= MEMFD_LUO_FLAG_TMPFS;
err = memfd_luo_preserve_folios(args->file, &ser->folios,
&folios_ser, &nr_folios);
@@ -515,10 +519,60 @@ static int memfd_luo_retrieve_folios(struct file *file,
return err;
}
+static struct file *memfd_luo_get_tmpfs_file(struct liveupdate_file_op_args *args)
+{
+ const struct liveupdate_memfd_retrieve_arg *rarg = args->arg;
+ struct inode *inode;
+ struct file *file;
+ int err;
+
+ if (!rarg)
+ return ERR_PTR(-EINVAL);
+
+ file = fget(rarg->fd);
+ if (!file)
+ return ERR_PTR(-EBADF);
+
+ if (!(file->f_mode & FMODE_WRITE)) {
+ err = -EACCES;
+ goto put_file;
+ }
+
+ if (!shmem_file(file)) {
+ err = -EINVAL;
+ goto put_file;
+ }
+
+ inode = file_inode(file);
+ inode_lock(inode);
+ if (!inode->i_nlink) {
+ err = -EINVAL;
+ goto unlock_inode;
+ }
+
+ if (i_size_read(inode) != 0 || !mapping_empty(inode->i_mapping)) {
+ err = -EBUSY;
+ goto unlock_inode;
+ }
+
+ err = liveupdate_claim_file(args->handler, file);
+ if (err)
+ goto unlock_inode;
+
+ return file;
+
+unlock_inode:
+ inode_unlock(inode);
+put_file:
+ fput(file);
+ return ERR_PTR(err);
+}
+
static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)
{
struct memfd_luo_folio_ser *folios_ser;
struct memfd_luo_ser *ser;
+ struct inode *inode;
struct file *file;
int err;
@@ -526,50 +580,75 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)
if (!ser)
return -EINVAL;
- /* Make sure the file only has seals supported by this version. */
- if (ser->seals & ~MEMFD_LUO_ALL_SEALS) {
+ /* Make sure the file only has seals and flags supported by this version. */
+ if ((ser->seals & ~MEMFD_LUO_ALL_SEALS) ||
+ (ser->flags & ~MEMFD_LUO_ALL_FLAGS)) {
err = -EOPNOTSUPP;
goto free_ser;
}
- /*
- * The seals are preserved. Allow sealing here so they can be added
- * later.
- */
- file = memfd_alloc_file("", MFD_ALLOW_SEALING);
- if (IS_ERR(file)) {
- pr_err("failed to setup file: %pe\n", file);
- err = PTR_ERR(file);
- goto free_ser;
- }
+ if (ser->flags & MEMFD_LUO_FLAG_TMPFS) {
+ file = memfd_luo_get_tmpfs_file(args);
+ if (IS_ERR(file)) {
+ args->retryable = true;
+ return PTR_ERR(file);
+ }
+ inode = file_inode(file);
+ } else {
+ if (args->arg) {
+ args->retryable = true;
+ return -EINVAL;
+ }
- err = memfd_add_seals(file, ser->seals);
- if (err) {
- pr_err("failed to add seals: %pe\n", ERR_PTR(err));
- goto put_file;
- }
+ /*
+ * The seals are preserved. Allow sealing here so they can be
+ * added later.
+ */
+ file = memfd_alloc_file("", MFD_ALLOW_SEALING);
+ if (IS_ERR(file)) {
+ pr_err("failed to setup file: %pe\n", file);
+ err = PTR_ERR(file);
+ goto free_ser;
+ }
- vfs_setpos(file, ser->pos, MAX_LFS_FILESIZE);
- i_size_write(file_inode(file), ser->size);
+ err = memfd_add_seals(file, ser->seals);
+ if (err) {
+ pr_err("failed to add seals: %pe\n", ERR_PTR(err));
+ goto put_file;
+ }
+
+ inode = file_inode(file);
+ inode_lock(inode);
+ }
if (ser->nr_folios) {
folios_ser = kho_restore_vmalloc(&ser->folios);
if (!folios_ser) {
err = -EINVAL;
- goto put_file;
+ goto unclaim_file;
}
err = memfd_luo_retrieve_folios(file, folios_ser, ser->nr_folios);
vfree(folios_ser);
if (err)
- goto put_file;
+ goto unclaim_file;
}
+ vfs_setpos(file, ser->pos, MAX_LFS_FILESIZE);
+ i_size_write(inode, ser->size);
+ inode_unlock(inode);
+
args->file = file;
kho_restore_free(ser);
return 0;
+unclaim_file:
+ if (ser->flags & MEMFD_LUO_FLAG_TMPFS) {
+ shmem_truncate_range(inode, 0, (loff_t)-1);
+ liveupdate_unclaim_file(args->handler, file);
+ }
+ inode_unlock(inode);
put_file:
fput(file);
free_ser:
@@ -580,9 +659,7 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)
static bool memfd_luo_can_preserve(struct liveupdate_file_handler *handler,
struct file *file)
{
- struct inode *inode = file_inode(file);
-
- return shmem_file(file) && !inode->i_nlink;
+ return shmem_file(file);
}
static unsigned long memfd_luo_get_id(struct file *file)
@@ -598,6 +675,7 @@ static const struct liveupdate_file_ops memfd_luo_file_ops = {
.unpreserve = memfd_luo_unpreserve,
.can_preserve = memfd_luo_can_preserve,
.get_id = memfd_luo_get_id,
+ .rarg = LIVEUPDATE_ARG(struct liveupdate_memfd_retrieve_arg, fd),
.owner = THIS_MODULE,
};
diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
index fa07fed083646..dc5c01408462d 100644
--- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
+++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
@@ -26,13 +26,19 @@ int luo_create_session(int luo_fd, const char *name);
int luo_retrieve_session(int luo_fd, const char *name);
int luo_session_finish(int session_fd);
int luo_get_session_name(int session_fd, char *name, size_t name_len);
+int luo_session_freeze(int session_fd);
int luo_ensure_nofile_limit(long min_limit);
int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
+int luo_session_preserve_fd_arg(int session_fd, int fd, __u64 token,
+ __u64 user_arg);
int luo_session_retrieve_fd(int session_fd, __u64 token);
+int luo_session_retrieve_fd_arg(int session_fd, __u64 token, __u64 user_arg);
int create_and_preserve_memfd(int session_fd, int token, const char *data);
int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
+int restore_and_verify_tmpfs(int session_fd, int token, int fd,
+ const char *expected_data);
void create_state_file(int luo_fd, const char *session_name, int token,
int next_stage);
diff --git a/tools/testing/selftests/liveupdate/lib/lu_utils.c b/tools/testing/selftests/liveupdate/lib/lu_utils.c
index 74d41115c2815..1b1a556287d3a 100644
--- a/tools/testing/selftests/liveupdate/lib/lu_utils.c
+++ b/tools/testing/selftests/liveupdate/lib/lu_utils.c
@@ -79,12 +79,14 @@ int luo_retrieve_session(int luo_fd, const char *name)
return arg.fd;
}
-int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
+int luo_session_preserve_fd_arg(int session_fd, int fd, __u64 token,
+ __u64 user_arg)
{
struct liveupdate_session_preserve_fd arg = {
.size = sizeof(arg),
.fd = fd,
.token = token,
+ .arg = user_arg,
};
if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg))
@@ -93,11 +95,17 @@ int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
return 0;
}
-int luo_session_retrieve_fd(int session_fd, __u64 token)
+int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
+{
+ return luo_session_preserve_fd_arg(session_fd, fd, token, 0);
+}
+
+int luo_session_retrieve_fd_arg(int session_fd, __u64 token, __u64 user_arg)
{
struct liveupdate_session_retrieve_fd arg = {
.size = sizeof(arg),
.token = token,
+ .arg = user_arg,
};
if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg))
@@ -106,6 +114,11 @@ int luo_session_retrieve_fd(int session_fd, __u64 token)
return arg.fd;
}
+int luo_session_retrieve_fd(int session_fd, __u64 token)
+{
+ return luo_session_retrieve_fd_arg(session_fd, token, 0);
+}
+
/* Helper function to get a session name via ioctl. */
int luo_get_session_name(int session_fd, char *name, size_t name_len)
{
@@ -198,6 +211,16 @@ int luo_session_finish(int session_fd)
return 0;
}
+int luo_session_freeze(int session_fd)
+{
+ struct liveupdate_session_freeze arg = { .size = sizeof(arg) };
+
+ if (ioctl(session_fd, LIVEUPDATE_SESSION_FREEZE, &arg) < 0)
+ return -errno;
+
+ return 0;
+}
+
void create_state_file(int luo_fd, const char *session_name, int token,
int next_stage)
{
@@ -324,3 +347,47 @@ int luo_test(int argc, char *argv[],
return 0;
}
+
+int restore_and_verify_tmpfs(int session_fd, int token, int fd,
+ const char *expected_data)
+{
+ struct liveupdate_memfd_retrieve_arg rarg = {
+ .size = sizeof(rarg),
+ .fd = fd,
+ };
+ long page_size = getpagesize();
+ void *map = MAP_FAILED;
+ struct stat st;
+ int ret_fd;
+
+ ret_fd = luo_session_retrieve_fd_arg(session_fd, token,
+ (unsigned long)&rarg);
+ if (ret_fd < 0) {
+ ksft_print_msg("luo_session_retrieve_fd_arg failed: %d\n",
+ ret_fd);
+ return ret_fd;
+ }
+ close(ret_fd);
+
+ if (fstat(fd, &st) < 0)
+ return -errno;
+ if (st.st_size != page_size) {
+ ksft_print_msg("Size mismatch! Expected %ld, Got %lld\n",
+ page_size, (long long)st.st_size);
+ return -EINVAL;
+ }
+
+ map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (map == MAP_FAILED)
+ return -errno;
+
+ if (expected_data && strcmp(expected_data, map) != 0) {
+ ksft_print_msg("Data mismatch! Expected '%s', Got '%s'\n",
+ expected_data, (char *)map);
+ munmap(map, page_size);
+ return -EINVAL;
+ }
+
+ munmap(map, page_size);
+ return 0;
+}
diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c
index 2dedd5fc2534f..83e0978f3818d 100644
--- a/tools/testing/selftests/liveupdate/liveupdate.c
+++ b/tools/testing/selftests/liveupdate/liveupdate.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <stddef.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
@@ -530,4 +531,87 @@ TEST_F(liveupdate_device, preserve_many_files)
ASSERT_EQ(close(session_fd), 0);
}
+/*
+ * Test Case: Session Freeze
+ *
+ * Verifies that an outgoing session can be frozen early via
+ * LIVEUPDATE_SESSION_FREEZE, that subsequent freeze attempts return -EBUSY,
+ * and that attempting to preserve an additional file descriptor into a frozen
+ * session fails with -EBUSY.
+ */
+TEST_F(liveupdate_device, session_freeze)
+{
+ int session_fd, mem_fd1, mem_fd2;
+
+ self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
+ if (self->fd1 < 0 && errno == ENOENT)
+ SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
+ ASSERT_GE(self->fd1, 0);
+
+ session_fd = luo_create_session(self->fd1, "session-freeze-test");
+ ASSERT_GE(session_fd, 0);
+
+ mem_fd1 = memfd_create("freeze-memfd-1", 0);
+ ASSERT_GE(mem_fd1, 0);
+ ASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fd1, 0x1111), 0);
+
+ /* Freeze the session early */
+ ASSERT_EQ(luo_session_freeze(session_fd), 0);
+
+ /* Subsequent freeze attempt on an already frozen session must fail with -EBUSY */
+ EXPECT_EQ(luo_session_freeze(session_fd), -EBUSY);
+
+ /* Preserving a file after freeze must fail with -EBUSY */
+ mem_fd2 = memfd_create("freeze-memfd-2", 0);
+ ASSERT_GE(mem_fd2, 0);
+ EXPECT_EQ(luo_session_preserve_fd(session_fd, mem_fd2, 0x2222), -EBUSY);
+
+ ASSERT_EQ(close(session_fd), 0);
+ ASSERT_EQ(close(mem_fd1), 0);
+ ASSERT_EQ(close(mem_fd2), 0);
+}
+
+/*
+ * Test Case: Preserve MemFD with User Argument
+ *
+ * Verifies that passing a non-zero user argument to memfd preservation fails
+ * with -EOPNOTSUPP, while passing a zero argument or using the minimum struct
+ * size without the arg field succeeds.
+ */
+TEST_F(liveupdate_device, preserve_memfd_with_arg)
+{
+ struct liveupdate_session_preserve_fd min_arg = {};
+ int session_fd, mem_fd1, mem_fd2;
+
+ self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
+ if (self->fd1 < 0 && errno == ENOENT)
+ SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
+ ASSERT_GE(self->fd1, 0);
+
+ session_fd = luo_create_session(self->fd1, "preserve-arg-test");
+ ASSERT_GE(session_fd, 0);
+
+ mem_fd1 = memfd_create("arg-memfd-1", 0);
+ ASSERT_GE(mem_fd1, 0);
+
+ /* Non-zero arg is not supported by memfd handler */
+ EXPECT_EQ(luo_session_preserve_fd_arg(session_fd, mem_fd1, 0x1111, 1),
+ -EOPNOTSUPP);
+
+ /* Legacy struct size (up to token) should zero-fill arg and succeed */
+ min_arg.size = offsetof(struct liveupdate_session_preserve_fd, arg);
+ min_arg.fd = mem_fd1;
+ min_arg.token = 0x1111;
+ ASSERT_EQ(ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &min_arg), 0);
+
+ /* Explicit zero arg with full struct size should also succeed */
+ mem_fd2 = memfd_create("arg-memfd-2", 0);
+ ASSERT_GE(mem_fd2, 0);
+ ASSERT_EQ(luo_session_preserve_fd_arg(session_fd, mem_fd2, 0x2222, 0), 0);
+
+ ASSERT_EQ(close(session_fd), 0);
+ ASSERT_EQ(close(mem_fd1), 0);
+ ASSERT_EQ(close(mem_fd2), 0);
+}
+
TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/liveupdate/luo_kexec_simple.c b/tools/testing/selftests/liveupdate/luo_kexec_simple.c
index 786ac93b9ae38..ab108c7f1d855 100644
--- a/tools/testing/selftests/liveupdate/luo_kexec_simple.c
+++ b/tools/testing/selftests/liveupdate/luo_kexec_simple.c
@@ -40,6 +40,11 @@ static void run_stage_1(int luo_fd)
TEST_MEMFD_TOKEN);
}
+ ksft_print_msg("[STAGE 1] Freezing session '%s' early...\n",
+ TEST_SESSION_NAME);
+ if (luo_session_freeze(session_fd) < 0)
+ fail_exit("luo_session_freeze for '%s'", TEST_SESSION_NAME);
+
close(luo_fd);
daemonize_and_wait();
}
diff --git a/tools/testing/selftests/liveupdate/luo_multi_session.c b/tools/testing/selftests/liveupdate/luo_multi_session.c
index aac24a5f5ce3c..46889676d9f52 100644
--- a/tools/testing/selftests/liveupdate/luo_multi_session.c
+++ b/tools/testing/selftests/liveupdate/luo_multi_session.c
@@ -9,7 +9,15 @@
* files.
*/
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#include <libliveupdate.h>
+#include <linux/liveupdate.h>
#define SESSION_EMPTY_1 "multi-test-empty-1"
#define SESSION_EMPTY_2 "multi-test-empty-2"
@@ -23,6 +31,7 @@
#define MFD1_DATA "Data for session files 1"
#define MFD2_DATA "First file for session files 2"
#define MFD3_DATA "Second file for session files 2"
+#define MFD3_POS 42
#define STATE_SESSION_NAME "kexec_multi_state"
#define STATE_MEMFD_TOKEN 998
@@ -31,6 +40,8 @@
static void run_stage_1(int luo_fd)
{
int s_empty1_fd, s_empty2_fd, s_files1_fd, s_files2_fd;
+ int tmpfs_fd;
+ void *map;
ksft_print_msg("[STAGE 1] Starting pre-kexec setup for multi-session test...\n");
@@ -53,25 +64,50 @@ static void run_stage_1(int luo_fd)
s_files1_fd = luo_create_session(luo_fd, SESSION_FILES_1);
if (s_files1_fd < 0)
fail_exit("luo_create_session for '%s'", SESSION_FILES_1);
+ ksft_print_msg(" -> Preserving memfd (token %#x, content: \"%s\")\n",
+ MFD1_TOKEN, MFD1_DATA);
if (create_and_preserve_memfd(s_files1_fd, MFD1_TOKEN, MFD1_DATA) < 0) {
fail_exit("create_and_preserve_memfd for token %#x",
MFD1_TOKEN);
}
- ksft_print_msg("[STAGE 1] Creating session '%s' with two memfds...\n",
+ ksft_print_msg("[STAGE 1] Creating session '%s' with memfd and tmpfs file...\n",
SESSION_FILES_2);
s_files2_fd = luo_create_session(luo_fd, SESSION_FILES_2);
if (s_files2_fd < 0)
fail_exit("luo_create_session for '%s'", SESSION_FILES_2);
+ ksft_print_msg(" -> Preserving memfd (token %#x, content: \"%s\")\n",
+ MFD2_TOKEN, MFD2_DATA);
if (create_and_preserve_memfd(s_files2_fd, MFD2_TOKEN, MFD2_DATA) < 0) {
fail_exit("create_and_preserve_memfd for token %#x",
MFD2_TOKEN);
}
- if (create_and_preserve_memfd(s_files2_fd, MFD3_TOKEN, MFD3_DATA) < 0) {
- fail_exit("create_and_preserve_memfd for token %#x",
- MFD3_TOKEN);
- }
+
+ ksft_print_msg(" -> Populating tmpfs file at /mnt/mfd3...\n");
+ if (mkdir("/mnt", 0777) < 0 && errno != EEXIST)
+ fail_exit("mkdir /mnt");
+ if (mount("tmpfs", "/mnt", "tmpfs", 0, NULL) < 0)
+ fail_exit("mount tmpfs");
+ tmpfs_fd = open("/mnt/mfd3", O_CREAT | O_RDWR, 0666);
+ if (tmpfs_fd < 0)
+ fail_exit("failed to open tmpfs_fd");
+ ksft_print_msg(" -> Preserving generic tmpfs file (token %#x, content: \"%s\")\n",
+ MFD3_TOKEN, MFD3_DATA);
+ if (ftruncate(tmpfs_fd, getpagesize()) < 0)
+ fail_exit("ftruncate tmpfs_fd");
+ map = mmap(NULL, getpagesize(), PROT_WRITE, MAP_SHARED, tmpfs_fd, 0);
+ if (map == MAP_FAILED)
+ fail_exit("mmap tmpfs_fd");
+ strcpy(map, MFD3_DATA);
+ munmap(map, getpagesize());
+ if (lseek(tmpfs_fd, MFD3_POS, SEEK_SET) != MFD3_POS)
+ fail_exit("lseek tmpfs_fd");
+
+ if (luo_session_preserve_fd(s_files2_fd, tmpfs_fd, MFD3_TOKEN) < 0)
+ fail_exit("preserve tmpfs fd");
+
+ close(tmpfs_fd);
close(luo_fd);
daemonize_and_wait();
@@ -81,7 +117,10 @@ static void run_stage_1(int luo_fd)
static void run_stage_2(int luo_fd, int state_session_fd)
{
int s_empty1_fd, s_empty2_fd, s_files1_fd, s_files2_fd;
- int mfd1, mfd2, mfd3, stage;
+ struct liveupdate_memfd_retrieve_arg rarg = {
+ .size = sizeof(rarg),
+ };
+ int mfd1, mfd2, mfd3, ro_fd, ret, stage;
ksft_print_msg("[STAGE 2] Starting post-kexec verification...\n");
@@ -110,6 +149,8 @@ static void run_stage_2(int luo_fd, int state_session_fd)
ksft_print_msg("[STAGE 2] Verifying contents of session '%s'...\n",
SESSION_FILES_1);
+ ksft_print_msg(" -> Retrieving memfd (token %#x) from session...\n",
+ MFD1_TOKEN);
mfd1 = restore_and_verify_memfd(s_files1_fd, MFD1_TOKEN, MFD1_DATA);
if (mfd1 < 0)
fail_exit("restore_and_verify_memfd for token %#x", MFD1_TOKEN);
@@ -118,14 +159,65 @@ static void run_stage_2(int luo_fd, int state_session_fd)
ksft_print_msg("[STAGE 2] Verifying contents of session '%s'...\n",
SESSION_FILES_2);
+ ksft_print_msg(" -> Creating empty tmpfs file at /mnt/mfd3...\n");
+ if (mkdir("/mnt", 0777) < 0 && errno != EEXIST)
+ fail_exit("mkdir /mnt");
+ if (mount("tmpfs", "/mnt", "tmpfs", 0, NULL) < 0)
+ fail_exit("mount tmpfs");
+ mfd3 = open("/mnt/mfd3", O_CREAT | O_RDWR, 0666);
+ if (mfd3 < 0)
+ fail_exit("open tmpfs file");
+ ro_fd = open("/mnt/mfd3", O_RDONLY);
+ if (ro_fd < 0)
+ fail_exit("open read-only tmpfs file");
+
+ ksft_print_msg(" -> Verifying retryable retrieve errors for memfd and tmpfs...\n");
+ rarg.fd = mfd3;
+ ret = luo_session_retrieve_fd_arg(s_files2_fd, MFD2_TOKEN,
+ (uintptr_t)&rarg);
+ if (ret != -EINVAL)
+ fail_exit("expected -EINVAL when passing arg to memfd retrieve, got %d",
+ ret);
+
+ ksft_print_msg(" -> Retrieving memfd (token %#x) from session...\n",
+ MFD2_TOKEN);
mfd2 = restore_and_verify_memfd(s_files2_fd, MFD2_TOKEN, MFD2_DATA);
if (mfd2 < 0)
fail_exit("restore_and_verify_memfd for token %#x", MFD2_TOKEN);
close(mfd2);
- mfd3 = restore_and_verify_memfd(s_files2_fd, MFD3_TOKEN, MFD3_DATA);
- if (mfd3 < 0)
- fail_exit("restore_and_verify_memfd for token %#x", MFD3_TOKEN);
+ ret = luo_session_retrieve_fd(s_files2_fd, MFD3_TOKEN);
+ if (ret != -EINVAL)
+ fail_exit("expected -EINVAL when retrieving tmpfs without arg, got %d",
+ ret);
+
+ rarg.fd = ro_fd;
+ ret = luo_session_retrieve_fd_arg(s_files2_fd, MFD3_TOKEN,
+ (uintptr_t)&rarg);
+ if (ret != -EACCES)
+ fail_exit("expected -EACCES when retrieving tmpfs into read-only fd, got %d",
+ ret);
+ close(ro_fd);
+
+ if (ftruncate(mfd3, 1) < 0)
+ fail_exit("ftruncate non-empty tmpfs file");
+ rarg.fd = mfd3;
+ ret = luo_session_retrieve_fd_arg(s_files2_fd, MFD3_TOKEN,
+ (uintptr_t)&rarg);
+ if (ret != -EBUSY)
+ fail_exit("expected -EBUSY when retrieving tmpfs into non-empty fd, got %d",
+ ret);
+ if (ftruncate(mfd3, 0) < 0)
+ fail_exit("ftruncate empty tmpfs file");
+
+ ksft_print_msg(" -> Retrieving tmpfs file (token %#x) from session...\n",
+ MFD3_TOKEN);
+ if (restore_and_verify_tmpfs(s_files2_fd, MFD3_TOKEN, mfd3,
+ MFD3_DATA) < 0)
+ fail_exit("restore_and_verify_tmpfs for token %#x",
+ MFD3_TOKEN);
+ if (lseek(mfd3, 0, SEEK_CUR) != MFD3_POS)
+ fail_exit("expected f_pos %d on restored tmpfs file", MFD3_POS);
close(mfd3);
ksft_print_msg("[STAGE 2] Test data verified successfully.\n");
|
| 3/2 | 2026/10/15 11:54 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22725 output: 28 thoughts: 474 Thoughts: **Analyzing the Live Update Patch** Okay, let's break this down. First, I need to get a clear picture of what this patch is doing. Judging from the file touches, it seems deeply involved with Live Update (LUO) functionality, and specifically, expanding its capabilities with memory file descriptors (memfd), potentially including tmpfs. I see changes across several areas: the header files which is a good starting point, like `memfd.h` with new flags (`MEMFD_LUO_FLAG_TMPFS`, etc.) which tells me tmpfs is definitely in the mix, and `liveupdate.h` and `uapi/linux/liveupdate.h` for the core LUO structures and commands related to session management, like freezing and retrieving. The core implementation is clearly in `kernel/liveupdate/luo_file.c` and `kernel/liveupdate/luo_session.c`. I see functions for claiming and unclaiming files, freezing, unfreezing, preserving file descriptors, and retrieving them. These are critical operations for any live update system, so I'd expect to see these. I also see internal prototypes in `luo_internal.h`, as expected. The presence of `mm/memfd_luo.c` is significant. This strongly suggests the patch adds the ability to use LUO with tmpfs files, not just anonymous memfds, which would be a useful addition. I see functions like `memfd_luo_get_tmpfs_file`, `memfd_luo_retrieve`, and `memfd_luo_can_preserve`. That confirms my suspicions. Finally, test coverage in `tools/testing/selftests/...` is always good to see. Now, I need to understand how this is enabled, the kernel configs and how it integrates with the rest of the system. Let's use `grepper` or check the directory structure to see the subsystem and dependencies, and how it is configured. This will tell me how broad or narrow the changes might be. |
| 4/2 | 2026/10/15 11:54 | tool | grepper |
0mArgs:{
"Expression": "config LIVEUPDATE|config MEMFD_LUO|config KHO"
}Results: {
"Output": "kernel/liveupdate/Kconfig=38=config KEXEC_HANDOVER_ENABLE_DEFAULT\n--\nkernel/liveupdate/Kconfig-51-\nkernel/liveupdate/Kconfig:52:config LIVEUPDATE\nkernel/liveupdate/Kconfig-53-\tbool \"Live Update Orchestrator\"\n--\nkernel/liveupdate/Kconfig-72-\nkernel/liveupdate/Kconfig:73:config LIVEUPDATE_MEMFD\nkernel/liveupdate/Kconfig-74-\tbool \"Live update support for memfd\"\n--\nlib/Kconfig.debug=2872=config CONTEXT_ANALYSIS_TEST\n--\nlib/Kconfig.debug-2885-\nlib/Kconfig.debug:2886:config LIVEUPDATE_TEST\nlib/Kconfig.debug-2887-\tbool \"Live Update Kernel Test\"\n"
} |
| 5/2 | 2026/10/15 11:55 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23878 output: 34 thoughts: 13 Thoughts: Here's a summary of my thought process, as requested: **Diving into `kernel/liveupdate/Kconfig`** Okay, time to get my hands dirty. My focus is on the `kernel/liveupdate/Kconfig` file. I immediately recognize this as a configuration file, likely used within the kernel's build system, probably Kbuild. That means it contains the conditional logic that determines which live update features and options are compiled into the kernel image. I need to understand the configuration options and their dependencies within the live update subsystem. This file will give me the building blocks I need to investigate further. I'll be looking for things like: the main `LIVEUPDATE` option, dependencies on other kernel subsystems, any specific features like rollback or security enhancements, and any default settings that might be in place. It will probably be a good starting point to trace the full features of the LiveUpdate subsystem. |
| 6/2 | 2026/10/15 11:55 | tool | read-file |
0mArgs:{
"File": "kernel/liveupdate/Kconfig",
"FirstLine": 1,
"LineCount": 100
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t\n 3:\tmenu \"Live Update and Kexec HandOver\"\n 4:\t\n 5:\tconfig KEXEC_HANDOVER\n 6:\t\tbool \"kexec handover\"\n 7:\t\tdepends on ARCH_SUPPORTS_KEXEC_HANDOVER \u0026\u0026 ARCH_SUPPORTS_KEXEC_FILE\n 8:\t\tselect MEMBLOCK_KHO_SCRATCH\n 9:\t\tselect KEXEC_FILE\n 10:\t\tselect LIBFDT\n 11:\t\tselect CMA\n 12:\t\thelp\n 13:\t\t Allow kexec to hand over state across kernels by generating and\n 14:\t\t passing additional metadata to the target kernel. This is useful\n 15:\t\t to keep data or state alive across the kexec. For this to work,\n 16:\t\t both source and target kernels need to have this option enabled.\n 17:\t\n 18:\tconfig KEXEC_HANDOVER_DEBUG\n 19:\t\tbool \"Enable Kexec Handover debug checks\"\n 20:\t\tdepends on KEXEC_HANDOVER\n 21:\t\thelp\n 22:\t\t This option enables extra sanity checks for the Kexec Handover\n 23:\t\t subsystem. Since, KHO performance is crucial in live update\n 24:\t\t scenarios and the extra code might be adding overhead it is\n 25:\t\t only optionally enabled.\n 26:\t\n 27:\tconfig KEXEC_HANDOVER_DEBUGFS\n 28:\t\tbool \"kexec handover debugfs interface\"\n 29:\t\tdefault KEXEC_HANDOVER\n 30:\t\tdepends on KEXEC_HANDOVER\n 31:\t\tselect DEBUG_FS\n 32:\t\thelp\n 33:\t\t Allow to control kexec handover device tree via debugfs\n 34:\t\t interface, i.e. finalize the state or aborting the finalization.\n 35:\t\t Also, enables inspecting the KHO fdt trees with the debugfs binary\n 36:\t\t blobs.\n 37:\t\n 38:\tconfig KEXEC_HANDOVER_ENABLE_DEFAULT\n 39:\t\tbool \"Enable kexec handover by default\"\n 40:\t\tdepends on KEXEC_HANDOVER\n 41:\t\thelp\n 42:\t\t Enable Kexec Handover by default. This avoids the need to\n 43:\t\t explicitly pass 'kho=on' on the kernel command line.\n 44:\t\n 45:\t\t This is useful for systems where KHO is a prerequisite for other\n 46:\t\t features, such as Live Update, ensuring the mechanism is always\n 47:\t\t active.\n 48:\t\n 49:\t\t The default behavior can still be overridden at boot time by\n 50:\t\t passing 'kho=off'.\n 51:\t\n 52:\tconfig LIVEUPDATE\n 53:\t\tbool \"Live Update Orchestrator\"\n 54:\t\tdepends on KEXEC_HANDOVER\n 55:\t\thelp\n 56:\t\t Enable the Live Update Orchestrator. Live Update is a mechanism,\n 57:\t\t typically based on kexec, that allows the kernel to be updated\n 58:\t\t while keeping selected devices operational across the transition.\n 59:\t\t These devices are intended to be reclaimed by the new kernel and\n 60:\t\t re-attached to their original workload without requiring a device\n 61:\t\t reset.\n 62:\t\n 63:\t\t Ability to handover a device from current to the next kernel depends\n 64:\t\t on specific support within device drivers and related kernel\n 65:\t\t subsystems.\n 66:\t\n 67:\t\t This feature primarily targets virtual machine hosts to quickly update\n 68:\t\t the kernel hypervisor with minimal disruption to the running virtual\n 69:\t\t machines.\n 70:\t\n 71:\t\t If unsure, say N.\n 72:\t\n 73:\tconfig LIVEUPDATE_MEMFD\n 74:\t\tbool \"Live update support for memfd\"\n 75:\t\tdepends on LIVEUPDATE\n 76:\t\tdepends on MEMFD_CREATE\n 77:\t\tdepends on SHMEM\n 78:\t\tdefault LIVEUPDATE\n 79:\t\thelp\n 80:\t\t Enable live update support for memfd regions. This allows preserving\n 81:\t\t memfd-backed memory across kernel live updates.\n 82:\t\n 83:\t\t This can be used to back VM memory with memfds, allowing the guest\n 84:\t\t memory to persist, or for other user workloads needing to preserve\n 85:\t\t pages.\n 86:\t\n 87:\t\t If unsure, say N.\n 88:\t\n 89:\tendmenu\n"
} |
| 7/2 | 2026/10/15 11:55 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25292 output: 44 thoughts: 38 Thoughts: Okay, let's dive into this. Here's how I'd approach understanding the user-space exposure of the liveupdate device: **Investigating Liveupdate Device Exposure** Right, so I need to figure out how the `liveupdate` device, whatever it may be, actually interacts with user-space applications. My instinct is to start digging around for the device node itself. To do that, I'll need to check how it's exposed to user space. My first thought is to use `grep`. I'll look for keywords, the most obvious being `LIVEUPDATE_DEV`, or any variations on "liveupdate" that might be used, either as a simple string or, if it's a character or misc device, a matching device name like `/dev/liveupdate`. This will help me locate where the device entry is located. It may be a `/dev/` entry, or perhaps it lives somewhere else in the filesystem. Using `grep` will find any code or configuration file that directly references the device. I need to make sure to search the entire relevant codebase. |
| 8/2 | 2026/10/15 11:55 | tool | grepper |
0mArgs:{
"Expression": "LIVEUPDATE_DEV|misc_register.*liveupdate",
"PathPrefixes": [
"kernel/liveupdate",
"drivers",
"tools"
]
}Results: {
"Output": "tools/testing/selftests/liveupdate/liveupdate.c-33-\ntools/testing/selftests/liveupdate/liveupdate.c:34:#define LIVEUPDATE_DEV \"/dev/liveupdate\"\ntools/testing/selftests/liveupdate/liveupdate.c-35-\n--\ntools/testing/selftests/liveupdate/liveupdate.c=61=TEST_F(liveupdate_device, basic_open_close)\ntools/testing/selftests/liveupdate/liveupdate.c-62-{\ntools/testing/selftests/liveupdate/liveupdate.c:63:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-64-\ntools/testing/selftests/liveupdate/liveupdate.c-65-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:66:\t\tSKIP(return, \"%s does not exist.\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-67-\n--\ntools/testing/selftests/liveupdate/liveupdate.c=80=TEST_F(liveupdate_device, exclusive_open)\ntools/testing/selftests/liveupdate/liveupdate.c-81-{\ntools/testing/selftests/liveupdate/liveupdate.c:82:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-83-\ntools/testing/selftests/liveupdate/liveupdate.c-84-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:85:\t\tSKIP(return, \"%s does not exist.\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-86-\ntools/testing/selftests/liveupdate/liveupdate.c-87-\tASSERT_GE(self-\u003efd1, 0);\ntools/testing/selftests/liveupdate/liveupdate.c:88:\tself-\u003efd2 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-89-\tEXPECT_LT(self-\u003efd2, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=99=TEST_F(liveupdate_device, create_duplicate_session)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-102-\ntools/testing/selftests/liveupdate/liveupdate.c:103:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-104-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:105:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-106-\n--\ntools/testing/selftests/liveupdate/liveupdate.c=124=TEST_F(liveupdate_device, create_distinct_sessions)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-127-\ntools/testing/selftests/liveupdate/liveupdate.c:128:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-129-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:130:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-131-\n--\ntools/testing/selftests/liveupdate/liveupdate.c=150=TEST_F(liveupdate_device, preserve_memfd)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-155-\ntools/testing/selftests/liveupdate/liveupdate.c:156:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-157-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:158:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-159-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=184=TEST_F(liveupdate_device, preserve_multiple_memfds)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-190-\ntools/testing/selftests/liveupdate/liveupdate.c:191:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-192-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:193:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-194-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=231=TEST_F(liveupdate_device, preserve_complex_scenario)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-238-\ntools/testing/selftests/liveupdate/liveupdate.c:239:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-240-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:241:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-242-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=299=TEST_F(liveupdate_device, preserve_unsupported_fd)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-303-\ntools/testing/selftests/liveupdate/liveupdate.c:304:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-305-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:306:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-307-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=329=TEST_F(liveupdate_device, prevent_double_preservation)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-333-\ntools/testing/selftests/liveupdate/liveupdate.c:334:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-335-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:336:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-337-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=369=TEST_F(liveupdate_device, create_session_no_null_termination)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-372-\ntools/testing/selftests/liveupdate/liveupdate.c:373:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-374-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:375:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-376-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=392=TEST_F(liveupdate_device, create_session_empty_name)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-395-\ntools/testing/selftests/liveupdate/liveupdate.c:396:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-397-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:398:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-399-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=411=TEST_F(liveupdate_device, get_session_name)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-416-\ntools/testing/selftests/liveupdate/liveupdate.c:417:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-418-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:419:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-420-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=437=TEST_F(liveupdate_device, get_session_name_max_length)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-445-\ntools/testing/selftests/liveupdate/liveupdate.c:446:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-447-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:448:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-449-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=468=TEST_F(liveupdate_device, preserve_many_sessions)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-473-\ntools/testing/selftests/liveupdate/liveupdate.c:474:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-475-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:476:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-477-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=503=TEST_F(liveupdate_device, preserve_many_files)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-508-\ntools/testing/selftests/liveupdate/liveupdate.c:509:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-510-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:511:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-512-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=542=TEST_F(liveupdate_device, session_freeze)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-545-\ntools/testing/selftests/liveupdate/liveupdate.c:546:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-547-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:548:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-549-\tASSERT_GE(self-\u003efd1, 0);\n--\ntools/testing/selftests/liveupdate/liveupdate.c=581=TEST_F(liveupdate_device, preserve_memfd_with_arg)\n--\ntools/testing/selftests/liveupdate/liveupdate.c-585-\ntools/testing/selftests/liveupdate/liveupdate.c:586:\tself-\u003efd1 = open(LIVEUPDATE_DEV, O_RDWR);\ntools/testing/selftests/liveupdate/liveupdate.c-587-\tif (self-\u003efd1 \u003c 0 \u0026\u0026 errno == ENOENT)\ntools/testing/selftests/liveupdate/liveupdate.c:588:\t\tSKIP(return, \"%s does not exist\", LIVEUPDATE_DEV);\ntools/testing/selftests/liveupdate/liveupdate.c-589-\tASSERT_GE(self-\u003efd1, 0);\n"
} |
| 9/2 | 2026/10/15 11:55 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29309 output: 34 thoughts: 25 Thoughts: Here's my thought process, as if I were considering this myself: **Investigating the Creation Point of `/dev/liveupdate`** Okay, so I need to track down the creation point for `/dev/liveupdate`. This sounds like a kernel-level thing, likely related to live kernel updates. My first instinct is to dig into the kernel source, specifically the `kernel/liveupdate` directory, as that seems the most logical place to start. A quick `grep` within that directory should quickly reveal any code responsible for creating that specific device node. That's usually the fastest way to get to the root of a device driver's initialization. Let's see what that uncovers. |
| 10/2 | 2026/10/15 11:55 | tool | grepper |
0mArgs:{
"Expression": "misc_register|miscdevice|LIVEUPDATE",
"PathPrefixes": [
"kernel/liveupdate"
]
}Results: {
"Output": "kernel/liveupdate/Kconfig=38=config KEXEC_HANDOVER_ENABLE_DEFAULT\n--\nkernel/liveupdate/Kconfig-51-\nkernel/liveupdate/Kconfig:52:config LIVEUPDATE\nkernel/liveupdate/Kconfig-53-\tbool \"Live Update Orchestrator\"\n--\nkernel/liveupdate/Kconfig-72-\nkernel/liveupdate/Kconfig:73:config LIVEUPDATE_MEMFD\nkernel/liveupdate/Kconfig-74-\tbool \"Live update support for memfd\"\nkernel/liveupdate/Kconfig:75:\tdepends on LIVEUPDATE\nkernel/liveupdate/Kconfig-76-\tdepends on MEMFD_CREATE\nkernel/liveupdate/Kconfig-77-\tdepends on SHMEM\nkernel/liveupdate/Kconfig:78:\tdefault LIVEUPDATE\nkernel/liveupdate/Kconfig-79-\thelp\n--\nkernel/liveupdate/Makefile=11=obj-$(CONFIG_KEXEC_HANDOVER_DEBUGFS)\t+= kexec_handover_debugfs.o\nkernel/liveupdate/Makefile-12-\nkernel/liveupdate/Makefile:13:obj-$(CONFIG_LIVEUPDATE)\t\t+= luo.o\n--\nkernel/liveupdate/luo_core.c-57-#include \u003clinux/liveupdate.h\u003e\nkernel/liveupdate/luo_core.c:58:#include \u003clinux/miscdevice.h\u003e\nkernel/liveupdate/luo_core.c-59-#include \u003clinux/mm.h\u003e\n--\nkernel/liveupdate/luo_core.c=265=struct luo_device_state {\nkernel/liveupdate/luo_core.c:266:\tstruct miscdevice miscdev;\nkernel/liveupdate/luo_core.c-267-\tatomic_t in_use;\n--\nkernel/liveupdate/luo_core.c=363=struct luo_ioctl_op {\n--\nkernel/liveupdate/luo_core.c-370-#define IOCTL_OP(_ioctl, _fn, _struct, _last) \\\nkernel/liveupdate/luo_core.c:371:\t[_IOC_NR(_ioctl) - LIVEUPDATE_CMD_BASE] = { \\\nkernel/liveupdate/luo_core.c-372-\t\t.size = sizeof(_struct) + \\\n--\nkernel/liveupdate/luo_core.c=380=static const struct luo_ioctl_op luo_ioctl_ops[] = {\nkernel/liveupdate/luo_core.c:381:\tIOCTL_OP(LIVEUPDATE_IOCTL_CREATE_SESSION, luo_ioctl_create_session,\nkernel/liveupdate/luo_core.c-382-\t\t struct liveupdate_ioctl_create_session, name),\nkernel/liveupdate/luo_core.c:383:\tIOCTL_OP(LIVEUPDATE_IOCTL_RETRIEVE_SESSION, luo_ioctl_retrieve_session,\nkernel/liveupdate/luo_core.c-384-\t\t struct liveupdate_ioctl_retrieve_session, name),\n--\nkernel/liveupdate/luo_core.c=387=static long luo_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)\n--\nkernel/liveupdate/luo_core.c-395-\tnr = _IOC_NR(cmd);\nkernel/liveupdate/luo_core.c:396:\tif (nr - LIVEUPDATE_CMD_BASE \u003e= ARRAY_SIZE(luo_ioctl_ops))\nkernel/liveupdate/luo_core.c-397-\t\treturn -EINVAL;\n--\nkernel/liveupdate/luo_core.c-403-\nkernel/liveupdate/luo_core.c:404:\top = \u0026luo_ioctl_ops[nr - LIVEUPDATE_CMD_BASE];\nkernel/liveupdate/luo_core.c-405-\tif (op-\u003eioctl_num != cmd)\n--\nkernel/liveupdate/luo_core.c=435=static int __init liveupdate_ioctl_init(void)\n--\nkernel/liveupdate/luo_core.c-439-\nkernel/liveupdate/luo_core.c:440:\treturn misc_register(\u0026luo_dev.miscdev);\nkernel/liveupdate/luo_core.c-441-}\n--\nkernel/liveupdate/luo_file.c-34- * - freeze(): Prepares the final state for kexec. Invoked either early via\nkernel/liveupdate/luo_file.c:35: * the LIVEUPDATE_SESSION_FREEZE ioctl once userspace is done modifying\nkernel/liveupdate/luo_file.c-36- * the session's files, or during the reboot() syscall.\n--\nkernel/liveupdate/luo_file.c-50- *\nkernel/liveupdate/luo_file.c:51: * 2. Freeze (Pre-Reboot): Either explicitly via LIVEUPDATE_SESSION_FREEZE or\nkernel/liveupdate/luo_file.c-52- * just before the kexec during reboot(), luo_file_freeze() is called.\n--\nkernel/liveupdate/luo_file.c=484=static void __luo_file_unfreeze(struct luo_file_set *file_set,\n--\nkernel/liveupdate/luo_file.c-505- * This function is called from the reboot() syscall path or from\nkernel/liveupdate/luo_file.c:506: * LIVEUPDATE_SESSION_FREEZE. Its purpose is to perform the preparation and\nkernel/liveupdate/luo_file.c-507- * serialization of all preserved files in the file_set.\n--\nkernel/liveupdate/luo_file.c-529- *\nkernel/liveupdate/luo_file.c:530: * Context: Called from the liveupdate_reboot() path or LIVEUPDATE_SESSION_FREEZE.\nkernel/liveupdate/luo_file.c-531- * Return: 0 on success, or a negative errno on failure.\n--\nkernel/liveupdate/luo_internal.h=72=struct luo_session {\nkernel/liveupdate/luo_internal.h:73:\tchar name[LIVEUPDATE_SESSION_NAME_LENGTH];\nkernel/liveupdate/luo_internal.h-74-\tstruct list_head list;\n--\nkernel/liveupdate/luo_internal.h=111=void luo_flb_serialize(void);\nkernel/liveupdate/luo_internal.h-112-\nkernel/liveupdate/luo_internal.h:113:#ifdef CONFIG_LIVEUPDATE_TEST\nkernel/liveupdate/luo_internal.h-114-void liveupdate_test_register(struct liveupdate_file_handler *fh);\n--\nkernel/liveupdate/luo_session.c-37- * 2. Freeze / Serialization: Sessions may be frozen early from userspace\nkernel/liveupdate/luo_session.c:38: * via `LIVEUPDATE_SESSION_FREEZE`. When the `reboot(LINUX_REBOOT_CMD_KEXEC)`\nkernel/liveupdate/luo_session.c-39- * syscall is made, `luo_session_serialize()` is called to freeze any\n--\nkernel/liveupdate/luo_session.c=399=struct luo_ioctl_op {\n--\nkernel/liveupdate/luo_session.c-407-#define IOCTL_OP(_ioctl, _fn, _struct, _last, _type) \\\nkernel/liveupdate/luo_session.c:408:\t[_IOC_NR(_ioctl) - LIVEUPDATE_CMD_SESSION_BASE] = { \\\nkernel/liveupdate/luo_session.c-409-\t\t.size = sizeof(_struct) + \\\n--\nkernel/liveupdate/luo_session.c=418=static const struct luo_ioctl_op luo_session_ioctl_ops[] = {\nkernel/liveupdate/luo_session.c:419:\tIOCTL_OP(LIVEUPDATE_SESSION_FINISH, luo_session_finish,\nkernel/liveupdate/luo_session.c-420-\t\t struct liveupdate_session_finish, reserved, LUO_IOCTL_INCOMING),\nkernel/liveupdate/luo_session.c:421:\tIOCTL_OP(LIVEUPDATE_SESSION_PRESERVE_FD, luo_session_preserve_fd,\nkernel/liveupdate/luo_session.c-422-\t\t struct liveupdate_session_preserve_fd, token, LUO_IOCTL_OUTGOING),\nkernel/liveupdate/luo_session.c:423:\tIOCTL_OP(LIVEUPDATE_SESSION_RETRIEVE_FD, luo_session_retrieve_fd,\nkernel/liveupdate/luo_session.c-424-\t\t struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),\nkernel/liveupdate/luo_session.c:425:\tIOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,\nkernel/liveupdate/luo_session.c-426-\t\t struct liveupdate_session_get_name, name, LUO_IOCTL_ALL),\nkernel/liveupdate/luo_session.c:427:\tIOCTL_OP(LIVEUPDATE_SESSION_FREEZE, luo_session_freeze,\nkernel/liveupdate/luo_session.c-428-\t\t struct liveupdate_session_freeze, reserved, LUO_IOCTL_OUTGOING),\n--\nkernel/liveupdate/luo_session.c=448=static long luo_session_ioctl(struct file *filep, unsigned int cmd,\n--\nkernel/liveupdate/luo_session.c-458-\tnr = _IOC_NR(cmd);\nkernel/liveupdate/luo_session.c:459:\tif (nr \u003c LIVEUPDATE_CMD_SESSION_BASE || (nr - LIVEUPDATE_CMD_SESSION_BASE) \u003e=\nkernel/liveupdate/luo_session.c-460-\t ARRAY_SIZE(luo_session_ioctl_ops)) {\n--\nkernel/liveupdate/luo_session.c-468-\nkernel/liveupdate/luo_session.c:469:\top = \u0026luo_session_ioctl_ops[nr - LIVEUPDATE_CMD_SESSION_BASE];\nkernel/liveupdate/luo_session.c-470-\tif (op-\u003eioctl_num != cmd)\n--\nkernel/liveupdate/luo_session.c=510=int luo_session_create(const char *name, struct file **filep)\nkernel/liveupdate/luo_session.c-511-{\nkernel/liveupdate/luo_session.c:512:\tsize_t len = strnlen(name, LIVEUPDATE_SESSION_NAME_LENGTH);\nkernel/liveupdate/luo_session.c-513-\tstruct luo_session *session;\n--\nkernel/liveupdate/luo_session.c-515-\nkernel/liveupdate/luo_session.c:516:\tif (len == 0 || len \u003e LIVEUPDATE_SESSION_NAME_LENGTH - 1)\nkernel/liveupdate/luo_session.c-517-\t\treturn -EINVAL;\n"
} |
| 11/2 | 2026/10/15 11:55 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32312 output: 24 thoughts: 474 Thoughts: **Diving into the Live Update Implementation** Alright, let's dissect this live update mechanism. Seems we have a misc device, `/dev/liveupdate`, registered through `misc_register`. Userspace interacts with it, and it's all handled via ioctls, standard stuff. We've got `LIVEUPDATE_IOCTL_CREATE_SESSION` which is interesting, creating a session file descriptor. Then we have a series of ioctls on that session fd: `FINISH`, `PRESERVE_FD`, `RETRIEVE_FD`, `GET_NAME`, and a new one, `FREEZE`, which I'll have to investigate further. The `PRESERVE_FD` and `RETRIEVE_FD` ioctls have been updated to support passing arguments through their associated structs which gives it additional flexibility. I see it's also been extended in `mm/memfd_luo.c` to handle the preservation and retrieval of generic tmpfs files (via `struct liveupdate_memfd_retrieve_arg`) on top of anonymous memfds. Smart, using tmpfs for that, keeps it contained and easy to manage. Now, the real question – can this run in a standard QEMU environment? No exotic hardware dependency? Thankfully, it looks like `/dev/liveupdate` is a virtual misc device that comes to life when `CONFIG_LIVEUPDATE` is enabled, which is a good sign. But before I get ahead of myself, let's verify what depends on what here. Quick Kconfig check... and here we are: `CONFIG_LIVEUPDATE` depends on `KEXEC_HANDOVER`. Let's dig deeper into that. `KEXEC_HANDOVER` in `kernel/liveupdate/Kconfig` depends on `ARCH_SUPPORTS_KEXEC_HANDOVER`, `ARCH_SUPPORTS_KEXEC_FILE` and selects a few options like `MEMBLOCK_KHO_SCRATCH`, `KEXEC_FILE`, `LIBFDT` and `CMA`. Right, that's expected. Gotta make sure the architecture is supported and this is not a niche feature. On to check for `ARCH_SUPPORTS_KEXEC_HANDOVER` for x86 / amd64. |
| 12/2 | 2026/10/15 11:55 | tool | grepper |
0mArgs:{
"Expression": "ARCH_SUPPORTS_KEXEC_HANDOVER"
}Results: {
"Output": "arch/arm64/Kconfig=1708=config ARCH_DEFAULT_KEXEC_IMAGE_VERIFY_SIG\n--\narch/arm64/Kconfig-1710-\narch/arm64/Kconfig:1711:config ARCH_SUPPORTS_KEXEC_HANDOVER\narch/arm64/Kconfig-1712-\tdef_bool y\n--\narch/x86/Kconfig=1978=config ARCH_SUPPORTS_KEXEC_JUMP\n--\narch/x86/Kconfig-1980-\narch/x86/Kconfig:1981:config ARCH_SUPPORTS_KEXEC_HANDOVER\narch/x86/Kconfig-1982-\tdef_bool X86_64\n--\nkernel/liveupdate/Kconfig=5=config KEXEC_HANDOVER\nkernel/liveupdate/Kconfig-6-\tbool \"kexec handover\"\nkernel/liveupdate/Kconfig:7:\tdepends on ARCH_SUPPORTS_KEXEC_HANDOVER \u0026\u0026 ARCH_SUPPORTS_KEXEC_FILE\nkernel/liveupdate/Kconfig-8-\tselect MEMBLOCK_KHO_SCRATCH\n"
} |
| 13/2 | 2026/10/15 11:55 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33581 output: 27 thoughts: 113 Thoughts: **Kernel Live Update Thoughts** Okay, so I see that amd64 (x86_64) has `ARCH_SUPPORTS_KEXEC_HANDOVER def_bool X86_64` which is excellent! It also confirms `KEXEC_FILE` is pretty standard on this architecture. The dependency chain continues, because `LIVEUPDATE` depends on `KEXEC_HANDOVER`. Further, it looks like `LIVEUPDATE_MEMFD` has a dependency on `LIVEUPDATE`, and also `MEMFD_CREATE` and `SHMEM`, as expected. Now, where do I find the build process for `memfd_luo.c`? I need to check either the `mm/Makefile` or wherever that file is getting compiled to see how it's being handled. That will give a better picture of the entire process. |
| 14/2 | 2026/10/15 11:55 | tool | grepper |
0mArgs:{
"Expression": "memfd_luo",
"PathPrefixes": [
"mm"
]
}Results: {
"Output": "mm/Makefile=102=obj-$(CONFIG_PAGE_COUNTER) += page_counter.o\nmm/Makefile:103:obj-$(CONFIG_LIVEUPDATE_MEMFD) += memfd_luo.o\nmm/Makefile-104-obj-$(CONFIG_MEMCG_V1) += memcontrol-v1.o\n--\nmm/memfd_luo.c-88-\nmm/memfd_luo.c:89:static int memfd_luo_preserve_folios(struct file *file,\nmm/memfd_luo.c-90-\t\t\t\t struct kho_vmalloc *kho_vmalloc,\nmm/memfd_luo.c:91:\t\t\t\t struct memfd_luo_folio_ser **out_folios_ser,\nmm/memfd_luo.c-92-\t\t\t\t u64 *nr_foliosp)\n--\nmm/memfd_luo.c-94-\tstruct inode *inode = file_inode(file);\nmm/memfd_luo.c:95:\tstruct memfd_luo_folio_ser *folios_ser;\nmm/memfd_luo.c-96-\tunsigned int max_folios;\n--\nmm/memfd_luo.c-150-\tfor (i = 0; i \u003c nr_folios; i++) {\nmm/memfd_luo.c:151:\t\tstruct memfd_luo_folio_ser *pfolio = \u0026folios_ser[i];\nmm/memfd_luo.c-152-\t\tstruct folio *folio = folios[i];\n--\nmm/memfd_luo.c-232-\nmm/memfd_luo.c:233:static void memfd_luo_unpreserve_folios(struct kho_vmalloc *kho_vmalloc,\nmm/memfd_luo.c:234:\t\t\t\t\tstruct memfd_luo_folio_ser *folios_ser,\nmm/memfd_luo.c-235-\t\t\t\t\tu64 nr_folios)\n--\nmm/memfd_luo.c-244-\tfor (i = 0; i \u003c nr_folios; i++) {\nmm/memfd_luo.c:245:\t\tconst struct memfd_luo_folio_ser *pfolio = \u0026folios_ser[i];\nmm/memfd_luo.c-246-\t\tstruct folio *folio;\n--\nmm/memfd_luo.c-259-\nmm/memfd_luo.c:260:static int memfd_luo_preserve(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-261-{\nmm/memfd_luo.c-262-\tstruct inode *inode = file_inode(args-\u003efile);\nmm/memfd_luo.c:263:\tstruct memfd_luo_folio_ser *folios_ser;\nmm/memfd_luo.c:264:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-265-\tu64 nr_folios, inode_size;\n--\nmm/memfd_luo.c-306-\nmm/memfd_luo.c:307:\terr = memfd_luo_preserve_folios(args-\u003efile, \u0026ser-\u003efolios,\nmm/memfd_luo.c-308-\t\t\t\t\t\u0026folios_ser, \u0026nr_folios);\n--\nmm/memfd_luo.c-327-\nmm/memfd_luo.c:328:static int memfd_luo_freeze(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-329-{\nmm/memfd_luo.c:330:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-331-\n--\nmm/memfd_luo.c-345-\nmm/memfd_luo.c:346:static void memfd_luo_unpreserve(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-347-{\nmm/memfd_luo.c-348-\tstruct inode *inode = file_inode(args-\u003efile);\nmm/memfd_luo.c:349:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-350-\n--\nmm/memfd_luo.c-358-\nmm/memfd_luo.c:359:\tmemfd_luo_unpreserve_folios(\u0026ser-\u003efolios, args-\u003eprivate_data,\nmm/memfd_luo.c-360-\t\t\t\t ser-\u003enr_folios);\n--\nmm/memfd_luo.c-365-\nmm/memfd_luo.c:366:static void memfd_luo_discard_folios(const struct memfd_luo_folio_ser *folios_ser,\nmm/memfd_luo.c-367-\t\t\t\t u64 nr_folios)\n--\nmm/memfd_luo.c-371-\tfor (i = 0; i \u003c nr_folios; i++) {\nmm/memfd_luo.c:372:\t\tconst struct memfd_luo_folio_ser *pfolio = \u0026folios_ser[i];\nmm/memfd_luo.c-373-\t\tstruct folio *folio;\n--\nmm/memfd_luo.c-390-\nmm/memfd_luo.c:391:static void memfd_luo_finish(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-392-{\nmm/memfd_luo.c:393:\tstruct memfd_luo_folio_ser *folios_ser;\nmm/memfd_luo.c:394:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-395-\n--\nmm/memfd_luo.c-412-\nmm/memfd_luo.c:413:\t\tmemfd_luo_discard_folios(folios_ser, ser-\u003enr_folios);\nmm/memfd_luo.c-414-\t\tvfree(folios_ser);\n--\nmm/memfd_luo.c-420-\nmm/memfd_luo.c:421:static int memfd_luo_retrieve_folios(struct file *file,\nmm/memfd_luo.c:422:\t\t\t\t struct memfd_luo_folio_ser *folios_ser,\nmm/memfd_luo.c-423-\t\t\t\t u64 nr_folios)\n--\nmm/memfd_luo.c-432-\tfor (i = 0; i \u003c nr_folios; i++) {\nmm/memfd_luo.c:433:\t\tconst struct memfd_luo_folio_ser *pfolio = \u0026folios_ser[i];\nmm/memfd_luo.c-434-\t\tphys_addr_t phys;\n--\nmm/memfd_luo.c-504-\tfor (long j = i + 1; j \u003c nr_folios; j++) {\nmm/memfd_luo.c:505:\t\tconst struct memfd_luo_folio_ser *pfolio = \u0026folios_ser[j];\nmm/memfd_luo.c-506-\t\tphys_addr_t phys;\n--\nmm/memfd_luo.c-521-\nmm/memfd_luo.c:522:static struct file *memfd_luo_get_tmpfs_file(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-523-{\n--\nmm/memfd_luo.c-570-\nmm/memfd_luo.c:571:static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-572-{\nmm/memfd_luo.c:573:\tstruct memfd_luo_folio_ser *folios_ser;\nmm/memfd_luo.c:574:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-575-\tstruct inode *inode;\n--\nmm/memfd_luo.c-590-\tif (ser-\u003eflags \u0026 MEMFD_LUO_FLAG_TMPFS) {\nmm/memfd_luo.c:591:\t\tfile = memfd_luo_get_tmpfs_file(args);\nmm/memfd_luo.c-592-\t\tif (IS_ERR(file)) {\n--\nmm/memfd_luo.c-630-\nmm/memfd_luo.c:631:\t\terr = memfd_luo_retrieve_folios(file, folios_ser, ser-\u003enr_folios);\nmm/memfd_luo.c-632-\t\tvfree(folios_ser);\n--\nmm/memfd_luo.c-658-\nmm/memfd_luo.c:659:static bool memfd_luo_can_preserve(struct liveupdate_file_handler *handler,\nmm/memfd_luo.c-660-\t\t\t\t struct file *file)\n--\nmm/memfd_luo.c-664-\nmm/memfd_luo.c:665:static unsigned long memfd_luo_get_id(struct file *file)\nmm/memfd_luo.c-666-{\n--\nmm/memfd_luo.c-669-\nmm/memfd_luo.c:670:static const struct liveupdate_file_ops memfd_luo_file_ops = {\nmm/memfd_luo.c:671:\t.freeze = memfd_luo_freeze,\nmm/memfd_luo.c:672:\t.finish = memfd_luo_finish,\nmm/memfd_luo.c:673:\t.retrieve = memfd_luo_retrieve,\nmm/memfd_luo.c:674:\t.preserve = memfd_luo_preserve,\nmm/memfd_luo.c:675:\t.unpreserve = memfd_luo_unpreserve,\nmm/memfd_luo.c:676:\t.can_preserve = memfd_luo_can_preserve,\nmm/memfd_luo.c:677:\t.get_id = memfd_luo_get_id,\nmm/memfd_luo.c-678-\t.rarg = LIVEUPDATE_ARG(struct liveupdate_memfd_retrieve_arg, fd),\n--\nmm/memfd_luo.c-681-\nmm/memfd_luo.c:682:static struct liveupdate_file_handler memfd_luo_handler = {\nmm/memfd_luo.c:683:\t.ops = \u0026memfd_luo_file_ops,\nmm/memfd_luo.c-684-\t.compatible = MEMFD_LUO_FH_COMPATIBLE,\n--\nmm/memfd_luo.c-686-\nmm/memfd_luo.c:687:static int __init memfd_luo_init(void)\nmm/memfd_luo.c-688-{\nmm/memfd_luo.c:689:\tint err = liveupdate_register_file_handler(\u0026memfd_luo_handler);\nmm/memfd_luo.c-690-\n--\nmm/memfd_luo.c-699-}\nmm/memfd_luo.c:700:late_initcall(memfd_luo_init);\n"
} |
| 15/2 | 2026/10/15 11:55 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36886 output: 40 thoughts: 795 Thoughts: **Analyzing the Live Update Code** Okay, let's break this down systematically. I need to understand this new live update functionality, and more importantly, its attack surface. First, I'm going to look at reachability. The code modifications are spread across several files: `include/linux/kho/abi/memfd.h`, `include/linux/liveupdate.h`, `include/uapi/linux/liveupdate.h`, `kernel/liveupdate/luo_file.c`, `kernel/liveupdate/luo_internal.h`, `kernel/liveupdate/luo_session.c`, and `mm/memfd_luo.c`. This is quite a spread, indicating a non-trivial change. Essentially, there's a new `LIVEUPDATE_SESSION_FREEZE` ioctl handled by `luo_session_freeze()` in `kernel/liveupdate/luo_session.c`. It looks like a userpace process opens `/dev/liveupdate`, creates a session, gets a session file descriptor, and then can trigger `luo_session_freeze()` via that ioctl. Inside that function, `luo_file_freeze()` is called, which then invokes the freeze callbacks of the relevant handlers. For instance, `memfd_luo_freeze`. Now, the user-supplied arguments are handled via `luo_copy_user_arg()` inside `luo_preserve_file` and `luo_retrieve_file`. This is an obvious area for potential vulnerabilities, especially when copying data from user space. The code checks size, uses `copy_struct_from_user()`, etc. but this is still a classic attack vector. Specifically in `mm/memfd_luo.c`: - `memfd_luo_can_preserve` now allows linked tmpfs files to be preserved, this is a change from before, which should be understood. - In `memfd_luo_preserve`, it sets `MEMFD_LUO_FLAG_TMPFS` if `inode->i_nlink` which indicates a linked tmpfs file. - In `memfd_luo_retrieve`, it retrieves the tmpfs file via `memfd_luo_get_tmpfs_file(args)`. The code is doing a series of checks on the file descriptor including `FMODE_WRITE`, `shmem_file`, `inode->i_nlink`, `i_size_read(inode) != 0`, `!mapping_empty(inode->i_mapping)`, and `liveupdate_claim_file`. - Also handling retryable retrieve errors. - Then `liveupdate_claim_file` and `liveupdate_unclaim_file` are used in `kernel/liveupdate/luo_file.c` using `luo_preserved_files` xarray. Given all this, is it reachable and executable in a standard QEMU environment? Yes, from any user process with the right privileges, or even syzkaller. The ability to preserve and retrieve memfds or tmpfs files, freeze the session, etc. is within reach. However, I need to understand the implications better. Can a userpace process, in fact, retrieve files without requiring a full kexec? I'm going to dig deeper into the session handling code, especially `kernel/liveupdate/luo_session.c`, to clarify the workflow of incoming sessions and the retrieve operation. |
| 16/2 | 2026/10/15 11:55 | tool | grepper |
0mArgs:{
"Expression": "LUO_IOCTL_INCOMING|luo_session_retrieve",
"PathPrefixes": [
"kernel/liveupdate"
]
}Results: {
"Output": "kernel/liveupdate/luo_core.c=300=static int luo_ioctl_retrieve_session(struct luo_ucmd *ucmd)\n--\nkernel/liveupdate/luo_core.c-309-\nkernel/liveupdate/luo_core.c:310:\terr = luo_session_retrieve(argp-\u003ename, \u0026file);\nkernel/liveupdate/luo_core.c-311-\tif (err \u003c 0)\n--\nkernel/liveupdate/luo_internal.h=83=int luo_session_create(const char *name, struct file **filep);\nkernel/liveupdate/luo_internal.h:84:int luo_session_retrieve(const char *name, struct file **filep);\nkernel/liveupdate/luo_internal.h-85-void __init luo_session_setup_outgoing(u64 *sessions_pa);\n--\nkernel/liveupdate/luo_session.c-47- * 4. Retrieval: A userspace agent in the new kernel can then call\nkernel/liveupdate/luo_session.c:48: * `luo_session_retrieve()` with a session name to get a new file\nkernel/liveupdate/luo_session.c-49- * descriptor and access the preserved state.\n--\nkernel/liveupdate/luo_session.c-61- * - Readers: Taken by any path modifying or accessing session state (e.g.,\nkernel/liveupdate/luo_session.c:62: * `luo_session_create()`, `luo_session_retrieve()`, `luo_session_release()`,\nkernel/liveupdate/luo_session.c-63- * and `luo_session_ioctl()`).\n--\nkernel/liveupdate/luo_session.c=277=static int luo_session_preserve_fd(struct luo_session *session,\n--\nkernel/liveupdate/luo_session.c-298-\nkernel/liveupdate/luo_session.c:299:static int luo_session_retrieve_fd(struct luo_session *session,\nkernel/liveupdate/luo_session.c-300-\t\t\t\t struct luo_ucmd *ucmd)\n--\nkernel/liveupdate/luo_session.c=393=enum luo_ioctl_type {\nkernel/liveupdate/luo_session.c:394:\tLUO_IOCTL_INCOMING,\nkernel/liveupdate/luo_session.c-395-\tLUO_IOCTL_OUTGOING,\n--\nkernel/liveupdate/luo_session.c=418=static const struct luo_ioctl_op luo_session_ioctl_ops[] = {\nkernel/liveupdate/luo_session.c-419-\tIOCTL_OP(LIVEUPDATE_SESSION_FINISH, luo_session_finish,\nkernel/liveupdate/luo_session.c:420:\t\t struct liveupdate_session_finish, reserved, LUO_IOCTL_INCOMING),\nkernel/liveupdate/luo_session.c-421-\tIOCTL_OP(LIVEUPDATE_SESSION_PRESERVE_FD, luo_session_preserve_fd,\nkernel/liveupdate/luo_session.c-422-\t\t struct liveupdate_session_preserve_fd, token, LUO_IOCTL_OUTGOING),\nkernel/liveupdate/luo_session.c:423:\tIOCTL_OP(LIVEUPDATE_SESSION_RETRIEVE_FD, luo_session_retrieve_fd,\nkernel/liveupdate/luo_session.c:424:\t\t struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),\nkernel/liveupdate/luo_session.c-425-\tIOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,\n--\nkernel/liveupdate/luo_session.c=431=static bool luo_ioctl_type_valid(struct luo_session *session,\n--\nkernel/liveupdate/luo_session.c-434-\tswitch (op-\u003etype) {\nkernel/liveupdate/luo_session.c:435:\tcase LUO_IOCTL_INCOMING:\nkernel/liveupdate/luo_session.c-436-\t\t/* Retrieved is only set on incoming sessions */\n--\nkernel/liveupdate/luo_session.c=510=int luo_session_create(const char *name, struct file **filep)\n--\nkernel/liveupdate/luo_session.c-545-\nkernel/liveupdate/luo_session.c:546:int luo_session_retrieve(const char *name, struct file **filep)\nkernel/liveupdate/luo_session.c-547-{\n"
} |
| 17/2 | 2026/10/15 11:55 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39661 output: 32 thoughts: 1374 Thoughts: **My Assessment: Live Update Logic – Definitely Worth Fuzzing!** Okay, so here's the breakdown of what I'm seeing. We have Live Update sessions coming in, either from a kexec/KHO handover or deserialized. Outgoing sessions are created via `LIVEUPDATE_IOCTL_CREATE_SESSION`, which is key. The interactions I'm observing revolve around file preservation, freezing, and retrieval within these sessions. I am seeing that: When preserving files (`LIVEUPDATE_SESSION_PRESERVE_FD`), it calls `luo_session_preserve_fd`, which eventually calls `luo_preserve_file`. The important detail is the call to `luo_copy_user_arg`, copying a user-provided argument and passing it into `fh->ops->preserve(&args)` -> `memfd_luo_preserve()`. If the file is a tmpfs file (based on `inode->i_nlink`), we set a `MEMFD_LUO_FLAG_TMPFS` flag. Freezing sessions (`LIVEUPDATE_SESSION_FREEZE`) calls `luo_session_freeze`. Here, there are reserved checks, `session->frozen` checks, and eventually `luo_file_freeze` is called. The `luo_file_freeze` call iterates through the files in `file_set` and calls the `freeze` function on each, ultimately calling `memfd_luo_freeze()`. Sessions can also be released, which involves unfreezing, and unpreserving files via `luo_file_unfreeze` and `luo_file_unpreserve_files` respectively. Furthermore, we can retrieve files. `luo_retrieve_file` and `memfd_luo_retrieve` can be called if KHO is set up or incoming sessions exist. And I can tell even without a fully deserialized session, fuzzing tools like syzkaller could be able to call ioctls and test error paths. The interesting part is the potential for vulnerabilities when we examine the code related to retrieval and preservation. In `luo_retrieve_file`, a check is done with `liveupdate_claim_file` which is called with a `WARN_ON`. Additionally, `memfd_luo_get_tmpfs_file` uses `fget` to retrieve a file by its file descriptor, and `luo_session_freeze` has an interesting logic gate around the `session->frozen` flag. Also `luo_copy_user_arg` copies in user-provided args, which may be a source of attack. Analyzing this closely reveals some important things. This entire process delves deep into core kernel functionalities: * **Misc device ioctl handlers:** We are dealing with `LIVEUPDATE_IOCTL_CREATE_SESSION`, `LIVEUPDATE_SESSION_PRESERVE_FD` and `LIVEUPDATE_SESSION_FREEZE`, these are all ioctl's. * **Memory Management:** The tmpfs interactions and `copy_struct_from_user` calls within `luo_copy_user_arg` are crucial. * **VFS operations:** We're dealing with files, file descriptors, and locking, which is classic VFS territory. * **Locking and State Management:** The checks on `session->frozen` and the use of the `session->mutex` are important to security. * **XArray Operations**: Operations on the xarray data structure. The modifications are in these key files: `kernel/liveupdate/luo_file.c`, `kernel/liveupdate/luo_session.c`, and `mm/memfd_luo.c`. This is all core enough that it falls squarely under: * Core Subsystems: Memory management (`mm/`), VFS, ioctl handling. * Reachable Drivers and Interfaces: The misc device `/dev/liveupdate`. * New/Modified Logic, State Management, and Assertions: Particularly the `WARN_ON` within `liveupdate_claim_file`. The fact that we are touching core kernel subsystems, potentially user-controlled data and complex state makes this a prime target for fuzzing. `WorthFuzzing = true` is a definite go! Now, let me check the relevant Kconfig options and Makefiles to see what's needed to build and enable this code path. |
| 18/2 | 2026/10/15 11:56 | tool | read-file |
0mArgs:{
"File": "kernel/liveupdate/Makefile",
"FirstLine": 1,
"LineCount": 20
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0\n 2:\t\n 3:\tluo-y :=\t\t\t\t\t\t\t\t\\\n 4:\t\t\tkho_block.o\t\t\t\t\t\t\\\n 5:\t\t\tluo_core.o\t\t\t\t\t\t\\\n 6:\t\t\tluo_file.o\t\t\t\t\t\t\\\n 7:\t\t\tluo_flb.o\t\t\t\t\t\t\\\n 8:\t\t\tluo_session.o\n 9:\t\n 10:\tobj-$(CONFIG_KEXEC_HANDOVER)\t\t+= kexec_handover.o\n 11:\tobj-$(CONFIG_KEXEC_HANDOVER_DEBUGFS)\t+= kexec_handover_debugfs.o\n 12:\t\n 13:\tobj-$(CONFIG_LIVEUPDATE)\t\t+= luo.o\n"
} |
| 19/2 | 2026/10/15 11:56 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42208 output: 19 thoughts: 235 Thoughts: **Investigating the `memfd_luo.o` Build Dependency** Okay, so I'm looking at how `memfd_luo.o` is being included in the build. The `mm/Makefile` entry on line 103, specifically `obj-$(CONFIG_LIVEUPDATE_MEMFD) += memfd_luo.o`, tells me that its inclusion is conditional on the `CONFIG_LIVEUPDATE_MEMFD` setting. Right, standard practice. Now, I need to understand the dependencies of `CONFIG_LIVEUPDATE_MEMFD`, and for that, I'm heading to `kernel/liveupdate/Kconfig`. Let's see... Ah, there it is. `CONFIG_LIVEUPDATE_MEMFD` depends on `LIVEUPDATE`, `MEMFD_CREATE`, and `SHMEM`, and defaults to `LIVEUPDATE`. Makes sense; `LIVEUPDATE` forms the core, with `MEMFD_CREATE` and `SHMEM` providing specific functionalities. And `LIVEUPDATE` depends on `KEXEC_HANDOVER`, that then has its own set of dependencies. Next step: I need to dig deeper into the definitions of `MEMFD_CREATE` and `SHMEM`. They are quite fundamental and I'd expect their definitions to be in either `init/Kconfig` or `mm/Kconfig`. I'll go check those next to clarify the full context. |
| 20/2 | 2026/10/15 11:56 | tool | grepper |
0mArgs:{
"Expression": "config MEMFD_CREATE"
}Results: {
"Output": "mm/Kconfig=1338=config KMAP_LOCAL_NON_LINEAR_PTE_ARRAY\n--\nmm/Kconfig-1340-\nmm/Kconfig:1341:config MEMFD_CREATE\nmm/Kconfig-1342-\tbool \"Enable memfd_create() system call\" if EXPERT\n"
} |
| 21/2 | 2026/10/15 11:56 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42855 output: 247 thoughts: 1878 Thoughts: **Live Update Configuration and Fuzzing Strategy** Okay, so the live update functionality is the focus here. First, let's nail down the critical kernel configurations. `CONFIG_LIVEUPDATE` and `CONFIG_LIVEUPDATE_MEMFD` are the main ones, but we also need `CONFIG_KEXEC_HANDOVER`. Digging a bit deeper, `KEXEC_HANDOVER` depends on `ARCH_SUPPORTS_KEXEC_HANDOVER` and `ARCH_SUPPORTS_KEXEC_FILE`. Those look good for amd64. `KEXEC_HANDOVER` also pulls in a few other options, and `LIVEUPDATE_MEMFD` needs a few more. So, to be clear, the configs to enable are `KEXEC_HANDOVER`, `LIVEUPDATE`, `LIVEUPDATE_MEMFD`, `MEMFD_CREATE`, and `SHMEM`. `SHMEM` is usually a default yes, but it’s always smart to double-check. Now, on to the fuzzing specifics. We need to define `FocusSymbols` carefully. The guidelines say to avoid ubiquitous lifecycle functions and instead target feature-specific logic. Let's look at the added and modified functions. In `kernel/liveupdate/luo_session.c`, we've got `luo_session_freeze`, `luo_session_freeze_one`, `luo_session_unfreeze_one`, `luo_session_preserve_fd`, `luo_session_retrieve_fd` and `luo_session_release`. `kernel/liveupdate/luo_file.c` shows `liveupdate_claim_file`, `liveupdate_unclaim_file`, `luo_copy_user_arg`, `luo_preserve_file`, `luo_file_freeze`, `luo_file_unfreeze`, and `luo_retrieve_file`. And in `mm/memfd_luo.c`, there are `memfd_luo_get_tmpfs_file`, `memfd_luo_retrieve`, `memfd_luo_preserve`, and `memfd_luo_can_preserve`. We need to make sure these are actually symbols and not inlined. `liveupdate_claim_file` and `liveupdate_unclaim_file` are exported. The `luo_` prefixed functions in `luo_*.c` seem to be global, and `memfd_luo_*` ones are in their respective file. `luo_session_freeze` is a static function, but it's called through `luo_session_ioctl_ops`. After reviewing the code definitions, let's select the symbols most relevant to fuzzing: `luo_session_freeze`, `luo_preserve_file`, `luo_retrieve_file`, `liveupdate_claim_file`, `liveupdate_unclaim_file`, `memfd_luo_get_tmpfs_file`, `memfd_luo_preserve`, and `memfd_luo_retrieve`. These all target specific live update logic, argument handling, session freezing, and tmpfs file interactions. With this analysis, we can now define `set-results`. `WorthFuzzing`: true `Reasoning`: Reachable IOCTLs on `/dev/liveupdate`, user argument validation, tmpfs file preservation and retrieval, session freeze, and newly introduced claims/invariants all warrant fuzzing. `EnableConfigs`: `["KEXEC_HANDOVER", "LIVEUPDATE", "LIVEUPDATE_MEMFD", "MEMFD_CREATE", "SHMEM"]` `FocusSymbols`: ``` - `luo_session_freeze` - `luo_preserve_file` - `luo_retrieve_file` - `liveupdate_claim_file` - `liveupdate_unclaim_file` - `memfd_luo_get_tmpfs_file` - `memfd_luo_preserve` - `memfd_luo_retrieve` ``` Now, it's time to call `set-results`. |
| 22/2 | 2026/10/15 11:56 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"KEXEC_HANDOVER",
"LIVEUPDATE",
"LIVEUPDATE_MEMFD",
"MEMFD_CREATE",
"SHMEM"
],
"FocusSymbols": [
"luo_session_freeze",
"luo_preserve_file",
"luo_retrieve_file",
"liveupdate_claim_file",
"liveupdate_unclaim_file",
"memfd_luo_get_tmpfs_file",
"memfd_luo_preserve",
"memfd_luo_retrieve"
],
"Reasoning": "The patch introduces the LIVEUPDATE_SESSION_FREEZE ioctl command, support for user-supplied arguments during file preservation and retrieval in the Live Update Orchestrator (LUO), and extends memfd preservation to arbitrary tmpfs files. These paths are exposed to userspace via /dev/liveupdate and session file descriptors, modifying core state management, file descriptor validation, and tmpfs folio handling. Fuzzing is warranted to test early freeze state transitions, user argument parsing, and tmpfs retrieval error recovery.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"KEXEC_HANDOVER",
"LIVEUPDATE",
"LIVEUPDATE_MEMFD",
"MEMFD_CREATE",
"SHMEM"
],
"FocusSymbols": [
"luo_session_freeze",
"luo_preserve_file",
"luo_retrieve_file",
"liveupdate_claim_file",
"liveupdate_unclaim_file",
"memfd_luo_get_tmpfs_file",
"memfd_luo_preserve",
"memfd_luo_retrieve"
],
"Reasoning": "The patch introduces the LIVEUPDATE_SESSION_FREEZE ioctl command, support for user-supplied arguments during file preservation and retrieval in the Live Update Orchestrator (LUO), and extends memfd preservation to arbitrary tmpfs files. These paths are exposed to userspace via /dev/liveupdate and session file descriptors, modifying core state management, file descriptor validation, and tmpfs folio handling. Fuzzing is warranted to test early freeze state transitions, user argument parsing, and tmpfs retrieval error recovery.",
"WorthFuzzing": true
} |
| 23/1 | 2026/10/15 11:56 | action | If |
4mArgs:{
"WorthFuzzing": true
}Results: null |
| 24/2 | 2026/10/15 11:56 | agent | kmsan-evaluator |
4mModel:core Args: null Results: {
"KMSANReasoning": "The patch series extends the Live Update Orchestrator (LUO) and memfd/tmpfs preservation mechanism by adding early session freeze support, a user argument passing mechanism for file handlers (with support for preserving/restoring generic linked tmpfs files), and retryable retrieve error handling.\n\nAn evaluation of memory initialization and leak risks shows:\n1. Kernel-to-user copies: The ioctl handlers (LIVEUPDATE_SESSION_PRESERVE_FD, LIVEUPDATE_SESSION_RETRIEVE_FD, LIVEUPDATE_SESSION_FREEZE) use copy_struct_from_user() into the stack buffer and luo_ucmd_respond() to copy back data. The relevant structures (struct liveupdate_session_preserve_fd, struct liveupdate_session_retrieve_fd, struct liveupdate_session_freeze) have naturally aligned 32-bit and 64-bit members with zero padding holes. copy_struct_from_user() explicitly zero-fills any trailing bytes when user-space provides a smaller structure.\n2. Handler arguments: In luo_copy_user_arg(), the kernel buffer is populated via copy_struct_from_user(), ensuring all bytes up to spec-\u003esize are initialized before being passed into handler callbacks.\n3. Heap/KHO allocations: luo_session is allocated with kzalloc_obj(), and the preserved serialization structure struct memfd_luo_ser is allocated using kho_alloc_preserve() which uses __GFP_ZERO. All local liveupdate_file_op_args instances are zero-initialized with '= {0}'.\n4. Folio operations: The restored tmpfs folio handling relies on page cache and KHO folio handover, operating on existing folios without introducing uninitialized reads or uninitialized page exposures.\n\nThe potential issues introduced by this patch involve concurrency, locking order (inode_lock vs session mutex), reference counting (fget/fput, get_file), and resource tracking (xarray insert/erase, unclaim cleanup on failure). These failure modes fall squarely into the domains of KASAN (use-after-free, memory corruption) and LOCKDEP (locking bugs, deadlocks), and do not present uninitialized memory risks. Therefore, a dedicated KMSAN session is not justified.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 73221d66de0cb87d5537af6ff35cba50bed7c783
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Oct 15 11:54:43 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/kho/abi/memfd.h b/include/linux/kho/abi/memfd.h
index 08b10fea2afc8..47ff5ab967501 100644
--- a/include/linux/kho/abi/memfd.h
+++ b/include/linux/kho/abi/memfd.h
@@ -68,7 +68,18 @@ struct memfd_luo_folio_ser {
F_SEAL_EXEC)
/**
- * struct memfd_luo_ser - Main serialization structure for a memfd.
+ * MEMFD_LUO_FLAG_TMPFS - The preserved file is a tmpfs file.
+ *
+ * Indicates the file was preserved from a linked tmpfs file rather than an
+ * anonymous memfd, and must be retrieved to an empty tmpfs file.
+ */
+#define MEMFD_LUO_FLAG_TMPFS BIT(0)
+
+/* The set of flags this version supports preserving. */
+#define MEMFD_LUO_ALL_FLAGS MEMFD_LUO_FLAG_TMPFS
+
+/**
+ * struct memfd_luo_ser - Main serialization structure for a memfd or tmpfs file.
* @pos: The file's current position (f_pos).
* @size: The total size of the file in bytes (i_size).
* @seals: The seals present on the memfd. The seals are uABI so it is safe
diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h
index 63ea5417de849..4e1f0f4cbd6fb 100644
--- a/include/linux/liveupdate.h
+++ b/include/linux/liveupdate.h
@@ -22,14 +22,48 @@ struct liveupdate_flb;
struct liveupdate_session;
struct file;
+/**
+ * struct liveupdate_arg_spec - Specification of a file handler user argument.
+ * @size: Full size of the argument structure in the current kernel.
+ * @min_size: Minimum valid user-supplied size (offsetofend of the last
+ * required field).
+ */
+struct liveupdate_arg_spec {
+ size_t size;
+ size_t min_size;
+};
+
+/**
+ * LIVEUPDATE_ARG - Validated specification of a file handler argument struct.
+ * @_struct: The argument structure type.
+ * @_min_last: The last required member in @_struct.
+ *
+ * All file handler argument structures passed via
+ * &liveupdate_session_preserve_fd.arg or &liveupdate_session_retrieve_fd.arg
+ * must begin with a 32-bit @size field so they can be extended compatibly.
+ * Use this macro to initialize &liveupdate_file_ops.parg and
+ * &liveupdate_file_ops.rarg.
+ */
+#define LIVEUPDATE_ARG(_struct, _min_last) \
+ { \
+ .size = sizeof(_struct) + \
+ BUILD_BUG_ON_ZERO(offsetof(_struct, size) != 0) + \
+ BUILD_BUG_ON_ZERO(sizeof_field(_struct, size) != sizeof(u32)), \
+ .min_size = offsetofend(_struct, _min_last), \
+ }
+
/**
* struct liveupdate_file_op_args - Arguments for file operation callbacks.
* @handler: The file handler being called.
* @retrieve_status: The retrieve status for the 'can_finish / finish'
* operation. A value of 0 means the retrieve has not been
- * attempted, a positive value means the retrieve was
- * successful, and a negative value means the retrieve failed,
- * and the value is the error code of the call.
+ * attempted (or only failed with a retryable error), a
+ * positive value means the retrieve was successful, and a
+ * negative value means the retrieve permanently failed, and
+ * the value is the error code of the call.
+ * @retryable: For .retrieve(): [OUT] Set to true by the callback on
+ * error when the preserved state has not been consumed and
+ * retrieval may be retried.
* @file: The file object. For retrieve: [OUT] The callback sets
* this to the new file. For other ops: [IN] The caller sets
* this to the file being operated on.
@@ -39,6 +73,11 @@ struct file;
* is not preserved. Set by the handler's .preserve()
* callback, and must be freed in the handler's
* .unpreserve() callback.
+ * @arg: Kernel copy of the user-provided argument for .preserve()
+ * and .retrieve(), or %NULL if none was provided. Allocated
+ * to the handler's expected argument size with any trailing
+ * bytes beyond the user-supplied size zero-filled. Valid
+ * only for the duration of the callback.
*
* This structure bundles all parameters for the file operation callbacks.
* The 'data' and 'file' fields are used for both input and output.
@@ -46,9 +85,11 @@ struct file;
struct liveupdate_file_op_args {
struct liveupdate_file_handler *handler;
int retrieve_status;
+ bool retryable;
struct file *file;
u64 serialized_data;
void *private_data;
+ const void *arg;
};
/**
@@ -57,7 +98,8 @@ struct liveupdate_file_op_args {
* compatible with the given file.
* @preserve: Required. Performs state-saving for the file.
* @unpreserve: Required. Cleans up any resources allocated by @preserve.
- * @freeze: Optional. Final actions just before kernel transition.
+ * @freeze: Optional. Prepares final state before kexec (via
+ * LIVEUPDATE_SESSION_FREEZE or during reboot).
* @unfreeze: Optional. Undo freeze operations.
* @retrieve: Required. Restores the file in the new kernel.
* @can_finish: Optional. Check if this FD can finish, i.e. all restoration
@@ -66,6 +108,12 @@ struct liveupdate_file_op_args {
* resources in the session.
* @finish: Required. Final cleanup in the new kernel.
* @get_id: Optional. Returns a unique identifier for the file.
+ * @parg: Optional. Specification of the user argument structure
+ * accepted by @preserve, initialized via LIVEUPDATE_ARG(). If
+ * unset, non-zero user arguments are rejected with -EOPNOTSUPP.
+ * @rarg: Optional. Specification of the user argument structure
+ * accepted by @retrieve, initialized via LIVEUPDATE_ARG(). If
+ * unset, non-zero user arguments are rejected with -EOPNOTSUPP.
* @owner: Module reference
*
* All operations (except can_preserve) receive a pointer to a
@@ -82,6 +130,8 @@ struct liveupdate_file_ops {
bool (*can_finish)(struct liveupdate_file_op_args *args);
void (*finish)(struct liveupdate_file_op_args *args);
unsigned long (*get_id)(struct file *file);
+ struct liveupdate_arg_spec parg;
+ struct liveupdate_arg_spec rarg;
struct module *owner;
};
@@ -236,6 +286,11 @@ int liveupdate_reboot(void);
int liveupdate_register_file_handler(struct liveupdate_file_handler *fh);
void liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh);
+int liveupdate_claim_file(struct liveupdate_file_handler *fh,
+ struct file *file);
+void liveupdate_unclaim_file(struct liveupdate_file_handler *fh,
+ struct file *file);
+
int liveupdate_register_flb(struct liveupdate_file_handler *fh,
struct liveupdate_flb *flb);
void liveupdate_unregister_flb(struct liveupdate_file_handler *fh,
@@ -268,6 +323,17 @@ static inline void liveupdate_unregister_file_handler(struct liveupdate_file_han
{
}
+static inline int liveupdate_claim_file(struct liveupdate_file_handler *fh,
+ struct file *file)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline void liveupdate_unclaim_file(struct liveupdate_file_handler *fh,
+ struct file *file)
+{
+}
+
static inline int liveupdate_register_flb(struct liveupdate_file_handler *fh,
struct liveupdate_flb *flb)
{
diff --git a/include/uapi/linux/liveupdate.h b/include/uapi/linux/liveupdate.h
index 4043d40387125..24e938d91392c 100644
--- a/include/uapi/linux/liveupdate.h
+++ b/include/uapi/linux/liveupdate.h
@@ -60,6 +60,7 @@ enum {
LIVEUPDATE_CMD_SESSION_RETRIEVE_FD = 0x41,
LIVEUPDATE_CMD_SESSION_FINISH = 0x42,
LIVEUPDATE_CMD_SESSION_GET_NAME = 0x43,
+ LIVEUPDATE_CMD_SESSION_FREEZE = 0x44,
};
/**
@@ -126,6 +127,8 @@ struct liveupdate_ioctl_retrieve_session {
* @size: Input; sizeof(struct liveupdate_session_preserve_fd)
* @fd: Input; The user-space file descriptor to be preserved.
* @token: Input; An opaque, unique token for preserved resource.
+ * @arg: Input; User-space pointer to a file-handler-specific argument
+ * structure starting with a 32-bit size field, or 0 if unused.
*
* Holds parameters for preserving a file descriptor.
*
@@ -149,6 +152,7 @@ struct liveupdate_session_preserve_fd {
__u32 size;
__s32 fd;
__aligned_u64 token;
+ __aligned_u64 arg;
};
#define LIVEUPDATE_SESSION_PRESERVE_FD \
@@ -160,6 +164,8 @@ struct liveupdate_session_preserve_fd {
* @fd: Output; The new file descriptor representing the fully restored
* kernel resource.
* @token: Input; An opaque, token that was used to preserve the resource.
+ * @arg: Input; User-space pointer to a file-handler-specific argument
+ * structure starting with a 32-bit size field, or 0 if unused.
*
* Retrieve a previously preserved file descriptor.
*
@@ -169,9 +175,10 @@ struct liveupdate_session_preserve_fd {
* associated with the token and populates the @fd field with a new file
* descriptor referencing the restored resource in the current (new) kernel.
* This operation must be performed *before* signaling completion via
- * %LIVEUPDATE_IOCTL_FINISH. If a retrieve of a token fails, subsequent
- * attempts to retrieve the token fail with the same error code. Failed
- * retrieves are not retried.
+ * %LIVEUPDATE_IOCTL_FINISH. If a retrieve of a token fails after consuming
+ * preserved state, subsequent attempts to retrieve the token fail with the
+ * same error code. Early argument or target validation errors before
+ * preserved state is consumed leave the token intact and may be retried.
*
* Return: 0 on success, negative error code on failure (e.g., invalid token).
*/
@@ -179,6 +186,7 @@ struct liveupdate_session_retrieve_fd {
__u32 size;
__s32 fd;
__aligned_u64 token;
+ __aligned_u64 arg;
};
#define LIVEUPDATE_SESSION_RETRIEVE_FD \
@@ -236,4 +244,49 @@ struct liveupdate_session_get_name {
#define LIVEUPDATE_SESSION_GET_NAME \
_IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_GET_NAME)
+/**
+ * struct liveupdate_session_freeze - ioctl(LIVEUPDATE_SESSION_FREEZE)
+ * @size: Input; sizeof(struct liveupdate_session_freeze)
+ * @reserved: Input; Must be zero. Reserved for future use.
+ *
+ * Freezes the session early from userspace before the reboot kexec phase.
+ *
+ * When this ioctl is called, the kernel executes the .freeze() callback on all
+ * preserved files in the session and serializes their metadata. Once frozen,
+ * no further files can be preserved in the session.
+ *
+ * During the subsequent reboot kexec, this session is recognized as already
+ * frozen and is skipped from the late auto freeze.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+struct liveupdate_session_freeze {
+ __u32 size;
+ __u32 reserved;
+};
+
+#define LIVEUPDATE_SESSION_FREEZE \
+ _IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_FREEZE)
+
+/**
+ * struct liveupdate_memfd_retrieve_arg - Argument for tmpfs file retrieval
+ * @size: Input; sizeof(struct liveupdate_memfd_retrieve_arg)
+ * @fd: Input; Writable, empty, linked tmpfs file descriptor to restore into.
+ *
+ * Passed via &struct liveupdate_session_retrieve_fd.arg on
+ * %LIVEUPDATE_SESSION_RETRIEVE_FD. This argument is required when retrieving
+ * a preserved linked tmpfs file and is rejected with -EINVAL when retrieving
+ * an anonymous memfd.
+ *
+ * @fd must refer to a writable, empty, linked tmpfs file that is not already
+ * claimed by LUO. On success, the file is populated with the preserved folios,
+ * its size and f_pos are restored, and the file descriptor returned in
+ * &struct liveupdate_session_retrieve_fd.fd references the same underlying open
+ * file description as @fd.
+ */
+struct liveupdate_memfd_retrieve_arg {
+ __u32 size;
+ __s32 fd;
+};
+
#endif /* _UAPI_LIVEUPDATE_H */
diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c
index c39f96961a85b..5c2ffec696885 100644
--- a/kernel/liveupdate/luo_file.c
+++ b/kernel/liveupdate/luo_file.c
@@ -31,9 +31,9 @@
* - unpreserve(): Cleans up any resources allocated by .preserve(), called
* if the preservation process is aborted before the reboot (i.e. session is
* closed).
- * - freeze(): A final pre-reboot opportunity to prepare the state for kexec.
- * We are already in reboot syscall, and therefore userspace cannot mutate
- * the file anymore.
+ * - freeze(): Prepares the final state for kexec. Invoked either early via
+ * the LIVEUPDATE_SESSION_FREEZE ioctl once userspace is done modifying
+ * the session's files, or during the reboot() syscall.
* - unfreeze(): Undoes the actions of .freeze(), called if the live update
* is aborted after the freeze phase.
* - retrieve(): Reconstructs the file in the new kernel from the preserved
@@ -48,7 +48,8 @@
* handler, calls its .preserve() operation, and creates an internal &struct
* luo_file to track the live state.
*
- * 2. Freeze (Pre-Reboot): Just before the kexec, luo_file_freeze() is called.
+ * 2. Freeze (Pre-Reboot): Either explicitly via LIVEUPDATE_SESSION_FREEZE or
+ * just before the kexec during reboot(), luo_file_freeze() is called.
* It iterates through all preserved files, calls their respective .freeze()
* operation, and serializes their final metadata (compatible string, token,
* and data handle) into a contiguous memory block for KHO.
@@ -111,6 +112,7 @@
#include <linux/xarray.h>
#include <linux/slab.h>
#include <linux/string.h>
+#include <linux/uaccess.h>
#include "luo_internal.h"
static LIST_HEAD(luo_file_handler_list);
@@ -136,9 +138,10 @@ static DEFINE_XARRAY(luo_preserved_files);
* @retrieve_status: Status code indicating whether a user/kernel in the new kernel has
* successfully called retrieve() on this file. This prevents
* multiple retrieval attempts. A value of 0 means a retrieve()
- * has not been attempted, a positive value means the retrieve()
- * was successful, and a negative value means the retrieve()
- * failed, and the value is the error code of the call.
+ * has not been attempted (or only failed with a retryable
+ * error), a positive value means the retrieve() was successful,
+ * and a negative value means the retrieve() permanently failed,
+ * and the value is the error code of the call.
* @mutex: A mutex that protects the fields of this specific instance
* (e.g., @retrieved, @file), ensuring that operations like
* retrieving or finishing a file are atomic.
@@ -175,6 +178,36 @@ static unsigned long luo_get_id(struct liveupdate_file_handler *fh,
return fh->ops->get_id ? fh->ops->get_id(file) : (unsigned long)file;
}
+/**
+ * liveupdate_claim_file - Claim a file in the LUO preserved files table.
+ * @fh: The file handler claiming @file.
+ * @file: The file to claim.
+ *
+ * File handlers whose .retrieve() callback restores state into an existing
+ * user-supplied &struct file (rather than allocating a new one) should call
+ * this before modifying @file to ensure @file is not already managed by LUO.
+ *
+ * Return: 0 on success, -EBUSY if @file is already managed by LUO, or a
+ * negative errno on allocation failure.
+ */
+int liveupdate_claim_file(struct liveupdate_file_handler *fh,
+ struct file *file)
+{
+ return xa_insert(&luo_preserved_files, luo_get_id(fh, file),
+ file, GFP_KERNEL);
+}
+
+/**
+ * liveupdate_unclaim_file - Release a claimed file from the LUO preserved files table.
+ * @fh: The file handler that claimed @file.
+ * @file: The file to release.
+ */
+void liveupdate_unclaim_file(struct liveupdate_file_handler *fh,
+ struct file *file)
+{
+ xa_erase(&luo_preserved_files, luo_get_id(fh, file));
+}
+
static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
{
struct luo_file *iter;
@@ -187,11 +220,45 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
return false;
}
+static int luo_copy_user_arg(u64 user_arg, const void **argp,
+ const struct liveupdate_arg_spec *spec)
+{
+ void *karg __free(kfree) = NULL;
+ void __user *uptr;
+ u32 user_size;
+ int err;
+
+ if (!user_arg)
+ return 0;
+ if (!spec->size)
+ return -EOPNOTSUPP;
+
+ uptr = u64_to_user_ptr(user_arg);
+ if (get_user(user_size, (u32 __user *)uptr))
+ return -EFAULT;
+ if (user_size < spec->min_size)
+ return -EINVAL;
+ if (user_size > PAGE_SIZE)
+ return -E2BIG;
+
+ karg = kmalloc(spec->size, GFP_KERNEL);
+ if (!karg)
+ return -ENOMEM;
+
+ err = copy_struct_from_user(karg, spec->size, uptr, user_size);
+ if (err)
+ return err;
+
+ *argp = no_free_ptr(karg);
+ return 0;
+}
+
/**
* luo_preserve_file - Initiate the preservation of a file descriptor.
* @file_set: The file_set to which the preserved file will be added.
* @token: A unique, user-provided identifier for the file.
* @fd: The file descriptor to be preserved.
+ * @arg: User-space pointer to the handler argument structure, or 0.
*
* This function orchestrates the first phase of preserving a file. Upon entry,
* it takes a reference to the 'struct file' via fget(), effectively making LUO
@@ -207,9 +274,11 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
* (allocates if needed).
* 3. Iterates through registered handlers, calling can_preserve() to find one
* compatible with the given @fd.
- * 4. Calls the handler's .preserve() operation, which saves the file's state
+ * 4. Copies the user argument structure (if @arg is non-zero) according to the
+ * handler's parg specification.
+ * 5. Calls the handler's .preserve() operation, which saves the file's state
* and returns an opaque private data handle.
- * 5. Adds the new instance to the file_set's internal list.
+ * 6. Adds the new instance to the file_set's internal list.
*
* On success, LUO takes a reference to the 'struct file' and considers it
* under its management until it is unpreserved or finished.
@@ -224,10 +293,12 @@ static bool luo_token_is_used(struct luo_file_set *file_set, u64 token)
* -EBADF if the file descriptor is invalid.
* -ENOSPC if the file_set is full.
* -ENOENT if no compatible handler is found.
+ * -EOPNOTSUPP if @arg is non-zero and the handler does not accept an arg.
* -ENOMEM on memory allocation failure.
* Other erros might be returned by .preserve().
*/
-int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
+int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd,
+ u64 arg)
{
struct liveupdate_file_op_args args = {0};
struct liveupdate_file_handler *fh;
@@ -263,10 +334,14 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
if (err)
goto err_fput;
+ err = luo_copy_user_arg(arg, &args.arg, &fh->ops->parg);
+ if (err)
+ goto err_module_put;
+
err = xa_insert(&luo_preserved_files, luo_get_id(fh, file),
file, GFP_KERNEL);
if (err)
- goto err_module_put;
+ goto err_free_arg;
err = luo_flb_file_preserve(fh);
if (err)
@@ -289,6 +364,7 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
if (err)
goto err_kfree;
+ kfree(args.arg);
luo_file->serialized_data = args.serialized_data;
luo_file->private_data = args.private_data;
list_add_tail(&luo_file->list, &file_set->files_list);
@@ -302,6 +378,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd)
luo_flb_file_unpreserve(fh);
err_erase_xa:
xa_erase(&luo_preserved_files, luo_get_id(fh, file));
+err_free_arg:
+ kfree(args.arg);
err_module_put:
module_put(fh->ops->owner);
err_fput:
@@ -422,11 +500,11 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
/**
* luo_file_freeze - Freezes all preserved files and serializes their metadata.
* @file_set: The file_set whose files are to be frozen.
- * @file_set_ser: Where to put the serialized file_set.
+ * @file_set_ser: Where to put the serialized file_set, or %NULL if freezing early.
*
- * This function is called from the reboot() syscall path, just before the
- * kernel transitions to the new image via kexec. Its purpose is to perform the
- * final preparation and serialization of all preserved files in the file_set.
+ * This function is called from the reboot() syscall path or from
+ * LIVEUPDATE_SESSION_FREEZE. Its purpose is to perform the preparation and
+ * serialization of all preserved files in the file_set.
*
* It iterates through each preserved file in FIFO order (the order of
* preservation) and performs two main actions:
@@ -449,7 +527,7 @@ static void __luo_file_unfreeze(struct luo_file_set *file_set,
* running state. The function then returns an error, causing the reboot()
* syscall to fail.
*
- * Context: Called only from the liveupdate_reboot() path.
+ * Context: Called from the liveupdate_reboot() path or LIVEUPDATE_SESSION_FREEZE.
* Return: 0 on success, or a negative errno on failure.
*/
int luo_file_freeze(struct luo_file_set *file_set,
@@ -487,8 +565,10 @@ int luo_file_freeze(struct luo_file_set *file_set,
file_ser->token = luo_file->token;
}
- file_set_ser->count = file_set->count;
- file_set_ser->files = kho_block_set_head_pa(&file_set->block_set);
+ if (file_set_ser) {
+ file_set_ser->count = file_set->count;
+ file_set_ser->files = kho_block_set_head_pa(&file_set->block_set);
+ }
return 0;
@@ -501,7 +581,7 @@ int luo_file_freeze(struct luo_file_set *file_set,
/**
* luo_file_unfreeze - Unfreezes all files in a file_set and clear serialization
* @file_set: The file_set whose files are to be unfrozen.
- * @file_set_ser: Serialized file_set.
+ * @file_set_ser: Serialized file_set, or %NULL if not serialized yet.
*
* This function rolls back the state of all files in a file_set after the
* freeze phase has begun but must be aborted. It is the counterpart to
@@ -512,7 +592,8 @@ int luo_file_freeze(struct luo_file_set *file_set,
* their respective .unfreeze() handler callbacks.
*
* Context: This is called when the live update is aborted during
- * the reboot() syscall, after luo_file_freeze() has been called.
+ * the reboot() syscall, after luo_file_freeze() has been called,
+ * or when an early-frozen session is released before kexec.
*/
void luo_file_unfreeze(struct luo_file_set *file_set,
struct luo_file_set_ser *file_set_ser)
@@ -521,13 +602,15 @@ void luo_file_unfreeze(struct luo_file_set *file_set,
return;
__luo_file_unfreeze(file_set, NULL);
- memset(file_set_ser, 0, sizeof(*file_set_ser));
+ if (file_set_ser)
+ memset(file_set_ser, 0, sizeof(*file_set_ser));
}
/**
* luo_retrieve_file - Restores a preserved file from a file_set by its token.
* @file_set: The file_set from which to retrieve the file.
* @token: The unique token identifying the file to be restored.
+ * @arg: User-space pointer to the handler argument structure, or 0.
* @filep: Output parameter; on success, this is populated with a pointer
* to the newly retrieved 'struct file'.
*
@@ -538,7 +621,9 @@ void luo_file_unfreeze(struct luo_file_set *file_set,
* The operation is idempotent: if a file has already been successfully
* retrieved, this function will simply return a pointer to the existing
* 'struct file' and report success without re-executing the retrieve
- * operation. This is handled by checking the 'retrieved' flag under a lock.
+ * operation. If a previous retrieve failed permanently, it returns that
+ * saved error code; if a previous retrieve failed with a retryable error
+ * before consuming preserved state, the retrieve operation is re-attempted.
*
* File retrieval can happen in any order; it is not bound by the order of
* preservation.
@@ -547,9 +632,10 @@ void luo_file_unfreeze(struct luo_file_set *file_set,
* kernel.
* Return: 0 on success. Returns a negative errno on failure:
* -ENOENT if no file with the matching token is found.
+ * -EOPNOTSUPP if @arg is non-zero and the handler does not accept an arg.
* Any error code returned by the handler's .retrieve() op.
*/
-int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
+int luo_retrieve_file(struct luo_file_set *file_set, u64 token, u64 arg,
struct file **filep)
{
struct liveupdate_file_op_args args = {0};
@@ -586,12 +672,22 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
return 0;
}
+ err = luo_copy_user_arg(arg, &args.arg, &luo_file->fh->ops->rarg);
+ if (err)
+ return err;
+
args.handler = luo_file->fh;
args.serialized_data = luo_file->serialized_data;
err = luo_file->fh->ops->retrieve(&args);
+ kfree(args.arg);
if (err) {
- /* Keep the error code for later use. */
- luo_file->retrieve_status = err;
+ /*
+ * Keep the error code for later use unless the handler marked
+ * the failure as retryable (e.g. invalid user argument before
+ * preserved state was consumed).
+ */
+ if (!args.retryable)
+ luo_file->retrieve_status = err;
return err;
}
@@ -599,9 +695,9 @@ int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
/* Get reference so we can keep this file in LUO until finish */
get_file(luo_file->file);
- WARN_ON(xa_insert(&luo_preserved_files,
- luo_get_id(luo_file->fh, luo_file->file),
- luo_file->file, GFP_KERNEL));
+ if (xa_load(&luo_preserved_files,
+ luo_get_id(luo_file->fh, luo_file->file)) != luo_file->file)
+ WARN_ON(liveupdate_claim_file(luo_file->fh, luo_file->file));
*filep = luo_file->file;
luo_file->retrieve_status = 1;
diff --git a/kernel/liveupdate/luo_internal.h b/kernel/liveupdate/luo_internal.h
index 64879ffe73781..3bd9ef442934e 100644
--- a/kernel/liveupdate/luo_internal.h
+++ b/kernel/liveupdate/luo_internal.h
@@ -64,6 +64,8 @@ struct luo_file_set {
* previous kernel) sessions.
* @retrieved: A boolean flag indicating whether this session has been
* retrieved by a consumer in the new kernel.
+ * @frozen: A boolean flag indicating whether this session has been
+ * frozen early from userspace.
* @file_set: A set of files that belong to this session.
* @mutex: protects fields in the luo_session.
*/
@@ -71,6 +73,7 @@ struct luo_session {
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
struct list_head list;
bool retrieved;
+ bool frozen;
struct luo_file_set file_set;
struct mutex mutex;
};
@@ -84,13 +87,14 @@ int __init luo_session_setup_incoming(u64 sessions_pa);
int luo_session_serialize(void);
int luo_session_deserialize(void);
-int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd);
+int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd,
+ u64 arg);
void luo_file_unpreserve_files(struct luo_file_set *file_set);
int luo_file_freeze(struct luo_file_set *file_set,
struct luo_file_set_ser *file_set_ser);
void luo_file_unfreeze(struct luo_file_set *file_set,
struct luo_file_set_ser *file_set_ser);
-int luo_retrieve_file(struct luo_file_set *file_set, u64 token,
+int luo_retrieve_file(struct luo_file_set *file_set, u64 token, u64 arg,
struct file **filep);
int luo_file_finish(struct luo_file_set *file_set);
int luo_file_deserialize(struct luo_file_set *file_set,
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index f48e9a4185f97..74f8a1bf1da8c 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -34,10 +34,11 @@
* 1. Creation: A userspace agent calls `luo_session_create()` to create a
* new, empty session and receives a file descriptor for it.
*
- * 2. Serialization: When the `reboot(LINUX_REBOOT_CMD_KEXEC)` syscall is
- * made, `luo_session_serialize()` is called. It iterates through all
- * active sessions and writes their metadata into a memory area preserved
- * by KHO.
+ * 2. Freeze / Serialization: Sessions may be frozen early from userspace
+ * via `LIVEUPDATE_SESSION_FREEZE`. When the `reboot(LINUX_REBOOT_CMD_KEXEC)`
+ * syscall is made, `luo_session_serialize()` is called to freeze any
+ * remaining active sessions and write all session metadata into a memory
+ * area preserved by KHO.
*
* 3. Deserialization (in new kernel): After kexec, `luo_session_deserialize()`
* runs, reading the serialized data and creating a list of `struct
@@ -222,6 +223,10 @@ static void luo_session_unfreeze_one(struct luo_session *session,
struct luo_session_ser *ser)
{
guard(mutex)(&session->mutex);
+ if (session->frozen) {
+ memset(&ser->file_set_ser, 0, sizeof(ser->file_set_ser));
+ return;
+ }
luo_file_unfreeze(&session->file_set, &ser->file_set_ser);
}
@@ -229,6 +234,12 @@ static int luo_session_freeze_one(struct luo_session *session,
struct luo_session_ser *ser)
{
guard(mutex)(&session->mutex);
+ if (session->frozen) {
+ ser->file_set_ser.count = session->file_set.count;
+ ser->file_set_ser.files =
+ kho_block_set_head_pa(&session->file_set.block_set);
+ return 0;
+ }
return luo_file_freeze(&session->file_set, &ser->file_set_ser);
}
@@ -249,8 +260,11 @@ static int luo_session_release(struct inode *inodep, struct file *filep)
}
sh = &luo_session_global.incoming;
} else {
- scoped_guard(mutex, &session->mutex)
+ scoped_guard(mutex, &session->mutex) {
+ if (session->frozen)
+ luo_file_unfreeze(&session->file_set, NULL);
luo_file_unpreserve_files(&session->file_set);
+ }
sh = &luo_session_global.outgoing;
}
@@ -267,7 +281,11 @@ static int luo_session_preserve_fd(struct luo_session *session,
int err;
guard(mutex)(&session->mutex);
- err = luo_preserve_file(&session->file_set, argp->token, argp->fd);
+ if (session->frozen)
+ return -EBUSY;
+
+ err = luo_preserve_file(&session->file_set, argp->token, argp->fd,
+ argp->arg);
if (err)
return err;
@@ -290,7 +308,8 @@ static int luo_session_retrieve_fd(struct luo_session *session,
return argp->fd;
mutex_lock(&session->mutex);
- err = luo_retrieve_file(&session->file_set, argp->token, &file);
+ err = luo_retrieve_file(&session->file_set, argp->token, argp->arg,
+ &file);
mutex_unlock(&session->mutex);
if (err < 0)
goto err_put_fd;
@@ -340,11 +359,34 @@ static int luo_session_get_name(struct luo_session *session,
return luo_ucmd_respond(ucmd, sizeof(*argp));
}
+static int luo_session_freeze(struct luo_session *session,
+ struct luo_ucmd *ucmd)
+{
+ struct liveupdate_session_freeze *argp = ucmd->cmd;
+ int err;
+
+ if (argp->reserved)
+ return -EINVAL;
+
+ guard(mutex)(&session->mutex);
+ if (session->frozen)
+ return -EBUSY;
+
+ err = luo_file_freeze(&session->file_set, NULL);
+ if (err)
+ return err;
+
+ session->frozen = true;
+
+ return luo_ucmd_respond(ucmd, sizeof(*argp));
+}
+
union ucmd_buffer {
struct liveupdate_session_finish finish;
struct liveupdate_session_preserve_fd preserve;
struct liveupdate_session_retrieve_fd retrieve;
struct liveupdate_session_get_name get_name;
+ struct liveupdate_session_freeze freeze;
};
/* Type of sessions the ioctl applies to. */
@@ -382,6 +424,8 @@ static const struct luo_ioctl_op luo_session_ioctl_ops[] = {
struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),
IOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,
struct liveupdate_session_get_name, name, LUO_IOCTL_ALL),
+ IOCTL_OP(LIVEUPDATE_SESSION_FREEZE, luo_session_freeze,
+ struct liveupdate_session_freeze, reserved, LUO_IOCTL_OUTGOING),
};
static bool luo_ioctl_type_valid(struct luo_session *session,
diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
index 59de210bee5f9..9d18f01191c07 100644
--- a/mm/memfd_luo.c
+++ b/mm/memfd_luo.c
@@ -9,14 +9,14 @@
*/
/**
- * DOC: Memfd Preservation via LUO
+ * DOC: Memfd and Tmpfs Preservation via LUO
*
* Overview
* ========
*
- * Memory file descriptors (memfd) can be preserved over a kexec using the Live
- * Update Orchestrator (LUO) file preservation. This allows userspace to
- * transfer its memory contents to the next kernel after a kexec.
+ * Memory file descriptors and generic tmpfs files can be preserved over a
+ * kexec using the LUO file preservation. This allows userspace to transfer its
+ * memory contents to the next kernel after a kexec.
*
* The preservation is not intended to be transparent. Only select properties of
* the file are preserved. All others are reset to default. The preserved
@@ -24,16 +24,17 @@
*
* .. note::
* The LUO API is not stabilized yet, so the preserved properties of a memfd
- * are also not stable and are subject to backwards incompatible changes.
+ * or tmpfs file are also not stable and are subject to backwards
+ * incompatible changes.
*
* .. note::
- * Currently a memfd backed by Hugetlb is not supported. Memfds created
+ * Currently a file backed by Hugetlb is not supported. Memfds created
* with ``MFD_HUGETLB`` will be rejected.
*
* Preserved Properties
* ====================
*
- * The following properties of the memfd are preserved across kexec:
+ * The following properties of the memfd/tmpfs file are preserved across kexec:
*
* File Contents
* All data stored in the file is preserved.
@@ -43,8 +44,9 @@
* allocating pages for them during preservation.
*
* File Position
- * The current file position is preserved, allowing applications to continue
- * reading/writing from their last position.
+ * The file position at the time the session is frozen is preserved,
+ * allowing applications to continue reading/writing from their last
+ * position.
*
* File Status Flags
* memfds are always opened with ``O_RDWR`` and ``O_LARGEFILE``. This property
@@ -299,6 +301,8 @@ static int memfd_luo_preserve(struct liveupdate_file_op_args *args)
ser->size = inode_size;
ser->seals = seals;
+ if (inode->i_nlink)
+ ser->flags |= MEMFD_LUO_FLAG_TMPFS;
err = memfd_luo_preserve_folios(args->file, &ser->folios,
&folios_ser, &nr_folios);
@@ -515,10 +519,60 @@ static int memfd_luo_retrieve_folios(struct file *file,
return err;
}
+static struct file *memfd_luo_get_tmpfs_file(struct liveupdate_file_op_args *args)
+{
+ const struct liveupdate_memfd_retrieve_arg *rarg = args->arg;
+ struct inode *inode;
+ struct file *file;
+ int err;
+
+ if (!rarg)
+ return ERR_PTR(-EINVAL);
+
+ file = fget(rarg->fd);
+ if (!file)
+ return ERR_PTR(-EBADF);
+
+ if (!(file->f_mode & FMODE_WRITE)) {
+ err = -EACCES;
+ goto put_file;
+ }
+
+ if (!shmem_file(file)) {
+ err = -EINVAL;
+ goto put_file;
+ }
+
+ inode = file_inode(file);
+ inode_lock(inode);
+ if (!inode->i_nlink) {
+ err = -EINVAL;
+ goto unlock_inode;
+ }
+
+ if (i_size_read(inode) != 0 || !mapping_empty(inode->i_mapping)) {
+ err = -EBUSY;
+ goto unlock_inode;
+ }
+
+ err = liveupdate_claim_file(args->handler, file);
+ if (err)
+ goto unlock_inode;
+
+ return file;
+
+unlock_inode:
+ inode_unlock(inode);
+put_file:
+ fput(file);
+ return ERR_PTR(err);
+}
+
static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)
{
struct memfd_luo_folio_ser *folios_ser;
struct memfd_luo_ser *ser;
+ struct inode *inode;
struct file *file;
int err;
@@ -526,50 +580,75 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)
if (!ser)
return -EINVAL;
- /* Make sure the file only has seals supported by this version. */
- if (ser->seals & ~MEMFD_LUO_ALL_SEALS) {
+ /* Make sure the file only has seals and flags supported by this version. */
+ if ((ser->seals & ~MEMFD_LUO_ALL_SEALS) ||
+ (ser->flags & ~MEMFD_LUO_ALL_FLAGS)) {
err = -EOPNOTSUPP;
goto free_ser;
}
- /*
- * The seals are preserved. Allow sealing here so they can be added
- * later.
- */
- file = memfd_alloc_file("", MFD_ALLOW_SEALING);
- if (IS_ERR(file)) {
- pr_err("failed to setup file: %pe\n", file);
- err = PTR_ERR(file);
- goto free_ser;
- }
+ if (ser->flags & MEMFD_LUO_FLAG_TMPFS) {
+ file = memfd_luo_get_tmpfs_file(args);
+ if (IS_ERR(file)) {
+ args->retryable = true;
+ return PTR_ERR(file);
+ }
+ inode = file_inode(file);
+ } else {
+ if (args->arg) {
+ args->retryable = true;
+ return -EINVAL;
+ }
- err = memfd_add_seals(file, ser->seals);
- if (err) {
- pr_err("failed to add seals: %pe\n", ERR_PTR(err));
- goto put_file;
- }
+ /*
+ * The seals are preserved. Allow sealing here so they can be
+ * added later.
+ */
+ file = memfd_alloc_file("", MFD_ALLOW_SEALING);
+ if (IS_ERR(file)) {
+ pr_err("failed to setup file: %pe\n", file);
+ err = PTR_ERR(file);
+ goto free_ser;
+ }
- vfs_setpos(file, ser->pos, MAX_LFS_FILESIZE);
- i_size_write(file_inode(file), ser->size);
+ err = memfd_add_seals(file, ser->seals);
+ if (err) {
+ pr_err("failed to add seals: %pe\n", ERR_PTR(err));
+ goto put_file;
+ }
+
+ inode = file_inode(file);
+ inode_lock(inode);
+ }
if (ser->nr_folios) {
folios_ser = kho_restore_vmalloc(&ser->folios);
if (!folios_ser) {
err = -EINVAL;
- goto put_file;
+ goto unclaim_file;
}
err = memfd_luo_retrieve_folios(file, folios_ser, ser->nr_folios);
vfree(folios_ser);
if (err)
- goto put_file;
+ goto unclaim_file;
}
+ vfs_setpos(file, ser->pos, MAX_LFS_FILESIZE);
+ i_size_write(inode, ser->size);
+ inode_unlock(inode);
+
args->file = file;
kho_restore_free(ser);
return 0;
+unclaim_file:
+ if (ser->flags & MEMFD_LUO_FLAG_TMPFS) {
+ shmem_truncate_range(inode, 0, (loff_t)-1);
+ liveupdate_unclaim_file(args->handler, file);
+ }
+ inode_unlock(inode);
put_file:
fput(file);
free_ser:
@@ -580,9 +659,7 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)
static bool memfd_luo_can_preserve(struct liveupdate_file_handler *handler,
struct file *file)
{
- struct inode *inode = file_inode(file);
-
- return shmem_file(file) && !inode->i_nlink;
+ return shmem_file(file);
}
static unsigned long memfd_luo_get_id(struct file *file)
@@ -598,6 +675,7 @@ static const struct liveupdate_file_ops memfd_luo_file_ops = {
.unpreserve = memfd_luo_unpreserve,
.can_preserve = memfd_luo_can_preserve,
.get_id = memfd_luo_get_id,
+ .rarg = LIVEUPDATE_ARG(struct liveupdate_memfd_retrieve_arg, fd),
.owner = THIS_MODULE,
};
diff --git a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
index fa07fed083646..dc5c01408462d 100644
--- a/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
+++ b/tools/testing/selftests/liveupdate/lib/include/libliveupdate.h
@@ -26,13 +26,19 @@ int luo_create_session(int luo_fd, const char *name);
int luo_retrieve_session(int luo_fd, const char *name);
int luo_session_finish(int session_fd);
int luo_get_session_name(int session_fd, char *name, size_t name_len);
+int luo_session_freeze(int session_fd);
int luo_ensure_nofile_limit(long min_limit);
int luo_session_preserve_fd(int session_fd, int fd, __u64 token);
+int luo_session_preserve_fd_arg(int session_fd, int fd, __u64 token,
+ __u64 user_arg);
int luo_session_retrieve_fd(int session_fd, __u64 token);
+int luo_session_retrieve_fd_arg(int session_fd, __u64 token, __u64 user_arg);
int create_and_preserve_memfd(int session_fd, int token, const char *data);
int restore_and_verify_memfd(int session_fd, int token, const char *expected_data);
+int restore_and_verify_tmpfs(int session_fd, int token, int fd,
+ const char *expected_data);
void create_state_file(int luo_fd, const char *session_name, int token,
int next_stage);
diff --git a/tools/testing/selftests/liveupdate/lib/lu_utils.c b/tools/testing/selftests/liveupdate/lib/lu_utils.c
index 74d41115c2815..1b1a556287d3a 100644
--- a/tools/testing/selftests/liveupdate/lib/lu_utils.c
+++ b/tools/testing/selftests/liveupdate/lib/lu_utils.c
@@ -79,12 +79,14 @@ int luo_retrieve_session(int luo_fd, const char *name)
return arg.fd;
}
-int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
+int luo_session_preserve_fd_arg(int session_fd, int fd, __u64 token,
+ __u64 user_arg)
{
struct liveupdate_session_preserve_fd arg = {
.size = sizeof(arg),
.fd = fd,
.token = token,
+ .arg = user_arg,
};
if (ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &arg))
@@ -93,11 +95,17 @@ int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
return 0;
}
-int luo_session_retrieve_fd(int session_fd, __u64 token)
+int luo_session_preserve_fd(int session_fd, int fd, __u64 token)
+{
+ return luo_session_preserve_fd_arg(session_fd, fd, token, 0);
+}
+
+int luo_session_retrieve_fd_arg(int session_fd, __u64 token, __u64 user_arg)
{
struct liveupdate_session_retrieve_fd arg = {
.size = sizeof(arg),
.token = token,
+ .arg = user_arg,
};
if (ioctl(session_fd, LIVEUPDATE_SESSION_RETRIEVE_FD, &arg))
@@ -106,6 +114,11 @@ int luo_session_retrieve_fd(int session_fd, __u64 token)
return arg.fd;
}
+int luo_session_retrieve_fd(int session_fd, __u64 token)
+{
+ return luo_session_retrieve_fd_arg(session_fd, token, 0);
+}
+
/* Helper function to get a session name via ioctl. */
int luo_get_session_name(int session_fd, char *name, size_t name_len)
{
@@ -198,6 +211,16 @@ int luo_session_finish(int session_fd)
return 0;
}
+int luo_session_freeze(int session_fd)
+{
+ struct liveupdate_session_freeze arg = { .size = sizeof(arg) };
+
+ if (ioctl(session_fd, LIVEUPDATE_SESSION_FREEZE, &arg) < 0)
+ return -errno;
+
+ return 0;
+}
+
void create_state_file(int luo_fd, const char *session_name, int token,
int next_stage)
{
@@ -324,3 +347,47 @@ int luo_test(int argc, char *argv[],
return 0;
}
+
+int restore_and_verify_tmpfs(int session_fd, int token, int fd,
+ const char *expected_data)
+{
+ struct liveupdate_memfd_retrieve_arg rarg = {
+ .size = sizeof(rarg),
+ .fd = fd,
+ };
+ long page_size = getpagesize();
+ void *map = MAP_FAILED;
+ struct stat st;
+ int ret_fd;
+
+ ret_fd = luo_session_retrieve_fd_arg(session_fd, token,
+ (unsigned long)&rarg);
+ if (ret_fd < 0) {
+ ksft_print_msg("luo_session_retrieve_fd_arg failed: %d\n",
+ ret_fd);
+ return ret_fd;
+ }
+ close(ret_fd);
+
+ if (fstat(fd, &st) < 0)
+ return -errno;
+ if (st.st_size != page_size) {
+ ksft_print_msg("Size mismatch! Expected %ld, Got %lld\n",
+ page_size, (long long)st.st_size);
+ return -EINVAL;
+ }
+
+ map = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (map == MAP_FAILED)
+ return -errno;
+
+ if (expected_data && strcmp(expected_data, map) != 0) {
+ ksft_print_msg("Data mismatch! Expected '%s', Got '%s'\n",
+ expected_data, (char *)map);
+ munmap(map, page_size);
+ return -EINVAL;
+ }
+
+ munmap(map, page_size);
+ return 0;
+}
diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c
index 2dedd5fc2534f..83e0978f3818d 100644
--- a/tools/testing/selftests/liveupdate/liveupdate.c
+++ b/tools/testing/selftests/liveupdate/liveupdate.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <stddef.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
@@ -530,4 +531,87 @@ TEST_F(liveupdate_device, preserve_many_files)
ASSERT_EQ(close(session_fd), 0);
}
+/*
+ * Test Case: Session Freeze
+ *
+ * Verifies that an outgoing session can be frozen early via
+ * LIVEUPDATE_SESSION_FREEZE, that subsequent freeze attempts return -EBUSY,
+ * and that attempting to preserve an additional file descriptor into a frozen
+ * session fails with -EBUSY.
+ */
+TEST_F(liveupdate_device, session_freeze)
+{
+ int session_fd, mem_fd1, mem_fd2;
+
+ self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
+ if (self->fd1 < 0 && errno == ENOENT)
+ SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
+ ASSERT_GE(self->fd1, 0);
+
+ session_fd = luo_create_session(self->fd1, "session-freeze-test");
+ ASSERT_GE(session_fd, 0);
+
+ mem_fd1 = memfd_create("freeze-memfd-1", 0);
+ ASSERT_GE(mem_fd1, 0);
+ ASSERT_EQ(luo_session_preserve_fd(session_fd, mem_fd1, 0x1111), 0);
+
+ /* Freeze the session early */
+ ASSERT_EQ(luo_session_freeze(session_fd), 0);
+
+ /* Subsequent freeze attempt on an already frozen session must fail with -EBUSY */
+ EXPECT_EQ(luo_session_freeze(session_fd), -EBUSY);
+
+ /* Preserving a file after freeze must fail with -EBUSY */
+ mem_fd2 = memfd_create("freeze-memfd-2", 0);
+ ASSERT_GE(mem_fd2, 0);
+ EXPECT_EQ(luo_session_preserve_fd(session_fd, mem_fd2, 0x2222), -EBUSY);
+
+ ASSERT_EQ(close(session_fd), 0);
+ ASSERT_EQ(close(mem_fd1), 0);
+ ASSERT_EQ(close(mem_fd2), 0);
+}
+
+/*
+ * Test Case: Preserve MemFD with User Argument
+ *
+ * Verifies that passing a non-zero user argument to memfd preservation fails
+ * with -EOPNOTSUPP, while passing a zero argument or using the minimum struct
+ * size without the arg field succeeds.
+ */
+TEST_F(liveupdate_device, preserve_memfd_with_arg)
+{
+ struct liveupdate_session_preserve_fd min_arg = {};
+ int session_fd, mem_fd1, mem_fd2;
+
+ self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
+ if (self->fd1 < 0 && errno == ENOENT)
+ SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
+ ASSERT_GE(self->fd1, 0);
+
+ session_fd = luo_create_session(self->fd1, "preserve-arg-test");
+ ASSERT_GE(session_fd, 0);
+
+ mem_fd1 = memfd_create("arg-memfd-1", 0);
+ ASSERT_GE(mem_fd1, 0);
+
+ /* Non-zero arg is not supported by memfd handler */
+ EXPECT_EQ(luo_session_preserve_fd_arg(session_fd, mem_fd1, 0x1111, 1),
+ -EOPNOTSUPP);
+
+ /* Legacy struct size (up to token) should zero-fill arg and succeed */
+ min_arg.size = offsetof(struct liveupdate_session_preserve_fd, arg);
+ min_arg.fd = mem_fd1;
+ min_arg.token = 0x1111;
+ ASSERT_EQ(ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &min_arg), 0);
+
+ /* Explicit zero arg with full struct size should also succeed */
+ mem_fd2 = memfd_create("arg-memfd-2", 0);
+ ASSERT_GE(mem_fd2, 0);
+ ASSERT_EQ(luo_session_preserve_fd_arg(session_fd, mem_fd2, 0x2222, 0), 0);
+
+ ASSERT_EQ(close(session_fd), 0);
+ ASSERT_EQ(close(mem_fd1), 0);
+ ASSERT_EQ(close(mem_fd2), 0);
+}
+
TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/liveupdate/luo_kexec_simple.c b/tools/testing/selftests/liveupdate/luo_kexec_simple.c
index 786ac93b9ae38..ab108c7f1d855 100644
--- a/tools/testing/selftests/liveupdate/luo_kexec_simple.c
+++ b/tools/testing/selftests/liveupdate/luo_kexec_simple.c
@@ -40,6 +40,11 @@ static void run_stage_1(int luo_fd)
TEST_MEMFD_TOKEN);
}
+ ksft_print_msg("[STAGE 1] Freezing session '%s' early...\n",
+ TEST_SESSION_NAME);
+ if (luo_session_freeze(session_fd) < 0)
+ fail_exit("luo_session_freeze for '%s'", TEST_SESSION_NAME);
+
close(luo_fd);
daemonize_and_wait();
}
diff --git a/tools/testing/selftests/liveupdate/luo_multi_session.c b/tools/testing/selftests/liveupdate/luo_multi_session.c
index aac24a5f5ce3c..46889676d9f52 100644
--- a/tools/testing/selftests/liveupdate/luo_multi_session.c
+++ b/tools/testing/selftests/liveupdate/luo_multi_session.c
@@ -9,7 +9,15 @@
* files.
*/
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#include <libliveupdate.h>
+#include <linux/liveupdate.h>
#define SESSION_EMPTY_1 "multi-test-empty-1"
#define SESSION_EMPTY_2 "multi-test-empty-2"
@@ -23,6 +31,7 @@
#define MFD1_DATA "Data for session files 1"
#define MFD2_DATA "First file for session files 2"
#define MFD3_DATA "Second file for session files 2"
+#define MFD3_POS 42
#define STATE_SESSION_NAME "kexec_multi_state"
#define STATE_MEMFD_TOKEN 998
@@ -31,6 +40,8 @@
static void run_stage_1(int luo_fd)
{
int s_empty1_fd, s_empty2_fd, s_files1_fd, s_files2_fd;
+ int tmpfs_fd;
+ void *map;
ksft_print_msg("[STAGE 1] Starting pre-kexec setup for multi-session test...\n");
@@ -53,25 +64,50 @@ static void run_stage_1(int luo_fd)
s_files1_fd = luo_create_session(luo_fd, SESSION_FILES_1);
if (s_files1_fd < 0)
fail_exit("luo_create_session for '%s'", SESSION_FILES_1);
+ ksft_print_msg(" -> Preserving memfd (token %#x, content: \"%s\")\n",
+ MFD1_TOKEN, MFD1_DATA);
if (create_and_preserve_memfd(s_files1_fd, MFD1_TOKEN, MFD1_DATA) < 0) {
fail_exit("create_and_preserve_memfd for token %#x",
MFD1_TOKEN);
}
- ksft_print_msg("[STAGE 1] Creating session '%s' with two memfds...\n",
+ ksft_print_msg("[STAGE 1] Creating session '%s' with memfd and tmpfs file...\n",
SESSION_FILES_2);
s_files2_fd = luo_create_session(luo_fd, SESSION_FILES_2);
if (s_files2_fd < 0)
fail_exit("luo_create_session for '%s'", SESSION_FILES_2);
+ ksft_print_msg(" -> Preserving memfd (token %#x, content: \"%s\")\n",
+ MFD2_TOKEN, MFD2_DATA);
if (create_and_preserve_memfd(s_files2_fd, MFD2_TOKEN, MFD2_DATA) < 0) {
fail_exit("create_and_preserve_memfd for token %#x",
MFD2_TOKEN);
}
- if (create_and_preserve_memfd(s_files2_fd, MFD3_TOKEN, MFD3_DATA) < 0) {
- fail_exit("create_and_preserve_memfd for token %#x",
- MFD3_TOKEN);
- }
+
+ ksft_print_msg(" -> Populating tmpfs file at /mnt/mfd3...\n");
+ if (mkdir("/mnt", 0777) < 0 && errno != EEXIST)
+ fail_exit("mkdir /mnt");
+ if (mount("tmpfs", "/mnt", "tmpfs", 0, NULL) < 0)
+ fail_exit("mount tmpfs");
+ tmpfs_fd = open("/mnt/mfd3", O_CREAT | O_RDWR, 0666);
+ if (tmpfs_fd < 0)
+ fail_exit("failed to open tmpfs_fd");
+ ksft_print_msg(" -> Preserving generic tmpfs file (token %#x, content: \"%s\")\n",
+ MFD3_TOKEN, MFD3_DATA);
+ if (ftruncate(tmpfs_fd, getpagesize()) < 0)
+ fail_exit("ftruncate tmpfs_fd");
+ map = mmap(NULL, getpagesize(), PROT_WRITE, MAP_SHARED, tmpfs_fd, 0);
+ if (map == MAP_FAILED)
+ fail_exit("mmap tmpfs_fd");
+ strcpy(map, MFD3_DATA);
+ munmap(map, getpagesize());
+ if (lseek(tmpfs_fd, MFD3_POS, SEEK_SET) != MFD3_POS)
+ fail_exit("lseek tmpfs_fd");
+
+ if (luo_session_preserve_fd(s_files2_fd, tmpfs_fd, MFD3_TOKEN) < 0)
+ fail_exit("preserve tmpfs fd");
+
+ close(tmpfs_fd);
close(luo_fd);
daemonize_and_wait();
@@ -81,7 +117,10 @@ static void run_stage_1(int luo_fd)
static void run_stage_2(int luo_fd, int state_session_fd)
{
int s_empty1_fd, s_empty2_fd, s_files1_fd, s_files2_fd;
- int mfd1, mfd2, mfd3, stage;
+ struct liveupdate_memfd_retrieve_arg rarg = {
+ .size = sizeof(rarg),
+ };
+ int mfd1, mfd2, mfd3, ro_fd, ret, stage;
ksft_print_msg("[STAGE 2] Starting post-kexec verification...\n");
@@ -110,6 +149,8 @@ static void run_stage_2(int luo_fd, int state_session_fd)
ksft_print_msg("[STAGE 2] Verifying contents of session '%s'...\n",
SESSION_FILES_1);
+ ksft_print_msg(" -> Retrieving memfd (token %#x) from session...\n",
+ MFD1_TOKEN);
mfd1 = restore_and_verify_memfd(s_files1_fd, MFD1_TOKEN, MFD1_DATA);
if (mfd1 < 0)
fail_exit("restore_and_verify_memfd for token %#x", MFD1_TOKEN);
@@ -118,14 +159,65 @@ static void run_stage_2(int luo_fd, int state_session_fd)
ksft_print_msg("[STAGE 2] Verifying contents of session '%s'...\n",
SESSION_FILES_2);
+ ksft_print_msg(" -> Creating empty tmpfs file at /mnt/mfd3...\n");
+ if (mkdir("/mnt", 0777) < 0 && errno != EEXIST)
+ fail_exit("mkdir /mnt");
+ if (mount("tmpfs", "/mnt", "tmpfs", 0, NULL) < 0)
+ fail_exit("mount tmpfs");
+ mfd3 = open("/mnt/mfd3", O_CREAT | O_RDWR, 0666);
+ if (mfd3 < 0)
+ fail_exit("open tmpfs file");
+ ro_fd = open("/mnt/mfd3", O_RDONLY);
+ if (ro_fd < 0)
+ fail_exit("open read-only tmpfs file");
+
+ ksft_print_msg(" -> Verifying retryable retrieve errors for memfd and tmpfs...\n");
+ rarg.fd = mfd3;
+ ret = luo_session_retrieve_fd_arg(s_files2_fd, MFD2_TOKEN,
+ (uintptr_t)&rarg);
+ if (ret != -EINVAL)
+ fail_exit("expected -EINVAL when passing arg to memfd retrieve, got %d",
+ ret);
+
+ ksft_print_msg(" -> Retrieving memfd (token %#x) from session...\n",
+ MFD2_TOKEN);
mfd2 = restore_and_verify_memfd(s_files2_fd, MFD2_TOKEN, MFD2_DATA);
if (mfd2 < 0)
fail_exit("restore_and_verify_memfd for token %#x", MFD2_TOKEN);
close(mfd2);
- mfd3 = restore_and_verify_memfd(s_files2_fd, MFD3_TOKEN, MFD3_DATA);
- if (mfd3 < 0)
- fail_exit("restore_and_verify_memfd for token %#x", MFD3_TOKEN);
+ ret = luo_session_retrieve_fd(s_files2_fd, MFD3_TOKEN);
+ if (ret != -EINVAL)
+ fail_exit("expected -EINVAL when retrieving tmpfs without arg, got %d",
+ ret);
+
+ rarg.fd = ro_fd;
+ ret = luo_session_retrieve_fd_arg(s_files2_fd, MFD3_TOKEN,
+ (uintptr_t)&rarg);
+ if (ret != -EACCES)
+ fail_exit("expected -EACCES when retrieving tmpfs into read-only fd, got %d",
+ ret);
+ close(ro_fd);
+
+ if (ftruncate(mfd3, 1) < 0)
+ fail_exit("ftruncate non-empty tmpfs file");
+ rarg.fd = mfd3;
+ ret = luo_session_retrieve_fd_arg(s_files2_fd, MFD3_TOKEN,
+ (uintptr_t)&rarg);
+ if (ret != -EBUSY)
+ fail_exit("expected -EBUSY when retrieving tmpfs into non-empty fd, got %d",
+ ret);
+ if (ftruncate(mfd3, 0) < 0)
+ fail_exit("ftruncate empty tmpfs file");
+
+ ksft_print_msg(" -> Retrieving tmpfs file (token %#x) from session...\n",
+ MFD3_TOKEN);
+ if (restore_and_verify_tmpfs(s_files2_fd, MFD3_TOKEN, mfd3,
+ MFD3_DATA) < 0)
+ fail_exit("restore_and_verify_tmpfs for token %#x",
+ MFD3_TOKEN);
+ if (lseek(mfd3, 0, SEEK_CUR) != MFD3_POS)
+ fail_exit("expected f_pos %d on restored tmpfs file", MFD3_POS);
close(mfd3);
ksft_print_msg("[STAGE 2] Test data verified successfully.\n");
|
| 25/3 | 2026/10/15 11:56 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 21937 output: 32 thoughts: 1797 Thoughts: **KMSAN Evaluation for Live Update Patch Series** Okay, let's break this down. The task is to determine if this patch series warrants a dedicated KMSAN fuzzing session. My first thought is to review the rules: KASAN, LOCKDEP, and other standard bug detectors come first. KMSAN is only needed if this patch introduces or modifies kernel structures sent to user space where uninitialized fields could leak or be read, introduces conditional logic based on potentially uninitialized variables, involves the allocation of complex data structures where uninitialized fields could be read later, or has bounds checks which could expose uninitialized bytes. So, let's dive into these code changes specifically in the patch diff! It looks like the patch modifies a number of files: `memfd.h`, `liveupdate.h`, `luo_file.c`, `luo_session.c`, and a couple of selftest files. Looking at `memfd.h`, it's just adding a couple of flags. That's unlikely to be a KMSAN candidate on its own. Now, `liveupdate.h` is more interesting. There are new structs and fields added, like `liveupdate_arg_spec`, `liveupdate_file_op_args`, and `liveupdate_file_ops` as well as changes to existing `struct liveupdate_session_preserve_fd`, `struct liveupdate_session_retrieve_fd` and addition of `struct liveupdate_session_freeze` and `struct liveupdate_memfd_retrieve_arg` . The addition of these new structs and the new `arg` fields is a red flag, as this is all new data that could possibly be sent to user space. The new `liveupdate_claim_file` and `liveupdate_unclaim_file` functions need to be examined as well. Moving to `luo_file.c`, `liveupdate_claim_file` and `liveupdate_unclaim_file` are just wrappers. `luo_copy_user_arg` looks important. We have to check `copy_struct_from_user`. Aha! It copies up to `spec->size` and zero-fills any remaining bytes. Good. This means `karg` is fully initialized, so no immediate KMSAN risk here, though we should double-check how these arguments are *used* later. `luo_preserve_file` and `luo_retrieve_file` both pass arguments to functions. Let's make sure these arguments are not subsequently used in ways where uninitialized memory could be a problem. In `luo_file_freeze` and `luo_file_unfreeze`, checks and zeroing look sound, mitigating potential issues. `luo_session.c` is where things start to seem more complicated. `luo_session_unfreeze_one`, `luo_session_freeze_one` modify session data with `memset`, and `luo_session_release` calls `luo_file_unfreeze`. The calls to `luo_session_preserve_fd`, `luo_session_retrieve_fd` are concerning: they pass `argp->arg`. That needs close inspection to see where it goes. `luo_session_freeze` calls `luo_file_freeze` with a NULL and then calls `luo_ucmd_respond(ucmd, sizeof(*argp));`. Hang on! `luo_ucmd_respond` – that's a key function. Does it send data to user space? We need to verify how ioctl responses are sent to the user. We need to check all `luo_ucmd` calls to trace how the data is sent to user. In conclusion, this patch series *could* justify a KMSAN session. The addition of new arguments, especially the `arg` fields in multiple structs and the use of `luo_ucmd_respond` require further investigation to determine if uninitialized memory could be exposed to user space. It hinges on how these new arguments are used, and whether `luo_ucmd_respond` copies data to userland. We have to make sure there are no uninitialized variables or data structures passed to user space. |
| 26/3 | 2026/10/15 11:56 | tool | grepper |
0mArgs:{
"Expression": "luo_ucmd_respond",
"PathPrefixes": [
"kernel/liveupdate"
]
}Results: {
"Output": "kernel/liveupdate/luo_core.c=270=static int luo_ioctl_create_session(struct luo_ucmd *ucmd)\n--\nkernel/liveupdate/luo_core.c-283-\nkernel/liveupdate/luo_core.c:284:\terr = luo_ucmd_respond(ucmd, sizeof(*argp));\nkernel/liveupdate/luo_core.c-285-\tif (err)\n--\nkernel/liveupdate/luo_core.c=300=static int luo_ioctl_retrieve_session(struct luo_ucmd *ucmd)\n--\nkernel/liveupdate/luo_core.c-313-\nkernel/liveupdate/luo_core.c:314:\terr = luo_ucmd_respond(ucmd, sizeof(*argp));\nkernel/liveupdate/luo_core.c-315-\tif (err)\n--\nkernel/liveupdate/luo_internal.h=15=struct luo_ucmd {\n--\nkernel/liveupdate/luo_internal.h-20-\nkernel/liveupdate/luo_internal.h:21:static inline int luo_ucmd_respond(struct luo_ucmd *ucmd,\nkernel/liveupdate/luo_internal.h-22-\t\t\t\t size_t kernel_cmd_size)\n--\nkernel/liveupdate/luo_session.c=277=static int luo_session_preserve_fd(struct luo_session *session,\n--\nkernel/liveupdate/luo_session.c-291-\nkernel/liveupdate/luo_session.c:292:\terr = luo_ucmd_respond(ucmd, sizeof(*argp));\nkernel/liveupdate/luo_session.c-293-\tif (err)\n--\nkernel/liveupdate/luo_session.c=299=static int luo_session_retrieve_fd(struct luo_session *session,\n--\nkernel/liveupdate/luo_session.c-316-\nkernel/liveupdate/luo_session.c:317:\terr = luo_ucmd_respond(ucmd, sizeof(*argp));\nkernel/liveupdate/luo_session.c-318-\tif (err)\n--\nkernel/liveupdate/luo_session.c=333=static int luo_session_finish(struct luo_session *session,\n--\nkernel/liveupdate/luo_session.c-345-\nkernel/liveupdate/luo_session.c:346:\treturn luo_ucmd_respond(ucmd, sizeof(*argp));\nkernel/liveupdate/luo_session.c-347-}\n--\nkernel/liveupdate/luo_session.c=349=static int luo_session_get_name(struct luo_session *session,\n--\nkernel/liveupdate/luo_session.c-358-\nkernel/liveupdate/luo_session.c:359:\treturn luo_ucmd_respond(ucmd, sizeof(*argp));\nkernel/liveupdate/luo_session.c-360-}\n--\nkernel/liveupdate/luo_session.c=362=static int luo_session_freeze(struct luo_session *session,\n--\nkernel/liveupdate/luo_session.c-380-\nkernel/liveupdate/luo_session.c:381:\treturn luo_ucmd_respond(ucmd, sizeof(*argp));\nkernel/liveupdate/luo_session.c-382-}\n"
} |
| 27/3 | 2026/10/15 11:56 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25572 output: 37 thoughts: 57 Thoughts: Here's my summary, as if I were thinking it: **Diving into the `luo_ucmd` Structure** Okay, let's get down to brass tacks. I need to understand the lifecycle of `luo_ucmd` and the communication flow around `luo_ucmd` and `luo_ucmd_respond`. I'm going to jump into `kernel/liveupdate/luo_internal.h`, specifically around line 15, that should contain the declaration or relevant structures. I'm especially interested in how the `ucmd->cmd` member is handled. I want to see if it's dynamically allocated, statically initialized, or handled some other way. This should give me a better handle on the underlying mechanism. |
| 28/3 | 2026/10/15 11:57 | tool | read-file |
0mArgs:{
"File": "kernel/liveupdate/luo_internal.h",
"FirstLine": 1,
"LineCount": 40
}Results: {
"Contents": " 1:\t/* SPDX-License-Identifier: GPL-2.0 */\n 2:\t\n 3:\t/*\n 4:\t * Copyright (c) 2025, Google LLC.\n 5:\t * Pasha Tatashin \u003cpasha.tatashin@soleen.com\u003e\n 6:\t */\n 7:\t\n 8:\t#ifndef _LINUX_LUO_INTERNAL_H\n 9:\t#define _LINUX_LUO_INTERNAL_H\n 10:\t\n 11:\t#include \u003clinux/liveupdate.h\u003e\n 12:\t#include \u003clinux/uaccess.h\u003e\n 13:\t#include \u003clinux/kho_block.h\u003e\n 14:\t\n 15:\tstruct luo_ucmd {\n 16:\t\tvoid __user *ubuffer;\n 17:\t\tu32 user_size;\n 18:\t\tvoid *cmd;\n 19:\t};\n 20:\t\n 21:\tstatic inline int luo_ucmd_respond(struct luo_ucmd *ucmd,\n 22:\t\t\t\t\t size_t kernel_cmd_size)\n 23:\t{\n 24:\t\t/*\n 25:\t\t * Copy the minimum of what the user provided and what we actually\n 26:\t\t * have.\n 27:\t\t */\n 28:\t\tif (copy_to_user(ucmd-\u003eubuffer, ucmd-\u003ecmd,\n 29:\t\t\t\t min_t(size_t, ucmd-\u003euser_size, kernel_cmd_size))) {\n 30:\t\t\treturn -EFAULT;\n 31:\t\t}\n 32:\t\treturn 0;\n 33:\t}\n 34:\t\n 35:\t/*\n 36:\t * Handles a deserialization failure: devices and memory is in unpredictable\n 37:\t * state.\n 38:\t *\n 39:\t * Continuing the boot process after a failure is dangerous because it could\n 40:\t * lead to leaks of private data.\n"
} |
| 29/3 | 2026/10/15 11:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26343 output: 29 thoughts: 27 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into the `ucmd` Setup in `kernel/liveupdate/luo_session.c`** Alright, let's get down to brass tacks. I need to understand the command interface – specifically, how `ucmd` is architected within the `luo_session.c` file of the kernel's live update functionality. I'm assuming, given the context, that `ucmd` likely handles the user-space command interpretation that drives the live update process. I'm particularly interested in the registration and dispatch mechanisms. Is it a simple command table, a more sophisticated handler based on function pointers, or something else entirely? I'll be looking for how the commands are defined, parsed, validated, and finally executed within the live update context. I'll need to see how these user commands interact with the underlying live update infrastructure, including the session management and image manipulation components. Specifically, I'm keen to understand any security implications inherent in the command structure, given the critical nature of live updates. Are there checks for command injection, buffer overflows, or other potential vulnerabilities that a well-crafted user command could exploit? I'll also be focusing on the state management – how the `ucmd` structure interacts with any internal state machines within `luo_session.c`, and how the state transitions are handled and synchronized. Let's see how they do it. |
| 30/3 | 2026/10/15 11:57 | tool | grepper |
0mArgs:{
"Expression": "IOCTL_OP",
"PathPrefixes": [
"kernel/liveupdate"
]
}Results: {
"Output": "kernel/liveupdate/luo_core.c=363=struct luo_ioctl_op {\n--\nkernel/liveupdate/luo_core.c-369-\nkernel/liveupdate/luo_core.c:370:#define IOCTL_OP(_ioctl, _fn, _struct, _last) \\\nkernel/liveupdate/luo_core.c-371-\t[_IOC_NR(_ioctl) - LIVEUPDATE_CMD_BASE] = { \\\n--\nkernel/liveupdate/luo_core.c=380=static const struct luo_ioctl_op luo_ioctl_ops[] = {\nkernel/liveupdate/luo_core.c:381:\tIOCTL_OP(LIVEUPDATE_IOCTL_CREATE_SESSION, luo_ioctl_create_session,\nkernel/liveupdate/luo_core.c-382-\t\t struct liveupdate_ioctl_create_session, name),\nkernel/liveupdate/luo_core.c:383:\tIOCTL_OP(LIVEUPDATE_IOCTL_RETRIEVE_SESSION, luo_ioctl_retrieve_session,\nkernel/liveupdate/luo_core.c-384-\t\t struct liveupdate_ioctl_retrieve_session, name),\n--\nkernel/liveupdate/luo_session.c=399=struct luo_ioctl_op {\n--\nkernel/liveupdate/luo_session.c-406-\nkernel/liveupdate/luo_session.c:407:#define IOCTL_OP(_ioctl, _fn, _struct, _last, _type) \\\nkernel/liveupdate/luo_session.c-408-\t[_IOC_NR(_ioctl) - LIVEUPDATE_CMD_SESSION_BASE] = { \\\n--\nkernel/liveupdate/luo_session.c=418=static const struct luo_ioctl_op luo_session_ioctl_ops[] = {\nkernel/liveupdate/luo_session.c:419:\tIOCTL_OP(LIVEUPDATE_SESSION_FINISH, luo_session_finish,\nkernel/liveupdate/luo_session.c-420-\t\t struct liveupdate_session_finish, reserved, LUO_IOCTL_INCOMING),\nkernel/liveupdate/luo_session.c:421:\tIOCTL_OP(LIVEUPDATE_SESSION_PRESERVE_FD, luo_session_preserve_fd,\nkernel/liveupdate/luo_session.c-422-\t\t struct liveupdate_session_preserve_fd, token, LUO_IOCTL_OUTGOING),\nkernel/liveupdate/luo_session.c:423:\tIOCTL_OP(LIVEUPDATE_SESSION_RETRIEVE_FD, luo_session_retrieve_fd,\nkernel/liveupdate/luo_session.c-424-\t\t struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),\nkernel/liveupdate/luo_session.c:425:\tIOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,\nkernel/liveupdate/luo_session.c-426-\t\t struct liveupdate_session_get_name, name, LUO_IOCTL_ALL),\nkernel/liveupdate/luo_session.c:427:\tIOCTL_OP(LIVEUPDATE_SESSION_FREEZE, luo_session_freeze,\nkernel/liveupdate/luo_session.c-428-\t\t struct liveupdate_session_freeze, reserved, LUO_IOCTL_OUTGOING),\n"
} |
| 31/3 | 2026/10/15 11:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27578 output: 39 thoughts: 56 Thoughts: Here's my summary, as if I were thinking it: **Digging into the Live Update Session Code** Okay, let's dive into `kernel/liveupdate/luo_session.c`. My immediate focus is on how the `ucmd` buffer is constructed and handled, specifically within the 390-460 line range. I need to understand the mechanics of this buffer preparation and passing process. It's key to how user commands are orchestrated during a live update. I need to know the flow to confidently troubleshoot any issues arising here. While I'm at it, I'll also pay close attention to the `_last` variable within the `IOCTL_OP` structure. Understanding the role of `_last` in that context is essential for building a complete picture of the live update process. This might be a critical flag or value. It's too important to skip over. I expect that I'll need this when I start debugging. |
| 32/3 | 2026/10/15 11:57 | tool | read-file |
0mArgs:{
"File": "kernel/liveupdate/luo_session.c",
"FirstLine": 395,
"LineCount": 70
}Results: {
"Contents": " 395:\t\tLUO_IOCTL_OUTGOING,\n 396:\t\tLUO_IOCTL_ALL,\n 397:\t};\n 398:\t\n 399:\tstruct luo_ioctl_op {\n 400:\t\tunsigned int size;\n 401:\t\tunsigned int min_size;\n 402:\t\tunsigned int ioctl_num;\n 403:\t\tenum luo_ioctl_type type;\n 404:\t\tint (*execute)(struct luo_session *session, struct luo_ucmd *ucmd);\n 405:\t};\n 406:\t\n 407:\t#define IOCTL_OP(_ioctl, _fn, _struct, _last, _type) \\\n 408:\t\t[_IOC_NR(_ioctl) - LIVEUPDATE_CMD_SESSION_BASE] = { \\\n 409:\t\t\t.size = sizeof(_struct) + \\\n 410:\t\t\t\tBUILD_BUG_ON_ZERO(sizeof(union ucmd_buffer) \u003c \\\n 411:\t\t\t\t\t\t sizeof(_struct)), \\\n 412:\t\t\t.min_size = offsetofend(_struct, _last), \\\n 413:\t\t\t.ioctl_num = _ioctl, \\\n 414:\t\t\t.type = _type, \\\n 415:\t\t\t.execute = _fn, \\\n 416:\t\t}\n 417:\t\n 418:\tstatic const struct luo_ioctl_op luo_session_ioctl_ops[] = {\n 419:\t\tIOCTL_OP(LIVEUPDATE_SESSION_FINISH, luo_session_finish,\n 420:\t\t\t struct liveupdate_session_finish, reserved, LUO_IOCTL_INCOMING),\n 421:\t\tIOCTL_OP(LIVEUPDATE_SESSION_PRESERVE_FD, luo_session_preserve_fd,\n 422:\t\t\t struct liveupdate_session_preserve_fd, token, LUO_IOCTL_OUTGOING),\n 423:\t\tIOCTL_OP(LIVEUPDATE_SESSION_RETRIEVE_FD, luo_session_retrieve_fd,\n 424:\t\t\t struct liveupdate_session_retrieve_fd, token, LUO_IOCTL_INCOMING),\n 425:\t\tIOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,\n 426:\t\t\t struct liveupdate_session_get_name, name, LUO_IOCTL_ALL),\n 427:\t\tIOCTL_OP(LIVEUPDATE_SESSION_FREEZE, luo_session_freeze,\n 428:\t\t\t struct liveupdate_session_freeze, reserved, LUO_IOCTL_OUTGOING),\n 429:\t};\n 430:\t\n 431:\tstatic bool luo_ioctl_type_valid(struct luo_session *session,\n 432:\t\t\t\t\t const struct luo_ioctl_op *op)\n 433:\t{\n 434:\t\tswitch (op-\u003etype) {\n 435:\t\tcase LUO_IOCTL_INCOMING:\n 436:\t\t\t/* Retrieved is only set on incoming sessions */\n 437:\t\t\treturn session-\u003eretrieved;\n 438:\t\tcase LUO_IOCTL_OUTGOING:\n 439:\t\t\treturn !session-\u003eretrieved;\n 440:\t\tcase LUO_IOCTL_ALL:\n 441:\t\t\treturn true;\n 442:\t\t}\n 443:\t\n 444:\t\t/* Catch-all. */\n 445:\t\treturn false;\n 446:\t}\n 447:\t\n 448:\tstatic long luo_session_ioctl(struct file *filep, unsigned int cmd,\n 449:\t\t\t\t unsigned long arg)\n 450:\t{\n 451:\t\tstruct luo_session *session = filep-\u003eprivate_data;\n 452:\t\tconst struct luo_ioctl_op *op;\n 453:\t\tstruct luo_ucmd ucmd = {};\n 454:\t\tunion ucmd_buffer buf;\n 455:\t\tunsigned int nr;\n 456:\t\tint ret;\n 457:\t\n 458:\t\tnr = _IOC_NR(cmd);\n 459:\t\tif (nr \u003c LIVEUPDATE_CMD_SESSION_BASE || (nr - LIVEUPDATE_CMD_SESSION_BASE) \u003e=\n 460:\t\t ARRAY_SIZE(luo_session_ioctl_ops)) {\n 461:\t\t\treturn -EINVAL;\n 462:\t\t}\n 463:\t\n 464:\t\tucmd.ubuffer = (void __user *)arg;\n"
} |
| 33/3 | 2026/10/15 11:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29066 output: 39 thoughts: 16 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Diving Deeper into `luo_session_ioctl`** Alright, so the call stack has brought us here, down into `luo_session_ioctl`. My initial instinct, based on the function name alone, is that we're dealing with some interface control, likely through an `ioctl` call, specific to a "luo_session". The specific semantics, of course, are what's critical. I need to understand what this `luo_session` abstraction represents within the overall architecture, and what control commands are being passed through this interface. What resources are being manipulated? What data structures are involved? Are there any potential security implications with an `ioctl` handling function? Are there any potential concurrency problems? I will begin to analyze the implementation of `luo_session_ioctl`. |
| 34/3 | 2026/10/15 11:57 | tool | read-file |
0mArgs:{
"File": "kernel/liveupdate/luo_session.c",
"FirstLine": 465,
"LineCount": 50
}Results: {
"Contents": " 465:\t\tret = get_user(ucmd.user_size, (u32 __user *)ucmd.ubuffer);\n 466:\t\tif (ret)\n 467:\t\t\treturn ret;\n 468:\t\n 469:\t\top = \u0026luo_session_ioctl_ops[nr - LIVEUPDATE_CMD_SESSION_BASE];\n 470:\t\tif (op-\u003eioctl_num != cmd)\n 471:\t\t\treturn -ENOIOCTLCMD;\n 472:\t\tif (!luo_ioctl_type_valid(session, op))\n 473:\t\t\treturn -EINVAL;\n 474:\t\tif (ucmd.user_size \u003c op-\u003emin_size)\n 475:\t\t\treturn -EINVAL;\n 476:\t\n 477:\t\tucmd.cmd = \u0026buf;\n 478:\t\tret = copy_struct_from_user(ucmd.cmd, op-\u003esize, ucmd.ubuffer,\n 479:\t\t\t\t\t ucmd.user_size);\n 480:\t\tif (ret)\n 481:\t\t\treturn ret;\n 482:\t\n 483:\t\tguard(rwsem_read)(\u0026luo_session_serialize_rwsem);\n 484:\t\treturn op-\u003eexecute(session, \u0026ucmd);\n 485:\t}\n 486:\t\n 487:\tstatic const struct file_operations luo_session_fops = {\n 488:\t\t.owner = THIS_MODULE,\n 489:\t\t.release = luo_session_release,\n 490:\t\t.unlocked_ioctl = luo_session_ioctl,\n 491:\t};\n 492:\t\n 493:\t/* Create a \"struct file\" for session */\n 494:\tstatic int luo_session_getfile(struct luo_session *session, struct file **filep)\n 495:\t{\n 496:\t\tchar name_buf[128];\n 497:\t\tstruct file *file;\n 498:\t\n 499:\t\tlockdep_assert_held(\u0026session-\u003emutex);\n 500:\t\tsnprintf(name_buf, sizeof(name_buf), \"[luo_session] %s\", session-\u003ename);\n 501:\t\tfile = anon_inode_getfile(name_buf, \u0026luo_session_fops, session, O_RDWR);\n 502:\t\tif (IS_ERR(file))\n 503:\t\t\treturn PTR_ERR(file);\n 504:\t\n 505:\t\t*filep = file;\n 506:\t\n 507:\t\treturn 0;\n 508:\t}\n 509:\t\n 510:\tint luo_session_create(const char *name, struct file **filep)\n 511:\t{\n 512:\t\tsize_t len = strnlen(name, LIVEUPDATE_SESSION_NAME_LENGTH);\n 513:\t\tstruct luo_session *session;\n 514:\t\tint err;\n"
} |
| 35/3 | 2026/10/15 11:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30107 output: 36 thoughts: 118 Thoughts: **Vulnerability Discovered: Potential Stack Buffer Overflow** Okay, so I'm looking at this code and immediately I see a red flag. That `union ucmd_buffer buf;` declared on the stack? Totally uninitialized. That's a classic setup for problems. My mind's racing... I see the next line: `ret = copy_struct_from_user(ucmd.cmd, op->size, ucmd.ubuffer, ucmd.user_size);` Wait a second... `copy_struct_from_user`… that's where things get interesting! I'm thinking, isn't that function's signature `copy_struct_from_user(dst, dst_size, src, src_size)`? If so, the first parameter is the destination and its size, while the second is the source and its size. The way the code's using it, `ucmd.cmd` is the destination, `op->size` is its size, `ucmd.ubuffer` is the source, and `ucmd.user_size` is the size of the user buffer. I need to see what `copy_struct_from_user` *actually* does. It's time to dig into the kernel implementation. My immediate concern is whether or not there is proper bounds checking. If `ucmd.user_size` is larger than `op->size`, we're staring at a potential stack buffer overflow caused by writing past the declared size of the buffer. Gotta verify this is handled correctly within the `copy_struct_from_user` function. This is critical. |
| 36/3 | 2026/10/15 11:57 | tool | grepper |
0mError:no matches Args: {
"Expression": "int copy_struct_from_user",
"PathPrefixes": [
"lib/",
"include/"
]
}Results: {
"error": "no matches"
} |
| 37/3 | 2026/10/15 11:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 30622 output: 22 thoughts: 18 Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person: **Finding `copy_struct_from_user` in the Codebase** Alright, I need to get my hands dirty. I want to understand the full scope of where `copy_struct_from_user` is being utilized within this project. Knowing its usage patterns is critical for understanding potential vulnerabilities related to user input validation, data copying strategies, and security risks. I’m thinking about its implications for memory safety; is it potentially creating a security hole I need to patch? Or perhaps it is being used in a performance-critical area, so how can I better understand the trade-offs in its current implementation? I'm thinking, "Let's find `copy_struct_from_user` across the whole codebase." That's the baseline. I need to be comprehensive, ensuring I don’t miss any instances, no matter how obscure the context. This isn’t about just a grep-and-ignore approach; I need a smart search that considers how the function is used. I'll need to figure out how to filter for the relevant instances; maybe I should begin by looking for usages near sensitive memory locations, or when reading input from untrusted sources. Next, I'll analyze each hit. I’ll be looking for things like: how the input buffer is validated (or isn't), where the destination memory is allocated, and what data is being copied. Is there a clear size check? Are there potential integer overflows or other buffer overflow vulnerabilities? I'll be focused on contextual analysis – not just the function call itself, but also the surrounding code. Ultimately, I want to understand if this is an area of possible concern, or if the current checks and balances are sufficiently robust. From there, I'll be in a position to recommend some improvements. |
| 38/3 | 2026/10/15 11:57 | tool | grepper |
0mArgs:{
"Expression": "copy_struct_from_user\\("
}Results: {
"Output": "\nFull output is too long, showing 200 out of 368 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (39 files in total):\nDocumentation/dev-tools/checkuapi.rst:2\nDocumentation/virt/kvm/api.rst:1\narch/powerpc/kvm/powerpc.c:2\ndrivers/fwctl/main.c:1\ndrivers/gpu/drm/imagination/pvr_drv.c:2\ndrivers/gpu/drm/panthor/panthor_drv.c:2\ndrivers/infiniband/core/ib_core_uverbs.c:1\ndrivers/infiniband/core/uverbs_cmd.c:1\ndrivers/iommu/amd/nested.c:1\ndrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c:1\ndrivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c:1\ndrivers/iommu/intel/nested.c:1\ndrivers/iommu/iommufd/hw_pagetable.c:1\ndrivers/iommu/iommufd/main.c:1\ndrivers/iommu/iommufd/selftest.c:3\ndrivers/platform/surface/surface_aggregator_cdev.c:5\ndrivers/platform/x86/amd/hsmp/hsmp.c:1\ndrivers/vfio/device_cdev.c:1\nfs/file_attr.c:1\nfs/namespace.c:2\nfs/open.c:1\nfs/proc/task_mmu.c:1\nfs/xattr.c:2\ninclude/linux/iommu.h:6\ninclude/linux/sockptr.h:1\ninclude/linux/uaccess.h:3\nio_uring/openclose.c:1\nkernel/events/core.c:1\nkernel/fork.c:1\nkernel/liveupdate/luo_core.c:1\nkernel/liveupdate/luo_file.c:1\nkernel/liveupdate/luo_session.c:1\nkernel/nstree.c:1\nkernel/sched/syscalls.c:1\nkernel/seccomp.c:1\nkernel/trace/rv/monitors/deadline/deadline.h:1\nkernel/trace/trace_events_user.c:2\nlib/tests/usercopy_kunit.c:13\nsecurity/landlock/syscalls.c:2\n\nDocumentation/dev-tools/checkuapi.rst=418=in the ioctl code that the user passed in and then use\nDocumentation/dev-tools/checkuapi.rst:419:``copy_struct_from_user()`` to safely copy the value::\nDocumentation/dev-tools/checkuapi.rst-420-\n--\nDocumentation/dev-tools/checkuapi.rst-426-\nDocumentation/dev-tools/checkuapi.rst:427: ret = copy_struct_from_user(\u0026my_cmd, arg, sizeof(struct foo), _IOC_SIZE(cmd));\nDocumentation/dev-tools/checkuapi.rst-428- ...\n--\nDocumentation/virt/kvm/api.rst=6637=field available for future use without ABI ambiguity.\nDocumentation/virt/kvm/api.rst-6638-\nDocumentation/virt/kvm/api.rst:6639:The ioctl uses ``copy_struct_from_user()`` and ``copy_struct_to_user()``\nDocumentation/virt/kvm/api.rst-6640-to support extensible versioning.\n--\narch/powerpc/kvm/powerpc.c=2388=int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)\n--\narch/powerpc/kvm/powerpc.c-2524-\t\t/*\narch/powerpc/kvm/powerpc.c:2525:\t\t * copy_struct_from_user() handles forward/backward compat:\narch/powerpc/kvm/powerpc.c-2526-\t\t * usize == ksize: verbatim copy\n--\narch/powerpc/kvm/powerpc.c-2529-\t\t */\narch/powerpc/kvm/powerpc.c:2530:\t\tr = copy_struct_from_user(\u0026host_caps, sizeof(host_caps),\narch/powerpc/kvm/powerpc.c-2531-\t\t\t\t\t argp, usize);\n--\ndrivers/fwctl/main.c=168=static long fwctl_fops_ioctl(struct file *filp, unsigned int cmd,\n--\ndrivers/fwctl/main.c-195-\ndrivers/fwctl/main.c:196:\tret = copy_struct_from_user(ucmd.cmd, op-\u003esize, ucmd.ubuffer,\ndrivers/fwctl/main.c-197-\t\t\t\t ucmd.user_size);\n--\ndrivers/gpu/drm/imagination/pvr_drv.c=1169=pvr_get_uobj(u64 usr_ptr, u32 usr_stride, u32 min_stride, u32 obj_size, void *out)\n--\ndrivers/gpu/drm/imagination/pvr_drv.c-1173-\ndrivers/gpu/drm/imagination/pvr_drv.c:1174:\treturn copy_struct_from_user(out, obj_size, u64_to_user_ptr(usr_ptr), usr_stride);\ndrivers/gpu/drm/imagination/pvr_drv.c-1175-}\n--\ndrivers/gpu/drm/imagination/pvr_drv.c=1195=pvr_get_uobj_array(const struct drm_pvr_obj_array *in, u32 min_stride, u32 obj_size, void **out)\n--\ndrivers/gpu/drm/imagination/pvr_drv.c-1218-\t\tfor (u32 i = 0; i \u003c in-\u003ecount; i++) {\ndrivers/gpu/drm/imagination/pvr_drv.c:1219:\t\t\tret = copy_struct_from_user(out_ptr, obj_size, in_ptr, in-\u003estride);\ndrivers/gpu/drm/imagination/pvr_drv.c-1220-\t\t\tif (ret)\n--\ndrivers/gpu/drm/panthor/panthor_drv.c=94=panthor_get_uobj_array(const struct drm_panthor_obj_array *in, u32 min_stride,\n--\ndrivers/gpu/drm/panthor/panthor_drv.c-123-\t\tfor (u32 i = 0; i \u003c in-\u003ecount; i++) {\ndrivers/gpu/drm/panthor/panthor_drv.c:124:\t\t\tret = copy_struct_from_user(out_ptr, obj_size, in_ptr, in-\u003estride);\ndrivers/gpu/drm/panthor/panthor_drv.c-125-\t\t\tif (ret)\n--\ndrivers/gpu/drm/panthor/panthor_drv.c=932=static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct drm_file *file)\n--\ndrivers/gpu/drm/panthor/panthor_drv.c-974-\tcase DRM_PANTHOR_DEV_QUERY_TIMESTAMP_INFO:\ndrivers/gpu/drm/panthor/panthor_drv.c:975:\t\tret = copy_struct_from_user(\u0026timestamp_info,\ndrivers/gpu/drm/panthor/panthor_drv.c-976-\t\t\t\t\t sizeof(timestamp_info),\n--\ndrivers/infiniband/core/ib_core_uverbs.c=434=int _ib_copy_validate_udata_in(struct ib_udata *udata, void *req,\n--\ndrivers/infiniband/core/ib_core_uverbs.c-448-\ndrivers/infiniband/core/ib_core_uverbs.c:449:\terr = copy_struct_from_user(req, kernel_size, udata-\u003einbuf,\ndrivers/infiniband/core/ib_core_uverbs.c-450-\t\t\t\t udata-\u003einlen);\n--\ndrivers/infiniband/core/uverbs_cmd.c=87=static int uverbs_request(struct uverbs_attr_bundle *attrs, void *req,\n--\ndrivers/infiniband/core/uverbs_cmd.c-91-\ndrivers/infiniband/core/uverbs_cmd.c:92:\tret = copy_struct_from_user(req, req_len, attrs-\u003eucore.inbuf,\ndrivers/infiniband/core/uverbs_cmd.c-93-\t\t\t\t attrs-\u003eucore.inlen);\n--\ndrivers/iommu/amd/nested.c=96=amd_iommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,\n--\ndrivers/iommu/amd/nested.c-111-\ndrivers/iommu/amd/nested.c:112:\tret = iommu_copy_struct_from_user(\u0026ndom-\u003egdte, user_data,\ndrivers/iommu/amd/nested.c-113-\t\t\t\t\t IOMMU_HWPT_DATA_AMD_GUEST,\n--\ndrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c=246=arm_vsmmu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,\n--\ndrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c-257-\ndrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c:258:\tret = iommu_copy_struct_from_user(\u0026arg, user_data,\ndrivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c-259-\t\t\t\t\t IOMMU_HWPT_DATA_ARM_SMMUV3, ste);\n--\ndrivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c=1304=tegra241_cmdqv_init_vintf_user(struct arm_vsmmu *vsmmu,\n--\ndrivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c-1323-\ndrivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c:1324:\tret = iommu_copy_struct_from_user(\u0026data, user_data,\ndrivers/iommu/arm/arm-smmu-v3/tegra241-cmdqv.c-1325-\t\t\t\t\t IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV,\n--\ndrivers/iommu/intel/nested.c=196=intel_iommu_domain_alloc_nested(struct device *dev, struct iommu_domain *parent,\n--\ndrivers/iommu/intel/nested.c-215-\ndrivers/iommu/intel/nested.c:216:\tret = iommu_copy_struct_from_user(\u0026vtd, user_data,\ndrivers/iommu/intel/nested.c-217-\t\t\t\t\t IOMMU_HWPT_DATA_VTD_S1, __reserved);\n--\ndrivers/iommu/iommufd/hw_pagetable.c=508=int iommufd_hwpt_invalidate(struct iommufd_ucmd *ucmd)\n--\ndrivers/iommu/iommufd/hw_pagetable.c-527-\t * Bound entry_num and entry_len so a single call cannot pin the CPU;\ndrivers/iommu/iommufd/hw_pagetable.c:528:\t * entry_len also caps the copy_struct_from_user() trailing-zero scan.\ndrivers/iommu/iommufd/hw_pagetable.c-529-\t */\n--\ndrivers/iommu/iommufd/main.c=524=static long iommufd_fops_ioctl(struct file *filp, unsigned int cmd,\n--\ndrivers/iommu/iommufd/main.c-551-\tucmd.cmd = \u0026buf;\ndrivers/iommu/iommufd/main.c:552:\tret = copy_struct_from_user(ucmd.cmd, op-\u003esize, ucmd.ubuffer,\ndrivers/iommu/iommufd/main.c-553-\t\t\t\t ucmd.user_size);\n--\ndrivers/iommu/iommufd/selftest.c=344=__mock_domain_alloc_nested(const struct iommu_user_data *user_data)\n--\ndrivers/iommu/iommufd/selftest.c-352-\ndrivers/iommu/iommufd/selftest.c:353:\trc = iommu_copy_struct_from_user(\u0026user_cfg, user_data,\ndrivers/iommu/iommufd/selftest.c-354-\t\t\t\t\t IOMMU_HWPT_DATA_SELFTEST, iotlb);\n--\ndrivers/iommu/iommufd/selftest.c=492=mock_domain_alloc_paging_flags(struct device *dev, u32 flags,\n--\ndrivers/iommu/iommufd/selftest.c-512-\tif (user_data) {\ndrivers/iommu/iommufd/selftest.c:513:\t\trc = iommu_copy_struct_from_user(\ndrivers/iommu/iommufd/selftest.c-514-\t\t\t\u0026user_cfg, user_data, IOMMU_HWPT_DATA_SELFTEST, iotlb);\n--\ndrivers/iommu/iommufd/selftest.c=793=static int mock_viommu_init(struct iommufd_viommu *viommu,\n--\ndrivers/iommu/iommufd/selftest.c-803-\tif (user_data) {\ndrivers/iommu/iommufd/selftest.c:804:\t\trc = iommu_copy_struct_from_user(\ndrivers/iommu/iommufd/selftest.c-805-\t\t\t\u0026data, user_data, IOMMU_VIOMMU_TYPE_SELFTEST, out_data);\n--\ndrivers/platform/surface/surface_aggregator_cdev.c=255=static long ssam_cdev_request(struct ssam_cdev_client *client, struct ssam_cdev_request __user *r)\n--\ndrivers/platform/surface/surface_aggregator_cdev.c-265-\ndrivers/platform/surface/surface_aggregator_cdev.c:266:\tret = copy_struct_from_user(\u0026rqst, sizeof(rqst), r, sizeof(*r));\ndrivers/platform/surface/surface_aggregator_cdev.c-267-\tif (ret)\n--\ndrivers/platform/surface/surface_aggregator_cdev.c=370=static long ssam_cdev_notif_register(struct ssam_cdev_client *client,\n--\ndrivers/platform/surface/surface_aggregator_cdev.c-377-\ndrivers/platform/surface/surface_aggregator_cdev.c:378:\tret = copy_struct_from_user(\u0026desc, sizeof(desc), d, sizeof(*d));\ndrivers/platform/surface/surface_aggregator_cdev.c-379-\tif (ret)\n--\ndrivers/platform/surface/surface_aggregator_cdev.c=385=static long ssam_cdev_notif_unregister(struct ssam_cdev_client *client,\n--\ndrivers/platform/surface/surface_aggregator_cdev.c-392-\ndrivers/platform/surface/surface_aggregator_cdev.c:393:\tret = copy_struct_from_user(\u0026desc, sizeof(desc), d, sizeof(*d));\ndrivers/platform/surface/surface_aggregator_cdev.c-394-\tif (ret)\n--\ndrivers/platform/surface/surface_aggregator_cdev.c=400=static long ssam_cdev_event_enable(struct ssam_cdev_client *client,\n--\ndrivers/platform/surface/surface_aggregator_cdev.c-410-\t/* Read descriptor from user-space. */\ndrivers/platform/surface/surface_aggregator_cdev.c:411:\tret = copy_struct_from_user(\u0026desc, sizeof(desc), d, sizeof(*d));\ndrivers/platform/surface/surface_aggregator_cdev.c-412-\tif (ret)\n--\ndrivers/platform/surface/surface_aggregator_cdev.c=428=static long ssam_cdev_event_disable(struct ssam_cdev_client *client,\n--\ndrivers/platform/surface/surface_aggregator_cdev.c-438-\t/* Read descriptor from user-space. */\ndrivers/platform/surface/surface_aggregator_cdev.c:439:\tret = copy_struct_from_user(\u0026desc, sizeof(desc), d, sizeof(*d));\ndrivers/platform/surface/surface_aggregator_cdev.c-440-\tif (ret)\n--\ndrivers/platform/x86/amd/hsmp/hsmp.c=353=static long hsmp_ioctl_msg(struct file *fp, unsigned long arg)\n--\ndrivers/platform/x86/amd/hsmp/hsmp.c-358-\ndrivers/platform/x86/amd/hsmp/hsmp.c:359:\tif (copy_struct_from_user(\u0026msg, sizeof(msg), arguser, sizeof(struct hsmp_message)))\ndrivers/platform/x86/amd/hsmp/hsmp.c-360-\t\treturn -EFAULT;\n--\ndrivers/vfio/device_cdev.c=92=long vfio_df_ioctl_bind_iommufd(struct vfio_device_file *df,\n--\ndrivers/vfio/device_cdev.c-110-\t\treturn -EINVAL;\ndrivers/vfio/device_cdev.c:111:\tret = copy_struct_from_user(\u0026bind, sizeof(bind), arg, user_size);\ndrivers/vfio/device_cdev.c-112-\tif (ret)\n--\nfs/file_attr.c=427=SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,\n--\nfs/file_attr.c-451-\nfs/file_attr.c:452:\terror = copy_struct_from_user(\u0026fattr, sizeof(struct file_attr), ufattr,\nfs/file_attr.c-453-\t\t\t\t usize);\n--\nfs/namespace.c=5119=static int wants_mount_setattr(struct mount_attr __user *uattr, size_t usize,\n--\nfs/namespace.c-5134-\nfs/namespace.c:5135:\tret = copy_struct_from_user(\u0026attr, sizeof(attr), uattr, usize);\nfs/namespace.c-5136-\tif (ret)\n--\nfs/namespace.c=5898=static int copy_mnt_id_req(const struct mnt_id_req __user *req,\n--\nfs/namespace.c-5913-\tmemset(kreq, 0, sizeof(*kreq));\nfs/namespace.c:5914:\tret = copy_struct_from_user(kreq, sizeof(*kreq), req, usize);\nfs/namespace.c-5915-\tif (ret)\n--\nfs/open.c=1442=SYSCALL_DEFINE4(openat2, int, dfd, const char __user *, filename,\n--\nfs/open.c-1455-\nfs/open.c:1456:\terr = copy_struct_from_user(\u0026tmp, sizeof(tmp), how, usize);\nfs/open.c-1457-\tif (err)\n--\nfs/proc/task_mmu.c=685=static int do_procmap_query(struct mm_struct *mm, void __user *uarg)\n--\nfs/proc/task_mmu.c-703-\t\treturn -EINVAL;\nfs/proc/task_mmu.c:704:\terr = copy_struct_from_user(\u0026karg, sizeof(karg), uarg, usize);\nfs/proc/task_mmu.c-705-\tif (err)\n--\nfs/xattr.c=740=SYSCALL_DEFINE6(setxattrat, int, dfd, const char __user *, pathname, unsigned int, at_flags,\n--\nfs/xattr.c-754-\nfs/xattr.c:755:\terror = copy_struct_from_user(\u0026args, sizeof(args), uargs, usize);\nfs/xattr.c-756-\tif (error)\n--\nfs/xattr.c=880=SYSCALL_DEFINE6(getxattrat, int, dfd, const char __user *, pathname, unsigned int, at_flags,\n--\nfs/xattr.c-893-\n\n"
} |
| 39/3 | 2026/10/15 11:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36483 output: 36 thoughts: 34 Thoughts: Here's my take on the thought process: **Diving into the Kernel's User-Space Data Copying** Okay, so I need to refresh my memory on `copy_struct_from_user` in the Linux kernel. I'm going to start by taking a look at `include/linux/uaccess.h`. Let's zero in on around line 350. That's usually where the core definitions of those user-space access functions reside, so it's a good starting point to understand exactly how the kernel handles the transfer of a structure's data from a user-space process. This should give me the details I need to reason about memory barriers and potential issues when dealing with concurrency. Knowing the function's internals will also give me a better understanding of potential security implications and best-practice considerations. |
| 40/3 | 2026/10/15 11:57 | tool | grepper |
0mArgs:{
"Expression": "copy_struct_from_user",
"PathPrefixes": [
"include/linux/uaccess.h"
]
}Results: {
"Output": "include/linux/uaccess.h=343=extern __must_check int check_zeroed_user(const void __user *from, size_t size);\n--\ninclude/linux/uaccess.h-345-/**\ninclude/linux/uaccess.h:346: * copy_struct_from_user: copy a struct from userspace\ninclude/linux/uaccess.h-347- * @dst: Destination address, in kernel space. This buffer must be @ksize\n--\ninclude/linux/uaccess.h-371- *\ninclude/linux/uaccess.h:372: * err = copy_struct_from_user(\u0026karg, sizeof(karg), uarg, usize);\ninclude/linux/uaccess.h-373- * if (err)\n--\ninclude/linux/uaccess.h=392=static __always_inline __must_check int\ninclude/linux/uaccess.h:393:copy_struct_from_user(void *dst, size_t ksize, const void __user *src,\ninclude/linux/uaccess.h-394-\t\t size_t usize)\n--\ninclude/linux/uaccess.h=515=__copy_struct_generic_bounce_buffer(void *dst, size_t dstsize,\n--\ninclude/linux/uaccess.h-532-/**\ninclude/linux/uaccess.h:533: * This is like copy_struct_from_user(), but the\ninclude/linux/uaccess.h-534- * src buffer was already copied into a kernel\n"
} |
| 41/3 | 2026/10/15 11:57 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 37127 output: 36 thoughts: 24 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Diving into `uaccess.h` - Addressing the Memory Barrier Concerns** Alright, let's get down to brass tacks. I'm focusing my attention on `include/linux/uaccess.h`, specifically lines 390 through 440. I know this section is crucial for understanding how the kernel safely interacts with user-space memory, and, if my intuition is correct, it has something to do with the memory barriers involved. I want a good, deep refresher. I'm anticipating some critical `barrier()` or `smp_rmb()` and `smp_wmb()` calls nestled in here. I want to see how the kernel mitigates potential race conditions when reading and writing from userspace. I'll be looking to refresh my memory on any subtleties related to cache coherence protocols, especially around the page fault handling. Is there any trickery with prefetching or speculative execution being addressed here, I wonder? I'm hoping I can also see the precise implementation details of how the kernel verifies the user-provided addresses. Maybe even spot some optimizations, or any remaining, lurking, potential vulnerabilities, even if they're theoretical in nature. Let's see how they've handled potential issues around atomicity of access, or if they're relying on compiler intrinsics to ensure things are properly serialized with regards to the CPU's memory model. Let's dig in. |
| 42/3 | 2026/10/15 11:58 | tool | read-file |
0mArgs:{
"File": "include/linux/uaccess.h",
"FirstLine": 392,
"LineCount": 50
}Results: {
"Contents": " 392:\tstatic __always_inline __must_check int\n 393:\tcopy_struct_from_user(void *dst, size_t ksize, const void __user *src,\n 394:\t\t\t size_t usize)\n 395:\t{\n 396:\t\tsize_t size = min(ksize, usize);\n 397:\t\tsize_t rest = max(ksize, usize) - size;\n 398:\t\n 399:\t\t/* Double check if ksize is larger than a known object size. */\n 400:\t\tif (WARN_ON_ONCE(ksize \u003e __builtin_object_size(dst, 1)))\n 401:\t\t\treturn -E2BIG;\n 402:\t\n 403:\t\t/* Deal with trailing bytes. */\n 404:\t\tif (usize \u003c ksize) {\n 405:\t\t\tmemset(dst + size, 0, rest);\n 406:\t\t} else if (usize \u003e ksize) {\n 407:\t\t\tint ret = check_zeroed_user(src + size, rest);\n 408:\t\t\tif (ret \u003c= 0)\n 409:\t\t\t\treturn ret ?: -E2BIG;\n 410:\t\t}\n 411:\t\t/* Copy the interoperable parts of the struct. */\n 412:\t\tif (copy_from_user(dst, src, size))\n 413:\t\t\treturn -EFAULT;\n 414:\t\treturn 0;\n 415:\t}\n 416:\t\n 417:\t/**\n 418:\t * copy_struct_to_user: copy a struct to userspace\n 419:\t * @dst: Destination address, in userspace. This buffer must be @ksize\n 420:\t * bytes long.\n 421:\t * @usize: (Alleged) size of @dst struct.\n 422:\t * @src: Source address, in kernel space.\n 423:\t * @ksize: Size of @src struct.\n 424:\t * @ignored_trailing: Set to %true if there was a non-zero byte in @src that\n 425:\t * userspace cannot see because they are using an smaller struct.\n 426:\t *\n 427:\t * Copies a struct from kernel space to userspace, in a way that guarantees\n 428:\t * backwards-compatibility for struct syscall arguments (as long as future\n 429:\t * struct extensions are made such that all new fields are *appended* to the\n 430:\t * old struct, and zeroed-out new fields have the same meaning as the old\n 431:\t * struct).\n 432:\t *\n 433:\t * Some syscalls may wish to make sure that userspace knows about everything in\n 434:\t * the struct, and if there is a non-zero value that userspce doesn't know\n 435:\t * about, they want to return an error (such as -EMSGSIZE) or have some other\n 436:\t * fallback (such as adding a \"you're missing some information\" flag). If\n 437:\t * @ignored_trailing is non-%NULL, it will be set to %true if there was a\n 438:\t * non-zero byte that could not be copied to userspace (ie. was past @usize).\n 439:\t *\n 440:\t * While unconditionally returning an error in this case is the simplest\n 441:\t * solution, for maximum backward compatibility you should try to only return\n"
} |
| 43/3 | 2026/10/15 11:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38405 output: 36 thoughts: 1556 Thoughts: **Analyzing Potential Uninitialized Memory Access in Live Update Operations** Okay, let's break this down systematically. I'm focusing on potential uninitialized memory reads, particularly related to the `liveupdate` functionality. First, let's look at `luo_session_freeze`. I see that the `luo_session_freeze` function takes a `struct luo_ucmd` and within it calls `luo_ucmd_respond`. I need to understand what `luo_ucmd_respond` does. Okay, `luo_ucmd_respond` copies data back to user space from a kernel command structure, specifically the minimum of what the user provided (`ucmd->user_size`) and the kernel's command size (`kernel_cmd_size`). Now, I need to understand how the command structure (`ucmd`) gets populated. Checking `luo_session_ioctl`, I see that a local stack buffer `buf` (of type `union ucmd_buffer`) is used, and then populated via `copy_struct_from_user`. The size passed to `copy_struct_from_user` is the size of the relevant command structure (e.g., `struct liveupdate_session_freeze`), and the source is the user-provided buffer. If `user_size` is less than `op->size`, then zero-initialization of the tail occurs. So, in the case of `LIVEUPDATE_SESSION_FREEZE`, the relevant structure `struct liveupdate_session_freeze` which has only two `__u32` fields (size, reserved), is copied into `buf` and then `luo_ucmd_respond` copies `min(ucmd->user_size, sizeof(*argp))` back to user space. It appears that the struct has no padding. This seems safe: `buf` is initialized and `luo_ucmd_respond` only copies data that was initialized by `copy_struct_from_user`. Next, I need to check `struct liveupdate_session_preserve_fd` and `struct liveupdate_session_retrieve_fd`. After checking the definitions, I see they contain the fields `size`, `fd`, `token`, and `arg`. I notice a potential issue. The struct does not contain any padding, so the fields immediately follow each other. In `IOCTL_OP` for `PRESERVE_FD` the `min_size` is set to the end of `token`, so, the size will be 16 bytes. If the user only passes a 16-byte buffer, the structure will be initialized up to that point. So, in this case, `arg` becomes 0, and that's fine. `luo_ucmd_respond` only copies back the minimum of the provided and kernel size, so the `arg` is not accidentally copied back to user space uninitialized, because the user provided a small size. Finally, I need to check `luo_session_retrieve_fd`. The retrieved file descriptor is placed into the `argp->fd` field, and copied to user space using `luo_ucmd_respond`, again, the copy is controlled by the minimal of `user_size` and kernel cmd size. So, it appears, after careful analysis, that there is no uninitialized memory copied to userspace. All reads are performed from within structures that are either fully initialized by the kernel using `copy_struct_from_user` or explicitly set. I'll need to double-check `memfd_luo.c` to be certain, though. |
| 44/3 | 2026/10/15 11:58 | tool | grepper |
0mArgs:{
"Expression": "struct memfd_luo_ser",
"PathPrefixes": [
"include/",
"mm/"
]
}Results: {
"Output": "include/linux/kho/abi/memfd.h-22- *\ninclude/linux/kho/abi/memfd.h:23: * The state is serialized into a packed structure `struct memfd_luo_ser`\ninclude/linux/kho/abi/memfd.h-24- * which is handed over to the next kernel via the KHO mechanism.\n--\ninclude/linux/kho/abi/memfd.h=53=struct memfd_luo_folio_ser {\n--\ninclude/linux/kho/abi/memfd.h-81-/**\ninclude/linux/kho/abi/memfd.h:82: * struct memfd_luo_ser - Main serialization structure for a memfd or tmpfs file.\ninclude/linux/kho/abi/memfd.h-83- * @pos: The file's current position (f_pos).\n--\ninclude/linux/kho/abi/memfd.h-91- */\ninclude/linux/kho/abi/memfd.h:92:struct memfd_luo_ser {\ninclude/linux/kho/abi/memfd.h-93-\tu64 pos;\n--\nmm/memfd_luo.c=260=static int memfd_luo_preserve(struct liveupdate_file_op_args *args)\n--\nmm/memfd_luo.c-263-\tstruct memfd_luo_folio_ser *folios_ser;\nmm/memfd_luo.c:264:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-265-\tu64 nr_folios, inode_size;\n--\nmm/memfd_luo.c=328=static int memfd_luo_freeze(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-329-{\nmm/memfd_luo.c:330:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-331-\n--\nmm/memfd_luo.c=346=static void memfd_luo_unpreserve(struct liveupdate_file_op_args *args)\n--\nmm/memfd_luo.c-348-\tstruct inode *inode = file_inode(args-\u003efile);\nmm/memfd_luo.c:349:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-350-\n--\nmm/memfd_luo.c=391=static void memfd_luo_finish(struct liveupdate_file_op_args *args)\n--\nmm/memfd_luo.c-393-\tstruct memfd_luo_folio_ser *folios_ser;\nmm/memfd_luo.c:394:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-395-\n--\nmm/memfd_luo.c=571=static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)\n--\nmm/memfd_luo.c-573-\tstruct memfd_luo_folio_ser *folios_ser;\nmm/memfd_luo.c:574:\tstruct memfd_luo_ser *ser;\nmm/memfd_luo.c-575-\tstruct inode *inode;\n"
} |
| 45/3 | 2026/10/15 11:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 41624 output: 39 thoughts: 28 Thoughts: Okay, here's my interpretation of reading those lines of the `memfd.h` header, summarized as a thought process, keeping in mind my expertise: **Diving into memfd.h: A Closer Look at the ABI** Alright, time to refresh my memory on the kernel's memfd implementation. Let's zero in on `include/linux/kho/abi/memfd.h`, specifically lines 70 to 110. I need to understand how the ABI is handling this. What are the key structures, defines, and enumerations within this section? Given I'm well-versed in system internals, I'm looking for the subtleties, the potential gotchas, and how this relates to my own work on related areas. I'm focusing on the data types and structures, specifically looking at any unusual bitfields, padding or alignment issues that could create problems when transferring memfd's contents in the user space and kernel space. I'll probably pay close attention to the definition of structures which define the data of the memfd that is being shared. Does this section use any of those common macros that are used to hide some part of the memfd that can not be accessed? I want to quickly identify how they work and what impact they're going to have. I want to see if the interface uses any advanced techniques or if it's a straightforward approach. Is there anything here that deviates from best practices? Knowing these details will help me evaluate its efficiency, security, and potential compatibility issues with other parts of the kernel. Overall, I am looking for the essential parts of memfd. |
| 46/3 | 2026/10/15 11:58 | tool | read-file |
0mArgs:{
"File": "include/linux/kho/abi/memfd.h",
"FirstLine": 70,
"LineCount": 40
}Results: {
"Contents": " 70:\t/**\n 71:\t * MEMFD_LUO_FLAG_TMPFS - The preserved file is a tmpfs file.\n 72:\t *\n 73:\t * Indicates the file was preserved from a linked tmpfs file rather than an\n 74:\t * anonymous memfd, and must be retrieved to an empty tmpfs file.\n 75:\t */\n 76:\t#define MEMFD_LUO_FLAG_TMPFS\t\tBIT(0)\n 77:\t\n 78:\t/* The set of flags this version supports preserving. */\n 79:\t#define MEMFD_LUO_ALL_FLAGS\t\tMEMFD_LUO_FLAG_TMPFS\n 80:\t\n 81:\t/**\n 82:\t * struct memfd_luo_ser - Main serialization structure for a memfd or tmpfs file.\n 83:\t * @pos: The file's current position (f_pos).\n 84:\t * @size: The total size of the file in bytes (i_size).\n 85:\t * @seals: The seals present on the memfd. The seals are uABI so it is safe\n 86:\t * to directly use them in the ABI.\n 87:\t * @flags: Flags for the file. Unused flag bits must be set to 0.\n 88:\t * @nr_folios: Number of folios in the folios array.\n 89:\t * @folios: KHO vmalloc descriptor pointing to the array of\n 90:\t * struct memfd_luo_folio_ser.\n 91:\t */\n 92:\tstruct memfd_luo_ser {\n 93:\t\tu64 pos;\n 94:\t\tu64 size;\n 95:\t\tu32 seals;\n 96:\t\tu32 flags;\n 97:\t\tu64 nr_folios;\n 98:\t\tstruct kho_vmalloc folios;\n 99:\t} __packed;\n 100:\t\n 101:\t/* The compatibility string for memfd file handler */\n 102:\t#define MEMFD_LUO_FH_COMPATIBLE\t\"memfd-v2\"\n 103:\t\n 104:\t#endif /* _LINUX_KHO_ABI_MEMFD_H */\n"
} |
| 47/3 | 2026/10/15 11:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42614 output: 37 thoughts: 38 Thoughts: Okay, let's dive into this. Here's how I'd approach this task, as if I were thinking it through: **Analyzing `memfd_luo.c`'s `memfd_luo_preserve` Function** Alright, the objective is to understand the logic around the `memfd_luo_preserve` function, specifically within the `mm/memfd_luo.c` file, and focusing on the code section from roughly lines 260 to 320. This indicates we're likely dealing with some core functionality related to the "LUO" aspect of `memfd`, probably involving preserving some state or preventing something from happening to the memory file. Knowing the file name suggests we're in the memory management subsystem, so I'll be looking for aspects of how the "locking and unlocking objects" relates to `memfd`. I'll be paying close attention to any data structures used within that function. Are there references to file descriptors, vmas, page tables, or anything relevant to shared memory or memory mapping? Is this function involved in preventing an object from being garbage collected in some way? Or perhaps it's related to some sort of lock that needs to be retained when sharing between processes? I expect I'll probably be seeing things related to memory faults or copy-on-write mechanisms, which are relevant in those kinds of scenarios. I expect I'll need to follow the data structures. Is there a reference counter? How does it interact with the lifetime of the memory object? I need to focus on what exactly is being "preserved" and why. Let's see what the code reveals. |
| 48/3 | 2026/10/15 11:58 | tool | read-file |
0mArgs:{
"File": "mm/memfd_luo.c",
"FirstLine": 260,
"LineCount": 55
}Results: {
"Contents": " 260:\tstatic int memfd_luo_preserve(struct liveupdate_file_op_args *args)\n 261:\t{\n 262:\t\tstruct inode *inode = file_inode(args-\u003efile);\n 263:\t\tstruct memfd_luo_folio_ser *folios_ser;\n 264:\t\tstruct memfd_luo_ser *ser;\n 265:\t\tu64 nr_folios, inode_size;\n 266:\t\tint err = 0, seals;\n 267:\t\n 268:\t\tinode_lock(inode);\n 269:\t\tshmem_freeze(inode, true);\n 270:\t\n 271:\t\t/* Allocate the main serialization structure in preserved memory */\n 272:\t\tser = kho_alloc_preserve(sizeof(*ser));\n 273:\t\tif (IS_ERR(ser)) {\n 274:\t\t\terr = PTR_ERR(ser);\n 275:\t\t\tgoto err_unlock;\n 276:\t\t}\n 277:\t\n 278:\t\tseals = memfd_get_seals(args-\u003efile);\n 279:\t\tif (seals \u003c 0) {\n 280:\t\t\terr = seals;\n 281:\t\t\tgoto err_free_ser;\n 282:\t\t}\n 283:\t\n 284:\t\t/* Make sure the file only has the seals supported by this version. */\n 285:\t\tif (seals \u0026 ~MEMFD_LUO_ALL_SEALS) {\n 286:\t\t\terr = -EOPNOTSUPP;\n 287:\t\t\tgoto err_free_ser;\n 288:\t\t}\n 289:\t\n 290:\t\tser-\u003epos = args-\u003efile-\u003ef_pos;\n 291:\t\tinode_size = i_size_read(inode);\n 292:\t\n 293:\t\t/*\n 294:\t\t * memfd_pin_folios() caps at UINT_MAX folios; refuse larger\n 295:\t\t * files to avoid silently preserving only a prefix.\n 296:\t\t */\n 297:\t\tif (DIV_ROUND_UP_ULL(inode_size, PAGE_SIZE) \u003e UINT_MAX) {\n 298:\t\t\terr = -EFBIG;\n 299:\t\t\tgoto err_free_ser;\n 300:\t\t}\n 301:\t\n 302:\t\tser-\u003esize = inode_size;\n 303:\t\tser-\u003eseals = seals;\n 304:\t\tif (inode-\u003ei_nlink)\n 305:\t\t\tser-\u003eflags |= MEMFD_LUO_FLAG_TMPFS;\n 306:\t\n 307:\t\terr = memfd_luo_preserve_folios(args-\u003efile, \u0026ser-\u003efolios,\n 308:\t\t\t\t\t\t\u0026folios_ser, \u0026nr_folios);\n 309:\t\tif (err)\n 310:\t\t\tgoto err_free_ser;\n 311:\t\n 312:\t\tser-\u003enr_folios = nr_folios;\n 313:\t\tinode_unlock(inode);\n 314:\t\n"
} |
| 49/3 | 2026/10/15 11:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 43853 output: 19 thoughts: 162 Thoughts: **Unraveling a Potential Memory Issue** Okay, hold on a second! I need to zero in on this `kho_alloc_preserve(sizeof(*ser))` call within `memfd_luo_preserve`. Something feels off. Does `kho_alloc_preserve` actually initialize the memory it allocates? Or, more specifically, is `ser->flags` potentially holding uninitialized memory at a critical point? Let me look at the code block again: ```c ser = kho_alloc_preserve(sizeof(*ser)); ... ser->size = inode_size; ser->seals = seals; if (inode->i_nlink) ser->flags |= MEMFD_LUO_FLAG_TMPFS; ``` Right, I'm seeing the allocation, but then `ser->flags` is being *or*-ed with a flag later. The key question I need to answer is: what value is in `ser->flags` *before* line 304? This is where the potential issue lies, and I must not assume a zero. Alright, time to get into the details: how exactly is `ser` allocated, and what does `kho_alloc_preserve` actually *do*? I need to understand its memory management behavior. This could be a sneaky uninitialized memory read waiting to bite us! |
| 50/3 | 2026/10/15 11:58 | tool | grepper |
0mArgs:{
"Expression": "kho_alloc_preserve"
}Results: {
"Output": "include/linux/kexec_handover.h=25=void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation);\ninclude/linux/kexec_handover.h:26:void *kho_alloc_preserve(size_t size);\ninclude/linux/kexec_handover.h-27-void kho_unpreserve_free(void *mem);\n--\ninclude/linux/kexec_handover.h=82=static inline void kho_unpreserve_vmalloc(struct kho_vmalloc *preservation) { }\ninclude/linux/kexec_handover.h-83-\ninclude/linux/kexec_handover.h:84:static inline void *kho_alloc_preserve(size_t size)\ninclude/linux/kexec_handover.h-85-{\n--\nkernel/liveupdate/kexec_handover.c=1529=EXPORT_SYMBOL_GPL(kho_restore_vmalloc);\n--\nkernel/liveupdate/kexec_handover.c-1531-/**\nkernel/liveupdate/kexec_handover.c:1532: * kho_alloc_preserve - Allocate, zero, and preserve memory.\nkernel/liveupdate/kexec_handover.c-1533- * @size: The number of bytes to allocate.\n--\nkernel/liveupdate/kexec_handover.c-1544- */\nkernel/liveupdate/kexec_handover.c:1545:void *kho_alloc_preserve(size_t size)\nkernel/liveupdate/kexec_handover.c-1546-{\n--\nkernel/liveupdate/kexec_handover.c-1568-}\nkernel/liveupdate/kexec_handover.c:1569:EXPORT_SYMBOL_GPL(kho_alloc_preserve);\nkernel/liveupdate/kexec_handover.c-1570-\n--\nkernel/liveupdate/kexec_handover.c-1572- * kho_unpreserve_free - Unpreserve and free memory.\nkernel/liveupdate/kexec_handover.c:1573: * @mem: Pointer to the memory allocated by kho_alloc_preserve().\nkernel/liveupdate/kexec_handover.c-1574- *\n--\nkernel/liveupdate/kexec_handover.c-1576- * pages back to the system. This function should be called to clean up\nkernel/liveupdate/kexec_handover.c:1577: * memory allocated with kho_alloc_preserve().\nkernel/liveupdate/kexec_handover.c-1578- */\n--\nkernel/liveupdate/kexec_handover.c=1590=EXPORT_SYMBOL_GPL(kho_unpreserve_free);\n--\nkernel/liveupdate/kexec_handover.c-1598- * to take ownership of and free a memory region that was preserved by the\nkernel/liveupdate/kexec_handover.c:1599: * old kernel using kho_alloc_preserve().\nkernel/liveupdate/kexec_handover.c-1600- *\n--\nkernel/liveupdate/kexec_handover.c=1779=static __init int kho_out_kexec_metadata(void)\n--\nkernel/liveupdate/kexec_handover.c-1783-\nkernel/liveupdate/kexec_handover.c:1784:\tmetadata = kho_alloc_preserve(sizeof(*metadata));\nkernel/liveupdate/kexec_handover.c-1785-\tif (IS_ERR(metadata))\n--\nkernel/liveupdate/kexec_handover.c=1818=static __init int kho_init(void)\n--\nkernel/liveupdate/kexec_handover.c-1830-\nkernel/liveupdate/kexec_handover.c:1831:\tkho_out.fdt = kho_alloc_preserve(PAGE_SIZE);\nkernel/liveupdate/kexec_handover.c-1832-\tif (IS_ERR(kho_out.fdt)) {\n--\nkernel/liveupdate/kho_block.c=73=static struct kho_block_header_ser *kho_block_alloc_ser(struct kho_block_set *bs)\n--\nkernel/liveupdate/kho_block.c-75-\tWARN_ON_ONCE(bs-\u003eincoming);\nkernel/liveupdate/kho_block.c:76:\treturn kho_alloc_preserve(KHO_BLOCK_SIZE);\nkernel/liveupdate/kho_block.c-77-}\n--\nkernel/liveupdate/luo_core.c=154=static int __init luo_state_setup(void)\n--\nkernel/liveupdate/luo_core.c-158-\nkernel/liveupdate/luo_core.c:159:\tluo_ser = kho_alloc_preserve(sizeof(*luo_ser));\nkernel/liveupdate/luo_core.c-160-\tif (IS_ERR(luo_ser)) {\n--\nkernel/liveupdate/luo_flb.c=560=int __init luo_flb_setup_outgoing(u64 *flbs_pa)\n--\nkernel/liveupdate/luo_flb.c-563-\nkernel/liveupdate/luo_flb.c:564:\theader_ser = kho_alloc_preserve(LUO_FLB_PGCNT \u003c\u003c PAGE_SHIFT);\nkernel/liveupdate/luo_flb.c-565-\tif (IS_ERR(header_ser))\n--\nmm/memfd_luo.c=260=static int memfd_luo_preserve(struct liveupdate_file_op_args *args)\n--\nmm/memfd_luo.c-271-\t/* Allocate the main serialization structure in preserved memory */\nmm/memfd_luo.c:272:\tser = kho_alloc_preserve(sizeof(*ser));\nmm/memfd_luo.c-273-\tif (IS_ERR(ser)) {\n"
} |
| 51/3 | 2026/10/15 11:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 45821 output: 41 thoughts: 93 Thoughts: Okay, let's dive into this. **Examining the Memory Allocation in `kexec_handover.c`** Alright, I need to verify something about `kho_alloc_preserve`. I'll start by checking its implementation, specifically within `kernel/liveupdate/kexec_handover.c`. First, I'll refresh my memory and look for the doc comment - just to confirm the core functionality. Ah, there it is: "kho_alloc_preserve - Allocate, zero, and preserve memory." That aligns with what I suspected. Now, to solidify my understanding, I need to review the code itself. Let me take a look at lines 1545 through 1565. Being precise with this is critical; I'll read those lines carefully to confirm the allocation and preservation details. I need to be absolutely sure this is operating as I expect. Okay, let's get to it. |
| 52/3 | 2026/10/15 11:58 | tool | read-file |
0mArgs:{
"File": "kernel/liveupdate/kexec_handover.c",
"FirstLine": 1545,
"LineCount": 25
}Results: {
"Contents": "1545:\tvoid *kho_alloc_preserve(size_t size)\n1546:\t{\n1547:\t\tstruct folio *folio;\n1548:\t\tint order, ret;\n1549:\t\n1550:\t\tif (!size)\n1551:\t\t\treturn ERR_PTR(-EINVAL);\n1552:\t\n1553:\t\torder = get_order(size);\n1554:\t\tif (order \u003e MAX_PAGE_ORDER)\n1555:\t\t\treturn ERR_PTR(-E2BIG);\n1556:\t\n1557:\t\tfolio = folio_alloc(GFP_KERNEL | __GFP_ZERO, order);\n1558:\t\tif (!folio)\n1559:\t\t\treturn ERR_PTR(-ENOMEM);\n1560:\t\n1561:\t\tret = kho_preserve_folio(folio);\n1562:\t\tif (ret) {\n1563:\t\t\tfolio_put(folio);\n1564:\t\t\treturn ERR_PTR(ret);\n1565:\t\t}\n1566:\t\n1567:\t\treturn folio_address(folio);\n1568:\t}\n1569:\tEXPORT_SYMBOL_GPL(kho_alloc_preserve);\n"
} |
| 53/3 | 2026/10/15 11:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 46484 output: 32 thoughts: 1486 Thoughts: **Analyzing the `memfd_luo_retrieve` Function and Locking** Okay, let's break this down. First, I see that `kho_alloc_preserve` uses `__GFP_ZERO`, so the `ser` structure is initialized to zero. That's a good starting point. Now, let's dig into the `memfd_luo_retrieve` function. I observe that if the `MEMFD_LUO_FLAG_TMPFS` flag is set, it calls `memfd_luo_get_tmpfs_file`. Otherwise it is in the other branch. I notice the important difference here is locking. Looking at the logic and the control flow, I see there's a significant change in how the inode is locked. In the old code, `inode_lock` was only taken within `memfd_luo_retrieve_folios`. However, now `inode_lock` is taken earlier. Specifically, if not TMPFS, an inode is locked at line 68, but if there's an error, it will jump to a different path that frees `ser` on line 125, but the inode is still locked. So, it appears that the locking behavior is now more encompassing in the new version. Let me examine the code: - If the "TMPFS" flag is set, the code calls `shmem_truncate_range` and `liveupdate_unclaim_file` *before* `inode_unlock`. This is only called when there is an error during folio restoration and the tmpfs case. - If the "TMPFS" flag is not set, I see a lock, but that is *after* the `memfd_add_seals`. So, in the current implementation, `inode_lock` is held throughout `memfd_luo_retrieve_folios`, `vfs_setpos`, and `i_size_write`. It's unlocked at the end of the function or in the `unclaim_file` path if there's an error. But there were different jumps in the code, which could lead to a race condition. Let me quickly examine `memfd_luo_retrieve_folios` now to be sure of what it's doing. |
| 54/3 | 2026/10/15 11:59 | tool | grepper |
0mArgs:{
"Expression": "memfd_luo_retrieve_folios",
"PathPrefixes": [
"mm/"
]
}Results: {
"Output": "mm/memfd_luo.c=391=static void memfd_luo_finish(struct liveupdate_file_op_args *args)\n--\nmm/memfd_luo.c-420-\nmm/memfd_luo.c:421:static int memfd_luo_retrieve_folios(struct file *file,\nmm/memfd_luo.c-422-\t\t\t\t struct memfd_luo_folio_ser *folios_ser,\n--\nmm/memfd_luo.c=571=static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)\n--\nmm/memfd_luo.c-630-\nmm/memfd_luo.c:631:\t\terr = memfd_luo_retrieve_folios(file, folios_ser, ser-\u003enr_folios);\nmm/memfd_luo.c-632-\t\tvfree(folios_ser);\n"
} |
| 55/3 | 2026/10/15 11:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 48737 output: 37 thoughts: 33 Thoughts: Okay, let's dive into this. Here's how I'd approach understanding `memfd_luo_retrieve_folios` within the context of `mm/memfd_luo.c`. **Diving into `memfd_luo_retrieve_folios`** Alright, my focus is now on `memfd_luo_retrieve_folios`. The line number helps pinpoint its location, giving me a solid starting point for contextual understanding within this file. My intuition suggests this function is central to handling folio retrieval, specifically in the memfd_luo context, which likely is related to large folio based memory management. I anticipate encountering data structures or operations that manage the lifecycle of these folios. My expertise in memory management tells me this likely interacts with other core kernel subsystems, like page allocators or the virtual memory management units. I'll expect to observe the interplay of locking mechanisms, and the consideration of multi-threading concerns. Further, I anticipate this interaction to depend heavily on the specifics of this memfd_luo implementation, meaning I will need to understand the details of this implementation. |
| 56/3 | 2026/10/15 11:59 | tool | read-file |
0mArgs:{
"File": "mm/memfd_luo.c",
"FirstLine": 421,
"LineCount": 45
}Results: {
"Contents": " 421:\tstatic int memfd_luo_retrieve_folios(struct file *file,\n 422:\t\t\t\t\t struct memfd_luo_folio_ser *folios_ser,\n 423:\t\t\t\t\t u64 nr_folios)\n 424:\t{\n 425:\t\tstruct inode *inode = file_inode(file);\n 426:\t\tstruct address_space *mapping = inode-\u003ei_mapping;\n 427:\t\tstruct folio *folio;\n 428:\t\tlong npages, nr_added_pages = 0;\n 429:\t\tint err = -EIO;\n 430:\t\tlong i;\n 431:\t\n 432:\t\tfor (i = 0; i \u003c nr_folios; i++) {\n 433:\t\t\tconst struct memfd_luo_folio_ser *pfolio = \u0026folios_ser[i];\n 434:\t\t\tphys_addr_t phys;\n 435:\t\t\tu64 index;\n 436:\t\t\tint flags;\n 437:\t\n 438:\t\t\tif (!pfolio-\u003epfn)\n 439:\t\t\t\tcontinue;\n 440:\t\n 441:\t\t\tphys = PFN_PHYS(pfolio-\u003epfn);\n 442:\t\t\tfolio = kho_restore_folio(phys);\n 443:\t\t\tif (!folio) {\n 444:\t\t\t\tpr_err(\"Unable to restore folio at physical address: %llx\\n\",\n 445:\t\t\t\t phys);\n 446:\t\t\t\terr = -EIO;\n 447:\t\t\t\tgoto put_folios;\n 448:\t\t\t}\n 449:\t\t\tindex = pfolio-\u003eindex;\n 450:\t\t\tflags = pfolio-\u003eflags;\n 451:\t\n 452:\t\t\t/* Set up the folio for insertion. */\n 453:\t\t\t__folio_set_locked(folio);\n 454:\t\t\t__folio_set_swapbacked(folio);\n 455:\t\n 456:\t\t\terr = mem_cgroup_charge(folio, NULL, mapping_gfp_mask(mapping));\n 457:\t\t\tif (err) {\n 458:\t\t\t\tpr_err(\"shmem: failed to charge folio index %ld: %d\\n\",\n 459:\t\t\t\t i, err);\n 460:\t\t\t\tgoto unlock_folio;\n 461:\t\t\t}\n 462:\t\n 463:\t\t\terr = shmem_add_to_page_cache(folio, mapping, index, NULL,\n 464:\t\t\t\t\t\t mapping_gfp_mask(mapping));\n 465:\t\t\tif (err) {\n"
} |
| 57/3 | 2026/10/15 11:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 49721 output: 37 thoughts: 18 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and delivered as a first-person summary: **Diving Back into `memfd_luo_retrieve_folios`** Alright, so the next logical step is to thoroughly examine the remaining parts of `memfd_luo_retrieve_folios`. We've gotten this far, so a comprehensive review is absolutely essential. I need to make sure I haven't missed any edge cases, off-by-one errors, or potential concurrency issues. Specifically, I'm looking for where we might have missed a spot. Are we handling all the necessary memory management considerations for the retrieved folios? Are there any subtle race conditions that could lead to data corruption or leaks? The implementation of this function is absolutely critical to the system's performance and stability, so every line warrants intense scrutiny. I need to confirm the algorithm is robust. I need to verify assumptions. And I need to triple-check the error handling paths. Let's see if this function is as solid as it needs to be. |
| 58/3 | 2026/10/15 11:59 | tool | read-file |
0mArgs:{
"File": "mm/memfd_luo.c",
"FirstLine": 466,
"LineCount": 55
}Results: {
"Contents": " 466:\t\t\t\tpr_err(\"shmem: failed to add to page cache folio index %ld: %d\\n\",\n 467:\t\t\t\t i, err);\n 468:\t\t\t\tgoto unlock_folio;\n 469:\t\t\t}\n 470:\t\n 471:\t\t\tif (flags \u0026 MEMFD_LUO_FOLIO_UPTODATE)\n 472:\t\t\t\tfolio_mark_uptodate(folio);\n 473:\t\t\tif (flags \u0026 MEMFD_LUO_FOLIO_DIRTY)\n 474:\t\t\t\tfolio_mark_dirty(folio);\n 475:\t\n 476:\t\t\tnpages = folio_nr_pages(folio);\n 477:\t\t\terr = shmem_inode_acct_blocks(inode, npages);\n 478:\t\t\tif (err) {\n 479:\t\t\t\tpr_err(\"shmem: failed to account folio index %ld(%ld pages): %d\\n\",\n 480:\t\t\t\t i, npages, err);\n 481:\t\t\t\tgoto remove_from_cache;\n 482:\t\t\t}\n 483:\t\n 484:\t\t\tnr_added_pages += npages;\n 485:\t\t\tfolio_add_lru(folio);\n 486:\t\t\tfolio_unlock(folio);\n 487:\t\t\tfolio_put(folio);\n 488:\t\t}\n 489:\t\n 490:\t\tshmem_recalc_inode(inode, nr_added_pages, 0);\n 491:\t\n 492:\t\treturn 0;\n 493:\t\n 494:\tremove_from_cache:\n 495:\t\tfilemap_remove_folio(folio);\n 496:\tunlock_folio:\n 497:\t\tfolio_unlock(folio);\n 498:\t\tfolio_put(folio);\n 499:\tput_folios:\n 500:\t\t/*\n 501:\t\t * Note: don't free the folios already added to the file. They will be\n 502:\t\t * freed when the file is freed. Free the ones not added yet here.\n 503:\t\t */\n 504:\t\tfor (long j = i + 1; j \u003c nr_folios; j++) {\n 505:\t\t\tconst struct memfd_luo_folio_ser *pfolio = \u0026folios_ser[j];\n 506:\t\t\tphys_addr_t phys;\n 507:\t\n 508:\t\t\tif (!pfolio-\u003epfn)\n 509:\t\t\t\tcontinue;\n 510:\t\n 511:\t\t\tphys = PFN_PHYS(pfolio-\u003epfn);\n 512:\t\t\tfolio = kho_restore_folio(phys);\n 513:\t\t\tif (folio)\n 514:\t\t\t\tfolio_put(folio);\n 515:\t\t}\n 516:\t\n 517:\t\tshmem_recalc_inode(inode, nr_added_pages, 0);\n 518:\t\n 519:\t\treturn err;\n 520:\t}\n"
} |
| 59/3 | 2026/10/15 11:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 50797 output: 22 thoughts: 3149 Thoughts: **Analysis of Kernel Memory Handling in Live Update Operations** Okay, let's break this down systematically. I've been examining the `luo` (Live Update Operations) code, particularly how it handles user-provided arguments and the potential for uninitialized memory exposure. The core concern is security: are we leaking kernel memory to user space, or are we reading potentially uninitialized kernel memory? First, I looked at `luo_copy_user_arg`. This function copies user data into a kernel buffer (`karg`). My initial worry was that if `user_arg` is zero, then `*argp` isn't set, potentially leaving a dangling pointer. However, the subsequent use of `args.arg` in `luo_preserve_file` and `luo_retrieve_file` *does* initialize it to NULL. So that's safe. It seems to be used as an input struct only. This function takes `user_arg`, gets `user_size`, allocates `karg` with `kmalloc`, copies the content with `copy_struct_from_user` and saves a pointer of it `argp`. Diving into `copy_struct_from_user` and the `uaccess.h` implementation, I verified that `copy_struct_from_user` properly deals with size mismatches between user and kernel buffers. It copies the minimum number of bytes and zero-fills the rest if the kernel buffer (`karg`) is larger than user's (`usize`). Critically, this initialization behavior is key to security. There's also a double-check on ksize to prevent overflows or reads from out-of-bounds, protecting us from potential buffer overflows. Then I considered the usage of the argument (`karg`). `karg` is read by the kernel handler, but the `karg` is *only* read internally, never copied back to user space. It's freed immediately after the kernel handlers return, preventing any memory leaks. It appears to be an input-only argument from user space to the kernel. Next, I turned my attention to the `ioctl` handlers (`LIVEUPDATE_SESSION_PRESERVE_FD` and `LIVEUPDATE_SESSION_RETRIEVE_FD`). I specifically analyzed how the `ucmd` buffer is used. The `ucmd` buffer receives data directly from userspace via `copy_struct_from_user`. Then `luo_ucmd_respond` copies data from this buffer back to the user, after ioctl. In `luo_session_preserve_fd`, `copy_struct_from_user` copies the struct from user space to `ucmd->cmd` (which is a `union ucmd_buffer buf`). `luo_ucmd_respond` copies data from `ucmd->cmd` back to the user space. The size transferred is correctly determined by the `op->size` field, which is the same as the size of the buffer the user passes in. Importantly, the code ensures that `copy_struct_from_user` initializes *all* bytes of the struct. `luo_ucmd_respond` *never* copies data beyond the size of the original buffer provided by the user (which is initialized by `copy_struct_from_user`). Therefore, no uninitialized memory is leaked. `luo_session_freeze` is similar: all bytes copied are initialized. I then carefully reviewed the `ucmd_buffer` union. The union is larger than most of the structures it contains. However, this doesn't create any vulnerability because `copy_struct_from_user` ensures the right size is used. The `luo_ucmd_respond` always copies a maximum of `op->size` bytes back to userspace. Because `copy_struct_from_user` initializes up to `op->size` and `luo_ucmd_respond` only reads/writes the same size (or less), this avoids uninitialized memory leakage. I double-checked `struct liveupdate_session_preserve_fd` and related structures for padding bytes and other potential sources of uninitialized memory. There's *no* padding. The structure members are laid out contiguously, therefore, all bytes are accounted for. The same holds true for `struct liveupdate_memfd_retrieve_arg` and `struct liveupdate_session_freeze` structures. I also looked at `struct memfd_luo_ser` and `liveupdate_file_op_args` as well and determined that there were no uninitialized fields, or that the memory was initialized before usage. In short, my analysis confirms that the Live Update code meticulously handles memory, initializing all buffers that are copied to/from user space and ensuring proper size calculations. It's |
| 60/3 | 2026/10/15 11:59 | tool | grepper |
0mArgs:{
"Expression": "liveupdate_file_op_args"
}Results: {
"Output": "include/linux/liveupdate.h=31=struct liveupdate_arg_spec {\n--\ninclude/linux/liveupdate.h-55-/**\ninclude/linux/liveupdate.h:56: * struct liveupdate_file_op_args - Arguments for file operation callbacks.\ninclude/linux/liveupdate.h-57- * @handler: The file handler being called.\n--\ninclude/linux/liveupdate.h-84- */\ninclude/linux/liveupdate.h:85:struct liveupdate_file_op_args {\ninclude/linux/liveupdate.h-86-\tstruct liveupdate_file_handler *handler;\n--\ninclude/linux/liveupdate.h-119- * All operations (except can_preserve) receive a pointer to a\ninclude/linux/liveupdate.h:120: * 'struct liveupdate_file_op_args' containing the necessary context.\ninclude/linux/liveupdate.h-121- */\ninclude/linux/liveupdate.h=122=struct liveupdate_file_ops {\n--\ninclude/linux/liveupdate.h-124-\t\t\t struct file *file);\ninclude/linux/liveupdate.h:125:\tint (*preserve)(struct liveupdate_file_op_args *args);\ninclude/linux/liveupdate.h:126:\tvoid (*unpreserve)(struct liveupdate_file_op_args *args);\ninclude/linux/liveupdate.h:127:\tint (*freeze)(struct liveupdate_file_op_args *args);\ninclude/linux/liveupdate.h:128:\tvoid (*unfreeze)(struct liveupdate_file_op_args *args);\ninclude/linux/liveupdate.h:129:\tint (*retrieve)(struct liveupdate_file_op_args *args);\ninclude/linux/liveupdate.h:130:\tbool (*can_finish)(struct liveupdate_file_op_args *args);\ninclude/linux/liveupdate.h:131:\tvoid (*finish)(struct liveupdate_file_op_args *args);\ninclude/linux/liveupdate.h-132-\tunsigned long (*get_id)(struct file *file);\n--\nkernel/liveupdate/luo_file.c=300=int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd,\n--\nkernel/liveupdate/luo_file.c-302-{\nkernel/liveupdate/luo_file.c:303:\tstruct liveupdate_file_op_args args = {0};\nkernel/liveupdate/luo_file.c-304-\tstruct liveupdate_file_handler *fh;\n--\nkernel/liveupdate/luo_file.c=411=void luo_file_unpreserve_files(struct luo_file_set *file_set)\n--\nkernel/liveupdate/luo_file.c-415-\twhile (!list_empty(\u0026file_set-\u003efiles_list)) {\nkernel/liveupdate/luo_file.c:416:\t\tstruct liveupdate_file_op_args args = {0};\nkernel/liveupdate/luo_file.c-417-\n--\nkernel/liveupdate/luo_file.c=444=static int luo_file_freeze_one(struct luo_file_set *file_set,\n--\nkernel/liveupdate/luo_file.c-451-\tif (luo_file-\u003efh-\u003eops-\u003efreeze) {\nkernel/liveupdate/luo_file.c:452:\t\tstruct liveupdate_file_op_args args = {0};\nkernel/liveupdate/luo_file.c-453-\n--\nkernel/liveupdate/luo_file.c=467=static void luo_file_unfreeze_one(struct luo_file_set *file_set,\n--\nkernel/liveupdate/luo_file.c-472-\tif (luo_file-\u003efh-\u003eops-\u003eunfreeze) {\nkernel/liveupdate/luo_file.c:473:\t\tstruct liveupdate_file_op_args args = {0};\nkernel/liveupdate/luo_file.c-474-\n--\nkernel/liveupdate/luo_file.c=638=int luo_retrieve_file(struct luo_file_set *file_set, u64 token, u64 arg,\n--\nkernel/liveupdate/luo_file.c-640-{\nkernel/liveupdate/luo_file.c:641:\tstruct liveupdate_file_op_args args = {0};\nkernel/liveupdate/luo_file.c-642-\tstruct luo_file *luo_file;\n--\nkernel/liveupdate/luo_file.c=708=static int luo_file_can_finish_one(struct luo_file_set *file_set,\n--\nkernel/liveupdate/luo_file.c-715-\tif (luo_file-\u003efh-\u003eops-\u003ecan_finish) {\nkernel/liveupdate/luo_file.c:716:\t\tstruct liveupdate_file_op_args args = {0};\nkernel/liveupdate/luo_file.c-717-\n--\nkernel/liveupdate/luo_file.c=728=static void luo_file_finish_one(struct luo_file_set *file_set,\n--\nkernel/liveupdate/luo_file.c-730-{\nkernel/liveupdate/luo_file.c:731:\tstruct liveupdate_file_op_args args = {0};\nkernel/liveupdate/luo_file.c-732-\n--\nmm/memfd_luo.c=233=static void memfd_luo_unpreserve_folios(struct kho_vmalloc *kho_vmalloc,\n--\nmm/memfd_luo.c-259-\nmm/memfd_luo.c:260:static int memfd_luo_preserve(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-261-{\n--\nmm/memfd_luo.c-327-\nmm/memfd_luo.c:328:static int memfd_luo_freeze(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-329-{\n--\nmm/memfd_luo.c-345-\nmm/memfd_luo.c:346:static void memfd_luo_unpreserve(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-347-{\n--\nmm/memfd_luo.c=366=static void memfd_luo_discard_folios(const struct memfd_luo_folio_ser *folios_ser,\n--\nmm/memfd_luo.c-390-\nmm/memfd_luo.c:391:static void memfd_luo_finish(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-392-{\n--\nmm/memfd_luo.c=421=static int memfd_luo_retrieve_folios(struct file *file,\n--\nmm/memfd_luo.c-521-\nmm/memfd_luo.c:522:static struct file *memfd_luo_get_tmpfs_file(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-523-{\n--\nmm/memfd_luo.c-570-\nmm/memfd_luo.c:571:static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)\nmm/memfd_luo.c-572-{\n"
} |
| 61/3 | 2026/10/15 12:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 56942 output: 31 thoughts: 124 Thoughts: **Analyzing Data Structures for Potential Zero-Initialization Issues**
Okay, so I'm looking at this code and immediately I see a pattern I want to investigate. Every instance where `liveupdate_file_op_args` is defined, it's initialized with `= {0}`. That raises a red flag; explicit zero-initialization *usually* points to a concern about uninitialized memory being used elsewhere, or at least a design decision that might impact performance. It suggests that the developer is intentionally ensuring a clean slate.
Now, I'll shift gears and move on to `struct luo_session`. Let's take a look at its definition:
```c
struct luo_session {
char name[LIVEUPDATE_SESSION_NAME_LENGTH];
struct list_head list;
bool retrieved;
bool frozen;
struct luo_file_set file_set;
struct mutex mutex;
};
```
My immediate question is: where is this struct allocated? I need to understand how `luo_session` is handled in memory. To figure that out, I'm going to track down the `luo_session_create` function. This should give me the allocation pattern.
|
| 62/3 | 2026/10/15 12:00 | tool | grepper |
0mArgs:{
"Expression": "luo_session_create",
"PathPrefixes": [
"kernel/liveupdate"
]
}Results: {
"Output": "kernel/liveupdate/luo_core.c=270=static int luo_ioctl_create_session(struct luo_ucmd *ucmd)\n--\nkernel/liveupdate/luo_core.c-279-\nkernel/liveupdate/luo_core.c:280:\terr = luo_session_create(argp-\u003ename, \u0026file);\nkernel/liveupdate/luo_core.c-281-\tif (err)\n--\nkernel/liveupdate/luo_internal.h=81=extern struct rw_semaphore luo_register_rwlock;\nkernel/liveupdate/luo_internal.h-82-\nkernel/liveupdate/luo_internal.h:83:int luo_session_create(const char *name, struct file **filep);\nkernel/liveupdate/luo_internal.h-84-int luo_session_retrieve(const char *name, struct file **filep);\n--\nkernel/liveupdate/luo_session.c-33- *\nkernel/liveupdate/luo_session.c:34: * 1. Creation: A userspace agent calls `luo_session_create()` to create a\nkernel/liveupdate/luo_session.c-35- * new, empty session and receives a file descriptor for it.\n--\nkernel/liveupdate/luo_session.c-61- * - Readers: Taken by any path modifying or accessing session state (e.g.,\nkernel/liveupdate/luo_session.c:62: * `luo_session_create()`, `luo_session_retrieve()`, `luo_session_release()`,\nkernel/liveupdate/luo_session.c-63- * and `luo_session_ioctl()`).\n--\nkernel/liveupdate/luo_session.c=494=static int luo_session_getfile(struct luo_session *session, struct file **filep)\n--\nkernel/liveupdate/luo_session.c-509-\nkernel/liveupdate/luo_session.c:510:int luo_session_create(const char *name, struct file **filep)\nkernel/liveupdate/luo_session.c-511-{\n"
} |
| 63/3 | 2026/10/15 12:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 57915 output: 39 thoughts: 32 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Diving into the `luo_session_create` Function** Alright, let's get down to brass tacks. I need to understand how the Live Update Overwrite (LUO) session is being initialized, particularly focusing on the `luo_session_create` function. I'm targeting line 510 in `kernel/liveupdate/luo_session.c`. My immediate goal is to refresh my understanding of how the framework sets up the new LUO session. I want to scrutinize the allocation, initialization of any data structures, and the overall setup context. I'm expecting some standard allocation patterns, perhaps memory management using slab allocators, and of course, a few mutexes for synchronization. I'm keen to spot any potential race conditions, or performance bottlenecks, the usual suspects in this area. My hope is this code will highlight any changes made to the live update flow over time. Time to see what's changed and what's stayed the same. |
| 64/3 | 2026/10/15 12:00 | tool | read-file |
0mArgs:{
"File": "kernel/liveupdate/luo_session.c",
"FirstLine": 510,
"LineCount": 40
}Results: {
"Contents": " 510:\tint luo_session_create(const char *name, struct file **filep)\n 511:\t{\n 512:\t\tsize_t len = strnlen(name, LIVEUPDATE_SESSION_NAME_LENGTH);\n 513:\t\tstruct luo_session *session;\n 514:\t\tint err;\n 515:\t\n 516:\t\tif (len == 0 || len \u003e LIVEUPDATE_SESSION_NAME_LENGTH - 1)\n 517:\t\t\treturn -EINVAL;\n 518:\t\n 519:\t\tsession = luo_session_alloc(name);\n 520:\t\tif (IS_ERR(session))\n 521:\t\t\treturn PTR_ERR(session);\n 522:\t\n 523:\t\tdown_read(\u0026luo_session_serialize_rwsem);\n 524:\t\terr = luo_session_insert(\u0026luo_session_global.outgoing, session);\n 525:\t\tif (err)\n 526:\t\t\tgoto err_free;\n 527:\t\n 528:\t\tmutex_lock(\u0026session-\u003emutex);\n 529:\t\terr = luo_session_getfile(session, filep);\n 530:\t\tmutex_unlock(\u0026session-\u003emutex);\n 531:\t\tif (err)\n 532:\t\t\tgoto err_remove;\n 533:\t\tup_read(\u0026luo_session_serialize_rwsem);\n 534:\t\n 535:\t\treturn 0;\n 536:\t\n 537:\terr_remove:\n 538:\t\tluo_session_remove(\u0026luo_session_global.outgoing, session);\n 539:\terr_free:\n 540:\t\tluo_session_free(session);\n 541:\t\tup_read(\u0026luo_session_serialize_rwsem);\n 542:\t\n 543:\t\treturn err;\n 544:\t}\n 545:\t\n 546:\tint luo_session_retrieve(const char *name, struct file **filep)\n 547:\t{\n 548:\t\tstruct luo_session_header *sh = \u0026luo_session_global.incoming;\n 549:\t\tstruct luo_session *session = NULL;\n"
} |
| 65/3 | 2026/10/15 12:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 58820 output: 31 thoughts: 12 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience and presented in the first person: **Diving into `luo_session_alloc`** Right, let's get down to brass tacks and take a closer look at `luo_session_alloc`. I need to understand its mechanics, how it behaves, and where it potentially bottlenecks or exposes vulnerabilities. Given the context of what we're working on, this is likely a critical function for managing... well, sessions, obviously! But the *how* is what I need to dig into. I'm wondering if it's thread-safe, how resource allocation is handled internally, and if there are any obvious race conditions that might be lurking. Time to start the deep dive and see what the code actually reveals. I want to look for potential flaws in error handling, and if there are memory leaks. Let's see how well it copes under load, and figure out the exact consequences if it fails. |
| 66/3 | 2026/10/15 12:00 | tool | grepper |
0mArgs:{
"Expression": "luo_session_alloc",
"PathPrefixes": [
"kernel/liveupdate"
]
}Results: {
"Output": "kernel/liveupdate/luo_session.c=135=static struct luo_session_global luo_session_global = {\n--\nkernel/liveupdate/luo_session.c-149-\nkernel/liveupdate/luo_session.c:150:static struct luo_session *luo_session_alloc(const char *name)\nkernel/liveupdate/luo_session.c-151-{\n--\nkernel/liveupdate/luo_session.c=510=int luo_session_create(const char *name, struct file **filep)\n--\nkernel/liveupdate/luo_session.c-518-\nkernel/liveupdate/luo_session.c:519:\tsession = luo_session_alloc(name);\nkernel/liveupdate/luo_session.c-520-\tif (IS_ERR(session))\n--\nkernel/liveupdate/luo_session.c=598=static int luo_session_deserialize_one(struct luo_session_header *sh,\n--\nkernel/liveupdate/luo_session.c-603-\nkernel/liveupdate/luo_session.c:604:\tsession = luo_session_alloc(ser-\u003ename);\nkernel/liveupdate/luo_session.c-605-\tif (IS_ERR(session)) {\n"
} |
| 67/3 | 2026/10/15 12:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 59418 output: 39 thoughts: 26 Thoughts: Okay, here we go... **Diving into `luo_session_alloc`** Right, let's get down to brass tacks. I need to understand this session allocation process in the Live Update context. So, I'm heading straight to `luo_session_alloc` within `kernel/liveupdate/luo_session.c`. This is the core of how these sessions are managed, and it's essential for me to grasp it thoroughly. I'm expecting to see the initialization, any resource constraints being checked, and likely some sort of data structure setup for the session itself. I'll be looking for potential race conditions, locking mechanisms, and the overall logic flow to ensure things are handled robustly, particularly since we're talking about updates to a running kernel. I anticipate seeing allocation of some session-specific context, and figuring out what gets stored there. Let's see what the code reveals. |
| 68/3 | 2026/10/15 12:00 | tool | read-file |
0mArgs:{
"File": "kernel/liveupdate/luo_session.c",
"FirstLine": 150,
"LineCount": 25
}Results: {
"Contents": " 150:\tstatic struct luo_session *luo_session_alloc(const char *name)\n 151:\t{\n 152:\t\tstruct luo_session *session = kzalloc_obj(*session);\n 153:\t\n 154:\t\tif (!session)\n 155:\t\t\treturn ERR_PTR(-ENOMEM);\n 156:\t\n 157:\t\tstrscpy(session-\u003ename, name, sizeof(session-\u003ename));\n 158:\t\tluo_file_set_init(\u0026session-\u003efile_set);\n 159:\t\tINIT_LIST_HEAD(\u0026session-\u003elist);\n 160:\t\tmutex_init(\u0026session-\u003emutex);\n 161:\t\n 162:\t\treturn session;\n 163:\t}\n 164:\t\n 165:\tstatic void luo_session_free(struct luo_session *session)\n 166:\t{\n 167:\t\tluo_file_set_destroy(\u0026session-\u003efile_set);\n 168:\t\tmutex_destroy(\u0026session-\u003emutex);\n 169:\t\tkfree(session);\n 170:\t}\n 171:\t\n 172:\tstatic int luo_session_insert(struct luo_session_header *sh,\n 173:\t\t\t\t struct luo_session *session)\n 174:\t{\n"
} |
| 69/3 | 2026/10/15 12:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 60044 output: 31 thoughts: 658 Thoughts: **Analyzing Potential Uninitialized Data in Kexec Handover** Okay, so `luo_session_alloc` uses `kzalloc_obj(*session)`, meaning `session->frozen` is definitely zero-initialized. Good. Now, I need to check for any potential serialization issues related to kexec, specifically if we are handling uninitialized data or reading uninitialized data. We're talking about KHO (kexec handover) serialization. Let's dive into `luo_file_freeze`. I see a loop iterating through `luo_file` entries in a `file_set`. Inside, `luo_file_freeze_one` is called, and after that, there's a conditional allocation of `file_ser` using `kho_block_set_alloc`. Crucially, `kho_block_set_alloc` utilizes `kho_alloc_preserve`, which zeroes memory thanks to `__GFP_ZERO`. This means `file_ser`'s members should be initialized. The interesting parts are then the assignments to `file_ser->compatible`, `file_ser->serialized_data`, and `file_ser->token`. Now, if `file_set_ser` is populated, the code sets `file_set_ser->count` and `file_set_ser->files`. Moving on to `luo_session_freeze_one`, I see a mutex guard on `session->mutex`. A key point here is the check for `session->frozen`. If it's already frozen, the serialization is straightforward: `file_set_ser.count` and `file_set_ser.files` are populated directly from the session's state. Otherwise, `luo_file_freeze` is called to prepare the serialization. So the question is: How is `ser` allocated in `luo_session_serialize`? I need to check that next. |
| 70/3 | 2026/10/15 12:00 | tool | grepper |
0mArgs:{
"Expression": "luo_session_serialize",
"PathPrefixes": [
"kernel/liveupdate"
]
}Results: {
"Output": "kernel/liveupdate/luo_core.c=220=int liveupdate_reboot(void)\n--\nkernel/liveupdate/luo_core.c-226-\nkernel/liveupdate/luo_core.c:227:\terr = luo_session_serialize();\nkernel/liveupdate/luo_core.c-228-\tif (err)\n--\nkernel/liveupdate/luo_internal.h=86=int __init luo_session_setup_incoming(u64 sessions_pa);\nkernel/liveupdate/luo_internal.h:87:int luo_session_serialize(void);\nkernel/liveupdate/luo_internal.h-88-int luo_session_deserialize(void);\n--\nkernel/liveupdate/luo_session.c-38- * via `LIVEUPDATE_SESSION_FREEZE`. When the `reboot(LINUX_REBOOT_CMD_KEXEC)`\nkernel/liveupdate/luo_session.c:39: * syscall is made, `luo_session_serialize()` is called to freeze any\nkernel/liveupdate/luo_session.c-40- * remaining active sessions and write all session metadata into a memory\n--\nkernel/liveupdate/luo_session.c-56- *\nkernel/liveupdate/luo_session.c:57: * 1. `luo_session_serialize_rwsem` (global rwsem):\nkernel/liveupdate/luo_session.c-58- * Protects session mutations (creation, retrieval, release, and ioctls)\n--\nkernel/liveupdate/luo_session.c-63- * and `luo_session_ioctl()`).\nkernel/liveupdate/luo_session.c:64: * - Writer: Taken by the serialization process (`luo_session_serialize()`)\nkernel/liveupdate/luo_session.c-65- * during reboot. On success, the write lock is held indefinitely to freeze\n--\nkernel/liveupdate/luo_session.c-80- * Lock Hierarchy:\nkernel/liveupdate/luo_session.c:81: * `luo_session_serialize_rwsem` -\u003e `luo_session_header-\u003erwsem` -\u003e `luo_session-\u003emutex`\nkernel/liveupdate/luo_session.c-82- */\n--\nkernel/liveupdate/luo_session.c-103-\nkernel/liveupdate/luo_session.c:104:static DECLARE_RWSEM(luo_session_serialize_rwsem);\nkernel/liveupdate/luo_session.c-105-/**\n--\nkernel/liveupdate/luo_session.c=246=static int luo_session_release(struct inode *inodep, struct file *filep)\n--\nkernel/liveupdate/luo_session.c-250-\nkernel/liveupdate/luo_session.c:251:\tguard(rwsem_read)(\u0026luo_session_serialize_rwsem);\nkernel/liveupdate/luo_session.c-252-\t/* If retrieved is set, it means this session is from incoming list */\n--\nkernel/liveupdate/luo_session.c=448=static long luo_session_ioctl(struct file *filep, unsigned int cmd,\n--\nkernel/liveupdate/luo_session.c-482-\nkernel/liveupdate/luo_session.c:483:\tguard(rwsem_read)(\u0026luo_session_serialize_rwsem);\nkernel/liveupdate/luo_session.c-484-\treturn op-\u003eexecute(session, \u0026ucmd);\n--\nkernel/liveupdate/luo_session.c=510=int luo_session_create(const char *name, struct file **filep)\n--\nkernel/liveupdate/luo_session.c-522-\nkernel/liveupdate/luo_session.c:523:\tdown_read(\u0026luo_session_serialize_rwsem);\nkernel/liveupdate/luo_session.c-524-\terr = luo_session_insert(\u0026luo_session_global.outgoing, session);\n--\nkernel/liveupdate/luo_session.c-532-\t\tgoto err_remove;\nkernel/liveupdate/luo_session.c:533:\tup_read(\u0026luo_session_serialize_rwsem);\nkernel/liveupdate/luo_session.c-534-\n--\nkernel/liveupdate/luo_session.c-540-\tluo_session_free(session);\nkernel/liveupdate/luo_session.c:541:\tup_read(\u0026luo_session_serialize_rwsem);\nkernel/liveupdate/luo_session.c-542-\n--\nkernel/liveupdate/luo_session.c=546=int luo_session_retrieve(const char *name, struct file **filep)\n--\nkernel/liveupdate/luo_session.c-552-\nkernel/liveupdate/luo_session.c:553:\tguard(rwsem_read)(\u0026luo_session_serialize_rwsem);\nkernel/liveupdate/luo_session.c-554-\tguard(rwsem_read)(\u0026sh-\u003erwsem);\n--\nkernel/liveupdate/luo_session.c=632=int luo_session_deserialize(void)\n--\nkernel/liveupdate/luo_session.c-680-\nkernel/liveupdate/luo_session.c:681:int luo_session_serialize(void)\nkernel/liveupdate/luo_session.c-682-{\n--\nkernel/liveupdate/luo_session.c-687-\nkernel/liveupdate/luo_session.c:688:\tdown_write(\u0026luo_session_serialize_rwsem);\nkernel/liveupdate/luo_session.c-689-\tdown_write(\u0026sh-\u003erwsem);\n--\nkernel/liveupdate/luo_session.c-725-\tup_write(\u0026sh-\u003erwsem);\nkernel/liveupdate/luo_session.c:726:\tup_write(\u0026luo_session_serialize_rwsem);\nkernel/liveupdate/luo_session.c-727-\n"
} |
| 71/3 | 2026/10/15 12:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 62686 output: 39 thoughts: 26 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person: **Diving into the Serialization Logic** Right, let's get down to brass tacks. I need to understand the specifics of how session data is serialized during a live update. The code I need to inspect is `luo_session_serialize` in `kernel/liveupdate/luo_session.c`. This is where the rubber meets the road in terms of persisting the running session's state. I need to understand the efficiency of this routine, possible points of failure, what is critical to performance, and if there are any potential race conditions. Is it using a standard serialization library or a custom solution? What compression techniques, if any, are implemented? The goal is to fully grasp the implementation details, how it interacts with the rest of the live update process, and any potential bottlenecks it introduces. I'll need to pay close attention to the data structures involved and the implications of this serialization approach on live update's ability to be fast and reliable. |
| 72/3 | 2026/10/15 12:00 | tool | read-file |
0mArgs:{
"File": "kernel/liveupdate/luo_session.c",
"FirstLine": 681,
"LineCount": 45
}Results: {
"Contents": " 681:\tint luo_session_serialize(void)\n 682:\t{\n 683:\t\tstruct luo_session_header *sh = \u0026luo_session_global.outgoing;\n 684:\t\tstruct luo_session *session;\n 685:\t\tstruct kho_block_set_it it;\n 686:\t\tint err;\n 687:\t\n 688:\t\tdown_write(\u0026luo_session_serialize_rwsem);\n 689:\t\tdown_write(\u0026sh-\u003erwsem);\n 690:\t\t*sh-\u003esessions_pa = 0;\n 691:\t\n 692:\t\tkho_block_set_it_init(\u0026it, \u0026sh-\u003eblock_set);\n 693:\t\n 694:\t\tlist_for_each_entry(session, \u0026sh-\u003elist, list) {\n 695:\t\t\tstruct luo_session_ser *ser = kho_block_set_it_reserve_entry(\u0026it);\n 696:\t\n 697:\t\t\t/* This should not fail normally as blocks were pre-allocated */\n 698:\t\t\tif (WARN_ON_ONCE(!ser)) {\n 699:\t\t\t\terr = -ENOSPC;\n 700:\t\t\t\tgoto err_undo;\n 701:\t\t\t}\n 702:\t\n 703:\t\t\terr = luo_session_freeze_one(session, ser);\n 704:\t\t\tif (err) {\n 705:\t\t\t\tkho_block_set_it_prev(\u0026it);\n 706:\t\t\t\tgoto err_undo;\n 707:\t\t\t}\n 708:\t\n 709:\t\t\tstrscpy(ser-\u003ename, session-\u003ename, sizeof(ser-\u003ename));\n 710:\t\t}\n 711:\t\n 712:\t\tif (sh-\u003ecount \u003e 0)\n 713:\t\t\t*sh-\u003esessions_pa = kho_block_set_head_pa(\u0026sh-\u003eblock_set);\n 714:\t\tup_write(\u0026sh-\u003erwsem);\n 715:\t\n 716:\t\treturn 0;\n 717:\t\n 718:\terr_undo:\n 719:\t\tlist_for_each_entry_continue_reverse(session, \u0026sh-\u003elist, list) {\n 720:\t\t\tstruct luo_session_ser *ser = kho_block_set_it_prev(\u0026it);\n 721:\t\n 722:\t\t\tluo_session_unfreeze_one(session, ser);\n 723:\t\t\tmemset(ser-\u003ename, 0, sizeof(ser-\u003ename));\n 724:\t\t}\n 725:\t\tup_write(\u0026sh-\u003erwsem);\n"
} |
| 73/3 | 2026/10/15 12:00 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 63678 output: 501 thoughts: 2184 Thoughts: **KMSAN Assessment: No Uninitialized Memory Risks Detected**
Alright, let's break this down. My primary concern here is always uninitialized memory reads or information leaks. I've gone through the code with a fine-toothed comb, looking for potential vulnerabilities based on the KMSAN criteria.
First, I examined `kho_block_set_it_reserve_entry` and confirmed that `kho_block_alloc_ser` uses zeroed memory via `kho_alloc_preserve` which uses `__GFP_ZERO`. Good. This avoids a lot of initial potential issues.
Next, I thoroughly reviewed changes in `kernel/liveupdate/luo_file.c`. `liveupdate_claim_file` and `liveupdate_unclaim_file` simply manage an XArray, which, in and of itself, doesn't present an uninitialized memory risk. The real meat is in `luo_copy_user_arg`. Here, user-provided data is copied into `karg` using `copy_struct_from_user`. Crucially, this function *does* proper bounds checking and, importantly, zero-initializes any trailing bytes if the user-supplied size is smaller than the expected size. So, the data passed to handlers *is* fully initialized. The handler (`memfd_luo.c`) just reads the argument, and the memory allocated for the user provided argument is freed after handler returns.
I then followed the flow through `memfd_luo.c`, examining `memfd_luo_get_tmpfs_file` and `memfd_luo_retrieve`. I verified that all relevant structures are handled correctly, with no uninitialized memory accessed. `args->arg` is always fully initialized before use. The file retrieval process, locking, inode checks, and folio restoration all appear sound from an uninitialized memory perspective.
Now, let's apply the KMSAN criteria.
Criterion 1 (Kernel structures to user space): `struct liveupdate_session_preserve_fd`, `liveupdate_session_retrieve_fd` and `liveupdate_session_freeze` are all examined. The data copied back to userspace via `luo_ucmd_respond` is either initialized by `copy_struct_from_user` or is internal, and, therefore, there's no risk of leaking uninitialized data to user space or uninitialized padding. Everything copied is properly accounted for, and `copy_struct_from_user` initializes bytes properly.
Criterion 2 (Conditional logic): In the code, `args`, `session`, `ser`, and `karg` are all initialized with either `= {0}`, `kzalloc_obj`, `kho_alloc_preserve` or `copy_struct_from_user`. All data is always fully initialized when it's accessed.
Criterion 3 (Complex data structures): There are simple structures, but they're either fully initialized, or zeroed.
Criterion 4 (Bounds checks): The `luo_copy_user_arg` function meticulously checks `user_size` against `spec->min_size` and `PAGE_SIZE`, preventing out-of-bounds reads. The use of `copy_struct_from_user` in this context also validates and zeros data properly. Page restoration of folio pages is accounted for.
Therefore, *none* of the KMSAN criteria are met. There's no uninitialized memory being read or leaked to userspace.
What risks *are* present? Well, this is kernel code, so logical errors related to the LUO file retrieval process (claiming/unclaiming, rollback, and locking), potential reference counting issues with `fput`/`fget`, file descriptor management, XArray management, and race conditions/deadlocks are present. I'm also watching out for out-of-bounds or use-after-free bugs. *However*, all of these risks can be detected by KASAN and LOCKDEP. There are no uninitialized memory bugs that KMSAN is uniquely equipped to find.
So, I'm confident that KMSAN is *not* necessary here. KASAN + LOCKDEP will catch all relevant issues, so the tool call will be to indicate that `NeedsKMSAN` should be set to `false`.
|
| 74/3 | 2026/10/15 12:00 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series extends the Live Update Orchestrator (LUO) and memfd/tmpfs preservation mechanism by adding early session freeze support, a user argument passing mechanism for file handlers (with support for preserving/restoring generic linked tmpfs files), and retryable retrieve error handling.\n\nAn evaluation of memory initialization and leak risks shows:\n1. Kernel-to-user copies: The ioctl handlers (LIVEUPDATE_SESSION_PRESERVE_FD, LIVEUPDATE_SESSION_RETRIEVE_FD, LIVEUPDATE_SESSION_FREEZE) use copy_struct_from_user() into the stack buffer and luo_ucmd_respond() to copy back data. The relevant structures (struct liveupdate_session_preserve_fd, struct liveupdate_session_retrieve_fd, struct liveupdate_session_freeze) have naturally aligned 32-bit and 64-bit members with zero padding holes. copy_struct_from_user() explicitly zero-fills any trailing bytes when user-space provides a smaller structure.\n2. Handler arguments: In luo_copy_user_arg(), the kernel buffer is populated via copy_struct_from_user(), ensuring all bytes up to spec-\u003esize are initialized before being passed into handler callbacks.\n3. Heap/KHO allocations: luo_session is allocated with kzalloc_obj(), and the preserved serialization structure struct memfd_luo_ser is allocated using kho_alloc_preserve() which uses __GFP_ZERO. All local liveupdate_file_op_args instances are zero-initialized with '= {0}'.\n4. Folio operations: The restored tmpfs folio handling relies on page cache and KHO folio handover, operating on existing folios without introducing uninitialized reads or uninitialized page exposures.\n\nThe potential issues introduced by this patch involve concurrency, locking order (inode_lock vs session mutex), reference counting (fget/fput, get_file), and resource tracking (xarray insert/erase, unclaim cleanup on failure). These failure modes fall squarely into the domains of KASAN (use-after-free, memory corruption) and LOCKDEP (locking bugs, deadlocks), and do not present uninitialized memory risks. Therefore, a dedicated KMSAN session is not justified.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series extends the Live Update Orchestrator (LUO) and memfd/tmpfs preservation mechanism by adding early session freeze support, a user argument passing mechanism for file handlers (with support for preserving/restoring generic linked tmpfs files), and retryable retrieve error handling.\n\nAn evaluation of memory initialization and leak risks shows:\n1. Kernel-to-user copies: The ioctl handlers (LIVEUPDATE_SESSION_PRESERVE_FD, LIVEUPDATE_SESSION_RETRIEVE_FD, LIVEUPDATE_SESSION_FREEZE) use copy_struct_from_user() into the stack buffer and luo_ucmd_respond() to copy back data. The relevant structures (struct liveupdate_session_preserve_fd, struct liveupdate_session_retrieve_fd, struct liveupdate_session_freeze) have naturally aligned 32-bit and 64-bit members with zero padding holes. copy_struct_from_user() explicitly zero-fills any trailing bytes when user-space provides a smaller structure.\n2. Handler arguments: In luo_copy_user_arg(), the kernel buffer is populated via copy_struct_from_user(), ensuring all bytes up to spec-\u003esize are initialized before being passed into handler callbacks.\n3. Heap/KHO allocations: luo_session is allocated with kzalloc_obj(), and the preserved serialization structure struct memfd_luo_ser is allocated using kho_alloc_preserve() which uses __GFP_ZERO. All local liveupdate_file_op_args instances are zero-initialized with '= {0}'.\n4. Folio operations: The restored tmpfs folio handling relies on page cache and KHO folio handover, operating on existing folios without introducing uninitialized reads or uninitialized page exposures.\n\nThe potential issues introduced by this patch involve concurrency, locking order (inode_lock vs session mutex), reference counting (fget/fput, get_file), and resource tracking (xarray insert/erase, unclaim cleanup on failure). These failure modes fall squarely into the domains of KASAN (use-after-free, memory corruption) and LOCKDEP (locking bugs, deadlocks), and do not present uninitialized memory risks. Therefore, a dedicated KMSAN session is not justified.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|