mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Lawrence <joe.lawrence@redhat.com>
To: Petr Mladek <pmladek@suse.com>, Jiri Kosina <jikos@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Miroslav Benes <mbenes@suse.cz>
Cc: Jason Baron <jbaron@akamai.com>,
	Evgenii Shatokhin <eshatokhin@virtuozzo.com>,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/4] livepatch: Proper error handling in the shadow variables selftest
Date: Tue, 5 Feb 2019 16:17:13 -0500	[thread overview]
Message-ID: <6c313c97-fd7b-8ab6-446f-6dac4c34a30c@redhat.com> (raw)
In-Reply-To: <20190204135653.31406-4-pmladek@suse.com>

On 2/4/19 8:56 AM, Petr Mladek wrote:
> Add proper error handling when allocating or getting shadow variables
> in the selftest. It prevents an invalid pointer access in some situations.
> It shows the good programming practice in the others.
> 
> The error codes are just the best guess and specific for this particular
> test. In general, klp_shadow_alloc() returns NULL also when the given
> shadow variable has already been allocated. In addition, both
> klp_shadow_alloc() and klp_shadow_get_or_alloc() might fail from
> other reasons when the constructor fails.
> 
> Note, that the error code is not really important even in the real life.
> The use of shadow variables should be transparent for the original
> livepatched code.
> 
> Signed-off-by: Petr Mladek <pmladek@suse.com>
> ---
>   lib/livepatch/test_klp_shadow_vars.c | 22 ++++++++++++++++++++++
>   1 file changed, 22 insertions(+)
> 
> diff --git a/lib/livepatch/test_klp_shadow_vars.c b/lib/livepatch/test_klp_shadow_vars.c
> index f5441c193166..fe5c413efe96 100644
> --- a/lib/livepatch/test_klp_shadow_vars.c
> +++ b/lib/livepatch/test_klp_shadow_vars.c
> @@ -154,22 +154,37 @@ static int test_klp_shadow_vars_init(void)
>   	 * Allocate a few shadow variables with different <obj> and <id>.
>   	 */
>   	sv1 = shadow_alloc(obj, id, size, gfp_flags, shadow_ctor, &var1);
> +	if (!sv1)
> +		return -ENOMEM;
> +
>   	sv2 = shadow_alloc(obj + 1, id, size, gfp_flags, shadow_ctor, &var2);
> +	if (!sv2)
> +		return -ENOMEM;
> +
>   	sv3 = shadow_alloc(obj, id + 1, size, gfp_flags, shadow_ctor, &var3);
> +	if (!sv3)
> +		return -ENOMEM;
>   
>   	/*
>   	 * Verify we can find our new shadow variables and that they point
>   	 * to expected data.
>   	 */
>   	ret = shadow_get(obj, id);
> +	if (!ret)
> +		return -EINVAL;
>   	if (ret == sv1 && *sv1 == &var1)
>   		pr_info("  got expected PTR%d -> PTR%d result\n",
>   			ptr_id(sv1), ptr_id(*sv1));
> +
>   	ret = shadow_get(obj + 1, id);
> +	if (!ret)
> +		return -EINVAL;
>   	if (ret == sv2 && *sv2 == &var2)
>   		pr_info("  got expected PTR%d -> PTR%d result\n",
>   			ptr_id(sv2), ptr_id(*sv2));
>   	ret = shadow_get(obj, id + 1);
> +	if (!ret)
> +		return -EINVAL;
>   	if (ret == sv3 && *sv3 == &var3)
>   		pr_info("  got expected PTR%d -> PTR%d result\n",
>   			ptr_id(sv3), ptr_id(*sv3));
> @@ -179,7 +194,12 @@ static int test_klp_shadow_vars_init(void)
>   	 * The second invocation should return the same shadow var.
>   	 */
>   	sv4 = shadow_get_or_alloc(obj + 2, id, size, gfp_flags, shadow_ctor, &var4);
> +	if (!sv4)
> +		return -ENOMEM;
> +
>   	ret = shadow_get_or_alloc(obj + 2, id, size, gfp_flags, shadow_ctor, &var4);
> +	if (!ret)
> +		return -EINVAL;
>   	if (ret == sv4 && *sv4 == &var4)
>   		pr_info("  got expected PTR%d -> PTR%d result\n",
>   			ptr_id(sv4), ptr_id(*sv4));
> @@ -207,6 +227,8 @@ static int test_klp_shadow_vars_init(void)
>   	 * We should still find an <id+1> variable.
>   	 */
>   	ret = shadow_get(obj, id + 1);
> +	if (!ret)
> +		return -EINVAL;
>   	if (ret == sv3 && *sv3 == &var3)
>   		pr_info("  got expected PTR%d -> PTR%d result\n",
>   			ptr_id(sv3), ptr_id(*sv3));
> 

Fixes look good to me,

Acked-by: Joe Lawrence <joe.lawrence@redhat.com>

-- Joe

  parent reply	other threads:[~2019-02-05 21:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04 13:56 [PATCH v2 0/4] livepatch: Followup changes for the atomic replace patchset Petr Mladek
2019-02-04 13:56 ` [PATCH v2 1/4] livepatch: Introduce klp_for_each_patch macro Petr Mladek
2019-02-04 13:56 ` [PATCH v2 2/4] livepatch: return -ENOMEM on ptr_id() allocation failure Petr Mladek
2019-02-05 13:26   ` Miroslav Benes
2019-02-04 13:56 ` [PATCH v2 3/4] livepatch: Proper error handling in the shadow variables selftest Petr Mladek
2019-02-05 14:18   ` Miroslav Benes
2019-02-05 21:17   ` Joe Lawrence [this message]
2019-02-04 13:56 ` [PATCH v2 4/4] livepatch: Module coming and going callbacks can proceed with all listed patches Petr Mladek
2019-02-06 10:29 ` [PATCH v2 0/4] livepatch: Followup changes for the atomic replace patchset Petr Mladek
2019-02-06 15:22 ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6c313c97-fd7b-8ab6-446f-6dac4c34a30c@redhat.com \
    --to=joe.lawrence@redhat.com \
    --cc=eshatokhin@virtuozzo.com \
    --cc=jbaron@akamai.com \
    --cc=jikos@kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=pmladek@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®