2014-02-11 20:01:00 +00:00
|
|
|
/*
|
|
|
|
* kpatch.h
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
|
2014-03-13 20:08:08 +00:00
|
|
|
* Copyright (C) 2013-2014 Josh Poimboeuf <jpoimboe@redhat.com>
|
2014-02-11 20:01:00 +00:00
|
|
|
*
|
2014-03-05 03:34:03 +00:00
|
|
|
* 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
|
2014-05-01 17:19:41 +00:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2014-03-05 03:34:03 +00:00
|
|
|
*
|
2014-02-13 16:51:00 +00:00
|
|
|
* Contains the API for the core kpatch module used by the patch modules
|
2014-02-11 20:01:00 +00:00
|
|
|
*/
|
|
|
|
|
2014-02-11 16:25:48 +00:00
|
|
|
#ifndef _KPATCH_H_
|
|
|
|
#define _KPATCH_H_
|
|
|
|
|
2014-06-17 14:51:47 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
enum kpatch_op {
|
|
|
|
KPATCH_OP_NONE,
|
|
|
|
KPATCH_OP_PATCH,
|
|
|
|
KPATCH_OP_UNPATCH,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kpatch_func {
|
|
|
|
/* public */
|
2014-03-14 18:22:59 +00:00
|
|
|
unsigned long new_addr;
|
2014-04-21 16:49:58 +00:00
|
|
|
unsigned long new_size;
|
2014-08-14 16:23:33 +00:00
|
|
|
unsigned long old_addr;
|
2014-03-14 18:22:59 +00:00
|
|
|
unsigned long old_size;
|
2016-11-15 21:02:09 +00:00
|
|
|
unsigned long sympos;
|
2014-06-17 14:51:47 +00:00
|
|
|
const char *name;
|
|
|
|
struct list_head list;
|
2014-07-02 17:35:18 +00:00
|
|
|
int force;
|
2014-06-17 14:51:47 +00:00
|
|
|
|
|
|
|
/* private */
|
|
|
|
struct hlist_node node;
|
|
|
|
enum kpatch_op op;
|
kmod: restructure kpatch sysfs tree
Restructure kpatch's sysfs interface and mirror the sysfs tree after
livepatch's sysfs layout. With the current sysfs layout, we cannot
distinguish which object a function belongs to, and we cannot tell which
modules/objects are patched. Therefore, restructure the kpatch sysfs tree
such that module/object information is available. With the new layout, each
patched object has its own directory, with each function being a
subdirectory of its object.
Implement this by embedding a kobject struct within the kpatch_module,
kpatch_func, and kpatch_object structs and supplying their ktypes and
kobject release methods.
Before:
/sys/kernel/kpatch
└── patches
└── <patch_module>
├── checksum
├── enabled
└── functions
├── <function> # from <object1>
│ ├── new_addr
│ └── old_addr
├── <function> # from <object2>
│ ├── new_addr
│ └── old_addr
└─── <function> # from <object3>
├── new_addr
└── old_addr
After:
/sys/kernel/kpatch
└── <patch_module>
├── <object1>
│ └── <function,sympos>
│ ├── new_addr
│ └── old_addr
├── <object2>
│ └── <function,sympos>
│ ├── new_addr
│ └── old_addr
├── checksum
├── enabled
└── <object3>
└── <function,sympos>
├── new_addr
└── old_addr
2017-02-28 03:17:11 +00:00
|
|
|
struct kobject kobj;
|
2014-02-11 16:25:48 +00:00
|
|
|
};
|
|
|
|
|
2014-05-14 20:59:05 +00:00
|
|
|
struct kpatch_dynrela {
|
|
|
|
unsigned long dest;
|
|
|
|
unsigned long src;
|
|
|
|
unsigned long type;
|
2016-11-15 21:02:09 +00:00
|
|
|
unsigned long sympos;
|
2014-06-17 14:51:47 +00:00
|
|
|
const char *name;
|
2014-05-23 21:36:31 +00:00
|
|
|
int addend;
|
2014-10-04 02:47:35 +00:00
|
|
|
int external;
|
2014-06-17 14:51:47 +00:00
|
|
|
struct list_head list;
|
2014-05-14 20:59:05 +00:00
|
|
|
};
|
|
|
|
|
2014-06-17 14:51:47 +00:00
|
|
|
struct kpatch_object {
|
|
|
|
struct list_head list;
|
|
|
|
const char *name;
|
|
|
|
struct list_head funcs;
|
|
|
|
struct list_head dynrelas;
|
2018-01-04 19:13:19 +00:00
|
|
|
|
|
|
|
int (*pre_patch_callback)(struct kpatch_object *);
|
|
|
|
void (*post_patch_callback)(struct kpatch_object *);
|
|
|
|
void (*pre_unpatch_callback)(struct kpatch_object *);
|
|
|
|
void (*post_unpatch_callback)(struct kpatch_object *);
|
|
|
|
bool callbacks_enabled;
|
2014-05-12 19:36:10 +00:00
|
|
|
|
2014-06-17 14:51:47 +00:00
|
|
|
/* private */
|
|
|
|
struct module *mod;
|
kmod: restructure kpatch sysfs tree
Restructure kpatch's sysfs interface and mirror the sysfs tree after
livepatch's sysfs layout. With the current sysfs layout, we cannot
distinguish which object a function belongs to, and we cannot tell which
modules/objects are patched. Therefore, restructure the kpatch sysfs tree
such that module/object information is available. With the new layout, each
patched object has its own directory, with each function being a
subdirectory of its object.
Implement this by embedding a kobject struct within the kpatch_module,
kpatch_func, and kpatch_object structs and supplying their ktypes and
kobject release methods.
Before:
/sys/kernel/kpatch
└── patches
└── <patch_module>
├── checksum
├── enabled
└── functions
├── <function> # from <object1>
│ ├── new_addr
│ └── old_addr
├── <function> # from <object2>
│ ├── new_addr
│ └── old_addr
└─── <function> # from <object3>
├── new_addr
└── old_addr
After:
/sys/kernel/kpatch
└── <patch_module>
├── <object1>
│ └── <function,sympos>
│ ├── new_addr
│ └── old_addr
├── <object2>
│ └── <function,sympos>
│ ├── new_addr
│ └── old_addr
├── checksum
├── enabled
└── <object3>
└── <function,sympos>
├── new_addr
└── old_addr
2017-02-28 03:17:11 +00:00
|
|
|
struct kobject kobj;
|
2014-06-17 14:51:47 +00:00
|
|
|
};
|
2014-05-12 19:36:10 +00:00
|
|
|
|
2014-04-21 16:29:01 +00:00
|
|
|
struct kpatch_module {
|
2014-06-10 17:02:34 +00:00
|
|
|
/* public */
|
2014-04-21 16:29:01 +00:00
|
|
|
struct module *mod;
|
2014-06-17 14:51:47 +00:00
|
|
|
struct list_head objects;
|
|
|
|
|
|
|
|
/* public read-only */
|
2014-04-26 04:05:26 +00:00
|
|
|
bool enabled;
|
2014-06-10 17:02:34 +00:00
|
|
|
|
|
|
|
/* private */
|
2014-06-10 17:28:40 +00:00
|
|
|
struct list_head list;
|
kmod: restructure kpatch sysfs tree
Restructure kpatch's sysfs interface and mirror the sysfs tree after
livepatch's sysfs layout. With the current sysfs layout, we cannot
distinguish which object a function belongs to, and we cannot tell which
modules/objects are patched. Therefore, restructure the kpatch sysfs tree
such that module/object information is available. With the new layout, each
patched object has its own directory, with each function being a
subdirectory of its object.
Implement this by embedding a kobject struct within the kpatch_module,
kpatch_func, and kpatch_object structs and supplying their ktypes and
kobject release methods.
Before:
/sys/kernel/kpatch
└── patches
└── <patch_module>
├── checksum
├── enabled
└── functions
├── <function> # from <object1>
│ ├── new_addr
│ └── old_addr
├── <function> # from <object2>
│ ├── new_addr
│ └── old_addr
└─── <function> # from <object3>
├── new_addr
└── old_addr
After:
/sys/kernel/kpatch
└── <patch_module>
├── <object1>
│ └── <function,sympos>
│ ├── new_addr
│ └── old_addr
├── <object2>
│ └── <function,sympos>
│ ├── new_addr
│ └── old_addr
├── checksum
├── enabled
└── <object3>
└── <function,sympos>
├── new_addr
└── old_addr
2017-02-28 03:17:11 +00:00
|
|
|
struct kobject kobj;
|
2014-04-21 16:29:01 +00:00
|
|
|
};
|
|
|
|
|
kmod: restructure kpatch sysfs tree
Restructure kpatch's sysfs interface and mirror the sysfs tree after
livepatch's sysfs layout. With the current sysfs layout, we cannot
distinguish which object a function belongs to, and we cannot tell which
modules/objects are patched. Therefore, restructure the kpatch sysfs tree
such that module/object information is available. With the new layout, each
patched object has its own directory, with each function being a
subdirectory of its object.
Implement this by embedding a kobject struct within the kpatch_module,
kpatch_func, and kpatch_object structs and supplying their ktypes and
kobject release methods.
Before:
/sys/kernel/kpatch
└── patches
└── <patch_module>
├── checksum
├── enabled
└── functions
├── <function> # from <object1>
│ ├── new_addr
│ └── old_addr
├── <function> # from <object2>
│ ├── new_addr
│ └── old_addr
└─── <function> # from <object3>
├── new_addr
└── old_addr
After:
/sys/kernel/kpatch
└── <patch_module>
├── <object1>
│ └── <function,sympos>
│ ├── new_addr
│ └── old_addr
├── <object2>
│ └── <function,sympos>
│ ├── new_addr
│ └── old_addr
├── checksum
├── enabled
└── <object3>
└── <function,sympos>
├── new_addr
└── old_addr
2017-02-28 03:17:11 +00:00
|
|
|
extern struct kobject *kpatch_root_kobj;
|
2014-04-26 04:05:26 +00:00
|
|
|
|
2014-04-28 21:18:29 +00:00
|
|
|
extern int kpatch_register(struct kpatch_module *kpmod, bool replace);
|
2014-04-21 16:29:01 +00:00
|
|
|
extern int kpatch_unregister(struct kpatch_module *kpmod);
|
2014-02-11 16:25:48 +00:00
|
|
|
|
2014-08-29 16:27:33 +00:00
|
|
|
extern void *kpatch_shadow_alloc(void *obj, char *var, size_t size, gfp_t gfp);
|
|
|
|
extern void kpatch_shadow_free(void *obj, char *var);
|
|
|
|
extern void *kpatch_shadow_get(void *obj, char *var);
|
|
|
|
|
2014-02-11 16:25:48 +00:00
|
|
|
#endif /* _KPATCH_H_ */
|