Skip to content

Commit

Permalink
livepatch/sample: Use the right type for the leaking data pointer
Browse files Browse the repository at this point in the history
The "leak" pointer, in the sample of shadow variable API, is allocated
as sizeof(int). Let's help developers and static analyzers with
understanding the code by using the appropriate pointer type.

Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Petr Mladek <[email protected]>
Reviewed-by: Joe Lawrence <[email protected]>
Acked-by: Miroslav Benes <[email protected]>
Reviewed-by: Kamalesh Babulal <[email protected]>
Signed-off-by: Jiri Kosina <[email protected]>
  • Loading branch information
pmladek authored and Jiri Kosina committed Jan 17, 2020
1 parent f838767 commit 8f6b886
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions samples/livepatch/livepatch-shadow-fix1.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ struct dummy {
*/
static int shadow_leak_ctor(void *obj, void *shadow_data, void *ctor_data)
{
void **shadow_leak = shadow_data;
void *leak = ctor_data;
int **shadow_leak = shadow_data;
int *leak = ctor_data;

*shadow_leak = leak;
return 0;
Expand All @@ -62,7 +62,7 @@ static int shadow_leak_ctor(void *obj, void *shadow_data, void *ctor_data)
static struct dummy *livepatch_fix1_dummy_alloc(void)
{
struct dummy *d;
void *leak;
int *leak;

d = kzalloc(sizeof(*d), GFP_KERNEL);
if (!d)
Expand All @@ -76,7 +76,7 @@ static struct dummy *livepatch_fix1_dummy_alloc(void)
* variable. A patched dummy_free routine can later fetch this
* pointer to handle resource release.
*/
leak = kzalloc(sizeof(int), GFP_KERNEL);
leak = kzalloc(sizeof(*leak), GFP_KERNEL);
if (!leak) {
kfree(d);
return NULL;
Expand All @@ -94,7 +94,7 @@ static struct dummy *livepatch_fix1_dummy_alloc(void)
static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
{
void *d = obj;
void **shadow_leak = shadow_data;
int **shadow_leak = shadow_data;

kfree(*shadow_leak);
pr_info("%s: dummy @ %p, prevented leak @ %p\n",
Expand All @@ -103,7 +103,7 @@ static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)

static void livepatch_fix1_dummy_free(struct dummy *d)
{
void **shadow_leak;
int **shadow_leak;

/*
* Patch: fetch the saved SV_LEAK shadow variable, detach and
Expand Down
4 changes: 2 additions & 2 deletions samples/livepatch/livepatch-shadow-fix2.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static bool livepatch_fix2_dummy_check(struct dummy *d, unsigned long jiffies)
static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)
{
void *d = obj;
void **shadow_leak = shadow_data;
int **shadow_leak = shadow_data;

kfree(*shadow_leak);
pr_info("%s: dummy @ %p, prevented leak @ %p\n",
Expand All @@ -68,7 +68,7 @@ static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)

static void livepatch_fix2_dummy_free(struct dummy *d)
{
void **shadow_leak;
int **shadow_leak;
int *shadow_count;

/* Patch: copy the memory leak patch from the fix1 module. */
Expand Down
4 changes: 2 additions & 2 deletions samples/livepatch/livepatch-shadow-mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct dummy {
static __used noinline struct dummy *dummy_alloc(void)
{
struct dummy *d;
void *leak;
int *leak;

d = kzalloc(sizeof(*d), GFP_KERNEL);
if (!d)
Expand All @@ -105,7 +105,7 @@ static __used noinline struct dummy *dummy_alloc(void)
msecs_to_jiffies(1000 * EXPIRE_PERIOD);

/* Oops, forgot to save leak! */
leak = kzalloc(sizeof(int), GFP_KERNEL);
leak = kzalloc(sizeof(*leak), GFP_KERNEL);
if (!leak) {
kfree(d);
return NULL;
Expand Down

0 comments on commit 8f6b886

Please sign in to comment.