From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Mikulas Patocka <mpatocka@redhat.com>,
Mike Snitzer <msnitzer@redhat.com>
Cc: dm-devel@redhat.com
Subject: Re: [PATCH] dm-ingerity: change memcmp to strncmp
Date: Wed, 13 Mar 2019 07:40:26 -0700 [thread overview]
Message-ID: <1552488026.3022.2.camel@HansenPartnership.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1903130753420.22289@file01.intranet.prod.int.rdu2.redhat.com>
On Wed, 2019-03-13 at 07:56 -0400, Mikulas Patocka wrote:
> If the string opt_string is small, the function memcmp can access
> bytes
> that are beyond the terminating nul character. In theory, it could
> cause
> segfault, if opt_string were located just below some unmapped memory.
>
> This patch changes memcmp to strncmp, so that we don't read bytes
> beyond
> the end of the string.
>
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org # v4.12+
>
> ---
> drivers/md/dm-integrity.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> Index: linux-2.6/drivers/md/dm-integrity.c
> ===================================================================
> --- linux-2.6.orig/drivers/md/dm-integrity.c 2019-03-12
> 15:33:17.000000000 +0100
> +++ linux-2.6/drivers/md/dm-integrity.c 2019-03-12
> 15:34:49.000000000 +0100
> @@ -3185,7 +3185,7 @@ static int dm_integrity_ctr(struct dm_ta
> journal_watermark = val;
> else if (sscanf(opt_string, "commit_time:%u%c",
> &val, &dummy) == 1)
> sync_msec = val;
> - else if (!memcmp(opt_string, "meta_device:",
> strlen("meta_device:"))) {
> + else if (!strncmp(opt_string, "meta_device:",
> strlen("meta_device:"))) {
strncmp(a, b, strlen(b)) is semantically equivalent to strcmp(a,b) but
the latter is far shorter and easier so you should use it.
James
next prev parent reply other threads:[~2019-03-13 14:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-13 11:56 [PATCH] dm-ingerity: change memcmp to strncmp Mikulas Patocka
2019-03-13 14:40 ` James Bottomley [this message]
2019-03-13 15:58 ` Mikulas Patocka
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=1552488026.3022.2.camel@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=dm-devel@redhat.com \
--cc=mpatocka@redhat.com \
--cc=msnitzer@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.