1. 04 Jan, 2022 1 commit
    • David Vernet's avatar
      livepatch: Fix kobject refcount bug on klp_init_patch_early failure path · 5ef3dd20
      David Vernet authored
      When enabling a klp patch with klp_enable_patch(), klp_init_patch_early()
      is invoked to initialize the kobjects for the patch itself, as well as the
      'struct klp_object' and 'struct klp_func' objects that comprise it.
      However, there are some error paths in klp_enable_patch() where some
      kobjects may have been initialized with kobject_init(), but an error code
      is still returned due to e.g. a 'struct klp_object' having a NULL funcs
      pointer.
      
      In these paths, the initial reference of the kobject of the 'struct
      klp_patch' may never be released, along with one or more of its objects and
      their functions, as kobject_put() is not invoked on the cleanup path if
      klp_init_patch_early() returns an error code.
      
      For example, if an object entry such as the following were added to the
      sample livepatch module's klp patch, it would cause the vmlinux klp_object,
      and its klp_func which updates 'cmdline_proc_show', to never be released:
      
      static struct klp_object objs[] = {
      	{
      		/* name being NULL means vmlinux */
      		.funcs = funcs,
      	},
      	{
      		/* NULL funcs -- would cause reference leak */
      		.name = "kvm",
      	}, { }
      };
      
      Without this change, if CONFIG_DEBUG_KOBJECT is enabled, and the sample klp
      patch is loaded, the kobjects (the patch, the vmlinux 'struct klp_object',
      and its func) are observed as initialized, but never released, in the dmesg
      log output.  With the change, these kobject references no longer fail to be
      released as the error case is properly handled before they are initialized.
      Signed-off-by: default avatarDavid Vernet <void@manifault.com>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Acked-by: default avatarMiroslav Benes <mbenes@suse.cz>
      Acked-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
      5ef3dd20
  2. 23 Dec, 2021 1 commit
    • David Vernet's avatar
      Documentation: livepatch: Add livepatch API page · e368cd72
      David Vernet authored
      The livepatch subsystem has several exported functions and objects with
      kerneldoc comments. Though the livepatch documentation contains handwritten
      descriptions of all of these exported functions, they are currently not
      pulled into the docs build using the kernel-doc directive.
      
      In order to allow readers of the documentation to see the full kerneldoc
      comments in the generated documentation files, this change adds a new
      Documentation/livepatch/api.rst page which contains kernel-doc directives
      to link the kerneldoc comments directly in the documentation.  With this,
      all of the hand-written descriptions of the APIs now cross-reference the
      kerneldoc comments on the new Livepatching APIs page, and running
      ./scripts/find-unused-docs.sh on kernel/livepatch no longer shows any files
      as missing documentation.
      
      Note that all of the handwritten API descriptions were left alone with the
      exception of Documentation/livepatch/system-state.rst, which was updated to
      allow the cross-referencing to work correctly. The file now follows the
      cross-referencing formatting guidance specified in
      Documentation/doc-guide/kernel-doc.rst. Furthermore, some comments around
      klp_shadow_free_all() were updated to say <_, id> rather than <*, id> to
      match the rest of the file, and to prevent the docs build from emitting an
      "Inline emphasis start-string without end string" error.
      Signed-off-by: default avatarDavid Vernet <void@manifault.com>
      Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
      Acked-by: default avatarMiroslav Benes <mbenes@suse.cz>
      Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
      Link: https://lore.kernel.org/r/20211221145743.4098360-1-void@manifault.com
      e368cd72
  3. 03 Sep, 2021 38 commits