File livepatch_main.c of Package kernel-livepatch-SLE15_Update_9.13003

/*
 * livepatch_main.c - kernel live patch main infrastructure
 *
 * Copyright (c) 2014 SUSE
 *  Author: Miroslav Benes <mbenes@suse.cz>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include <linux/livepatch.h>
#include <linux/module.h>
#include <linux/types.h>

#include "uname_patch/livepatch_uname.h"

/* Auto expanded KLP_PATCHES_INCLUDES: */
#include "bsc1133191/livepatch_bsc1133191.h"
#include "bsc1136446/livepatch_bsc1136446.h"
#include "bsc1137597/livepatch_bsc1137597.h"
#include "bsc1151021/livepatch_bsc1151021.h"
#include "bsc1153108/livepatch_bsc1153108.h"
#include "bsc1153161/livepatch_bsc1153161.h"


static struct klp_object objs[] = {
	/* Auto expanded KLP_PATCHES_OBJS: */
	{
		.name = NULL,
		.funcs = (struct klp_func[]) {
			{
			  .old_name = __stringify(KLP_SYSCALL_SYM(newuname)),
			  .new_func = KLP_SYSCALL_SYM(klp_newuname),
			},
#ifdef KLP_ARCH_HAS_SYSCALL_COMPAT_STUBS
			{
			  .old_name = __stringify(KLP_SYSCALL_COMPAT_STUB_SYM(newuname)),
			  .new_func = KLP_SYSCALL_COMPAT_STUB_SYM(klp_newuname),
			},
#endif
			{ .old_name = "follow_page_mask", .new_func = klp_follow_page_mask, },
			{ .old_name = "__get_user_pages", .new_func = klp__get_user_pages, },
#if IS_ENABLED(CONFIG_PPC64)
			{ .old_name = "__get_user_pages_fast", .new_func = klp__get_user_pages_fast, },
#endif
#if IS_ENABLED(CONFIG_X86_64)
			{ .old_name = "gup_pte_range", .new_func = klp_gup_pte_range, },
			{ .old_name = "gup_huge_pmd", .new_func = klp_gup_huge_pmd, },
			{ .old_name = "gup_huge_pud", .new_func = klp_gup_huge_pud, },
#endif
			{ .old_name = "SyS_splice", .new_func = SyS_klp_splice, },
			{ .old_name = "SyS_tee", .new_func = SyS_klp_tee, },
			{ .old_name = "tcp_sacktag_walk", .new_func = klp_tcp_sacktag_walk, },
			{ .old_name = "tcp_fragment", .new_func = klp_tcp_fragment, },
			{ .old_name = "__tcp_retransmit_skb", .new_func = klp__tcp_retransmit_skb, },
			{ .old_name = "filldir", .new_func = klpp_filldir, },
			{ .old_name = "filldir64", .new_func = klpp_filldir64, },
			{ }
		}
	},
	{
		.name = "cfg80211",
		.funcs = (struct klp_func[]) {
			{ .old_name = "cfg80211_mgd_wext_giwessid", .new_func = klpp_cfg80211_mgd_wext_giwessid, },
			{ }
		}
	},
	{
		.name = "fuse",
		.funcs = (struct klp_func[]) {
			{ .old_name = "fuse_dev_splice_write", .new_func = klp_fuse_dev_splice_write, },
			{ }
		}
	},
	{
		.name = "mwifiex",
		.funcs = (struct klp_func[]) {
			{ .old_name = "mwifiex_set_mgmt_ies", .new_func = klp_mwifiex_set_mgmt_ies, },
			{ .old_name = "mwifiex_update_bss_desc_with_ie", .new_func = klp_mwifiex_update_bss_desc_with_ie, },
			{ }
		}
	},
	{
		.name = "vhost",
		.funcs = (struct klp_func[]) {
			{ .old_name = "vhost_get_vq_desc", .new_func = klpp_vhost_get_vq_desc, },
			{ }
		}
	},
	{ }
};

static struct klp_patch patch = {
	.mod = THIS_MODULE,
	.objs = objs,
	.replace = true,
};

static int __init klp_patch_init(void)
{
	int retval;

	pr_info("livepatch: initializing\n");

	retval = klp_patch_uname_init();
	if (retval)
		return retval;

	/* Auto expanded KLP_PATCHES_INIT_CALLS: */
	retval = livepatch_bsc1133191_init();
	if (retval)
		goto err_bsc1133191;

	retval = livepatch_bsc1136446_init();
	if (retval)
		goto err_bsc1136446;

	retval = livepatch_bsc1137597_init();
	if (retval)
		goto err_bsc1137597;

	retval = livepatch_bsc1151021_init();
	if (retval)
		goto err_bsc1151021;

	retval = livepatch_bsc1153108_init();
	if (retval)
		goto err_bsc1153108;

	retval = livepatch_bsc1153161_init();
	if (retval)
		goto err_bsc1153161;

#ifndef KLP_NOREG_API
	retval = klp_register_patch(&patch);
	if (retval)
		goto err_patches_cleanup;
#endif
	retval = klp_enable_patch(&patch);
	if (!retval)
		return retval;

#ifndef KLP_NOREG_API
	WARN_ON(klp_unregister_patch(&patch));
#endif

err_patches_cleanup:
	/* Auto expanded KLP_PATCHES_INIT_ERR_HANDLERS: */
	livepatch_bsc1153161_cleanup();
err_bsc1153161:
	livepatch_bsc1153108_cleanup();
err_bsc1153108:
	livepatch_bsc1151021_cleanup();
err_bsc1151021:
	livepatch_bsc1137597_cleanup();
err_bsc1137597:
	livepatch_bsc1136446_cleanup();
err_bsc1136446:
	livepatch_bsc1133191_cleanup();
err_bsc1133191:

	return retval;
}

static void __exit klp_patch_cleanup(void)
{
	pr_info("livepatch: removed\n");

	/* Auto expanded KLP_PATCHES_CLEANUP_CALLS: */
	livepatch_bsc1133191_cleanup();
	livepatch_bsc1136446_cleanup();
	livepatch_bsc1137597_cleanup();
	livepatch_bsc1151021_cleanup();
	livepatch_bsc1153108_cleanup();
	livepatch_bsc1153161_cleanup();


#ifndef KLP_NOREG_API
	WARN_ON(klp_unregister_patch(&patch));
#endif
}

module_init(klp_patch_init);
module_exit(klp_patch_cleanup);

MODULE_LICENSE("GPL");
MODULE_INFO(livepatch, "Y");