File livepatch_main.c of Package kernel-livepatch-SLE15_Update_13.15077

/*
 * 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 "bsc1151021/livepatch_bsc1151021.h"
#include "bsc1153108/livepatch_bsc1153108.h"
#include "bsc1153161/livepatch_bsc1153161.h"
#include "bsc1156317/livepatch_bsc1156317.h"
#include "bsc1157770/livepatch_bsc1157770.h"
#include "bsc1159913/livepatch_bsc1159913.h"
#include "bsc1160467/livepatch_bsc1160467.h"
#include "bsc1165631/livepatch_bsc1165631.h"
#include "bsc1171252/livepatch_bsc1171252.h"
#include "bsc1171254/livepatch_bsc1171254.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 = "filldir", .new_func = klpp_filldir, },
			{ .old_name = "filldir64", .new_func = klpp_filldir64, },
			{ .old_name = "tcp_connect", .new_func = klpp_tcp_connect, },
			{ }
		}
	},
	{
		.name = "cfg80211",
		.funcs = (struct klp_func[]) {
			{ .old_name = "cfg80211_mgd_wext_giwessid", .new_func = klpp_cfg80211_mgd_wext_giwessid, },
			{ }
		}
	},
	{
		.name = "geneve",
		.funcs = (struct klp_func[]) {
			{ .old_name = "geneve_get_v6_dst", .new_func = klpp_geneve_get_v6_dst, },
			{ }
		}
	},
	{
		.name = "libertas",
		.funcs = (struct klp_func[]) {
			{ .old_name = "lbs_cfg_connect", .new_func = klpp_lbs_cfg_connect, },
			{ .old_name = "lbs_ibss_join_existing", .new_func = klpp_lbs_ibss_join_existing, },
			{ }
		}
	},
	{
		.name = "mac80211",
		.funcs = (struct klp_func[]) {
			{ .old_name = "ieee80211_add_station", .new_func = klpp_ieee80211_add_station, },
			{ .old_name = "ieee80211_change_station", .new_func = klpp_ieee80211_change_station, },
			{ .old_name = "sta_info_move_state", .new_func = klpp_sta_info_move_state, },
			{ }
		}
	},
	{
		.name = "mwifiex",
		.funcs = (struct klp_func[]) {
#if IS_ENABLED(CONFIG_MWIFIEX)
			{ .old_name = "mwifiex_ret_wmm_get_status", .new_func = klpp_mwifiex_ret_wmm_get_status, },
#endif
			{ .old_name = "mwifiex_cmd_append_vsie_tlv", .new_func = klpp_mwifiex_cmd_append_vsie_tlv, },
			{ .old_name = "mwifiex_cmd_802_11_bg_scan_config", .new_func = klpp_mwifiex_cmd_802_11_bg_scan_config, },
			{ .old_name = "mwifiex_scan_networks", .new_func = klpp_mwifiex_scan_networks, },
			{ }
		}
	},
#if IS_ENABLED(CONFIG_RDMA_RXE)
	{
		.name = "rdma_rxe",
		.funcs = (struct klp_func[]) {
			{ .old_name = "rxe_find_route", .new_func = klpp_rxe_find_route, },
			{ }
		}
	},
#endif
	{
		.name = "tipc",
		.funcs = (struct klp_func[]) {
			{ .old_name = "tipc_udp_send_msg", .new_func = klpp_tipc_udp_send_msg, },
			{ }
		}
	},
	{
		.name = "vhost",
		.funcs = (struct klp_func[]) {
			{ .old_name = "vhost_get_vq_desc", .new_func = klpp_vhost_get_vq_desc, },
			{ }
		}
	},
	{
		.name = "vxlan",
		.funcs = (struct klp_func[]) {
			{ .old_name = "vxlan_xmit_one", .new_func = klpp_vxlan_xmit_one, },
			{ .old_name = "vxlan_fill_metadata_dst", .new_func = klpp_vxlan_fill_metadata_dst, },
			{ }
		}
	},
	{ }
};

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_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;

	retval = livepatch_bsc1156317_init();
	if (retval)
		goto err_bsc1156317;

	retval = livepatch_bsc1157770_init();
	if (retval)
		goto err_bsc1157770;

	retval = livepatch_bsc1159913_init();
	if (retval)
		goto err_bsc1159913;

	retval = livepatch_bsc1160467_init();
	if (retval)
		goto err_bsc1160467;

	retval = livepatch_bsc1165631_init();
	if (retval)
		goto err_bsc1165631;

	retval = livepatch_bsc1171252_init();
	if (retval)
		goto err_bsc1171252;

	retval = livepatch_bsc1171254_init();
	if (retval)
		goto err_bsc1171254;

#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_bsc1171254_cleanup();
err_bsc1171254:
	livepatch_bsc1171252_cleanup();
err_bsc1171252:
	livepatch_bsc1165631_cleanup();
err_bsc1165631:
	livepatch_bsc1160467_cleanup();
err_bsc1160467:
	livepatch_bsc1159913_cleanup();
err_bsc1159913:
	livepatch_bsc1157770_cleanup();
err_bsc1157770:
	livepatch_bsc1156317_cleanup();
err_bsc1156317:
	livepatch_bsc1153161_cleanup();
err_bsc1153161:
	livepatch_bsc1153108_cleanup();
err_bsc1153108:
	livepatch_bsc1151021_cleanup();
err_bsc1151021:

	return retval;
}

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

	/* Auto expanded KLP_PATCHES_CLEANUP_CALLS: */
	livepatch_bsc1151021_cleanup();
	livepatch_bsc1153108_cleanup();
	livepatch_bsc1153161_cleanup();
	livepatch_bsc1156317_cleanup();
	livepatch_bsc1157770_cleanup();
	livepatch_bsc1159913_cleanup();
	livepatch_bsc1160467_cleanup();
	livepatch_bsc1165631_cleanup();
	livepatch_bsc1171252_cleanup();
	livepatch_bsc1171254_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");