Live-Patching Archive on lore.kernel.org
 help / color / Atom feed
* [bug report] livepatch: Initialize shadow variables safely by a custom callback
@ 2020-01-07 13:29 Dan Carpenter
  2020-01-07 15:06 ` Joe Lawrence
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2020-01-07 13:29 UTC (permalink / raw)
  To: pmladek; +Cc: live-patching

Hello Petr Mladek,

The patch e91c2518a5d2: "livepatch: Initialize shadow variables
safely by a custom callback" from Apr 16, 2018, leads to the
following static checker warning:

	samples/livepatch/livepatch-shadow-fix1.c:86 livepatch_fix1_dummy_alloc()
	error: 'klp_shadow_alloc()' 'leak' too small (4 vs 8)

samples/livepatch/livepatch-shadow-fix1.c
    53  static int shadow_leak_ctor(void *obj, void *shadow_data, void *ctor_data)
    54  {
    55          void **shadow_leak = shadow_data;
    56          void *leak = ctor_data;
    57  
    58          *shadow_leak = leak;
    59          return 0;
    60  }
    61  
    62  static struct dummy *livepatch_fix1_dummy_alloc(void)
    63  {
    64          struct dummy *d;
    65          void *leak;
    66  
    67          d = kzalloc(sizeof(*d), GFP_KERNEL);
    68          if (!d)
    69                  return NULL;
    70  
    71          d->jiffies_expire = jiffies +
    72                  msecs_to_jiffies(1000 * EXPIRE_PERIOD);
    73  
    74          /*
    75           * Patch: save the extra memory location into a SV_LEAK shadow
    76           * variable.  A patched dummy_free routine can later fetch this
    77           * pointer to handle resource release.
    78           */
    79          leak = kzalloc(sizeof(int), GFP_KERNEL);
    80          if (!leak) {
    81                  kfree(d);
    82                  return NULL;
    83          }
    84  
    85          klp_shadow_alloc(d, SV_LEAK, sizeof(leak), GFP_KERNEL,
                                             ^^^^^^^^^^^^
This doesn't seem right at all?  Leak is a pointer.  Why is leak a void
pointer instead of an int pointer?

    86                           shadow_leak_ctor, leak);
    87  
    88          pr_info("%s: dummy @ %p, expires @ %lx\n",
    89                  __func__, d, d->jiffies_expire);
    90  
    91          return d;
    92  }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-07 13:29 [bug report] livepatch: Initialize shadow variables safely by a custom callback Dan Carpenter
2020-01-07 15:06 ` Joe Lawrence
2020-01-07 15:23   ` Dan Carpenter
2020-01-07 15:43     ` Joe Lawrence
2020-01-09  9:29     ` Petr Mladek
2020-01-13 15:11       ` Joe Lawrence

Live-Patching Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/live-patching/0 live-patching/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 live-patching live-patching/ https://lore.kernel.org/live-patching \
		live-patching@vger.kernel.org
	public-inbox-index live-patching

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.live-patching


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git