Linux EDAC development
 help / color / mirror / Atom feed
From: "Luck, Tony" <tony.luck@intel.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Borislav Petkov <bp@alien8.de>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-edac@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>
Subject: [1/2] ras: fix an off-by-one error in __find_elem()
Date: Tue, 16 Apr 2019 18:53:51 -0700	[thread overview]
Message-ID: <20190417015351.GA28490@agluck-desk> (raw)

On Tue, Apr 16, 2019 at 04:47:55PM -0700, Cong Wang wrote:
> 229 static void del_elem(struct ce_array *ca, int idx)
> 230 {
> 231         /* Save us a function call when deleting the last element. */
> 232         if (ca->n - (idx + 1))
> 233                 memmove((void *)&ca->array[idx],
> 234                         (void *)&ca->array[idx + 1],
> 235                         (ca->n - (idx + 1)) * sizeof(u64));
> 236
> 237         ca->n--;
> 238 }
> 
> idx is ca->n and ca->n is MAX_ELEMS-1, then the above if statement
> becomes true, therefore idx+1 is MAX_ELEMS which is just beyond
> the valid range.

Is that really the memmove() where we die?  It looks like
it has a special case for dealing with the last element.

But this:

296         ret = find_elem(ca, pfn, &to);
297         if (ret < 0) {
298                 /*
299                  * Shift range [to-end] to make room for one more element.
300                  */
301                 memmove((void *)&ca->array[to + 1],
302                         (void *)&ca->array[to],
303                         (ca->n - to) * sizeof(u64));
304

looks like it also needs a special case for when "to ==  MAX_ELEMS-1"
(we don't need to memmove).

-Tony

WARNING: multiple messages have this Message-ID (diff)
From: "Luck, Tony" <tony.luck@intel.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Borislav Petkov <bp@alien8.de>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-edac@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH 1/2] ras: fix an off-by-one error in __find_elem()
Date: Tue, 16 Apr 2019 18:53:51 -0700	[thread overview]
Message-ID: <20190417015351.GA28490@agluck-desk> (raw)
Message-ID: <20190417015351.FuOh6mrCtmH-tThkLtv7wFKA2fqO2aPsZ8noJbmdIXY@z> (raw)
In-Reply-To: <CAM_iQpXBJ2eAz4TW_GmOWRLrkyJcO=u-8VSnmv91ZABG-21Agg@mail.gmail.com>

On Tue, Apr 16, 2019 at 04:47:55PM -0700, Cong Wang wrote:
> 229 static void del_elem(struct ce_array *ca, int idx)
> 230 {
> 231         /* Save us a function call when deleting the last element. */
> 232         if (ca->n - (idx + 1))
> 233                 memmove((void *)&ca->array[idx],
> 234                         (void *)&ca->array[idx + 1],
> 235                         (ca->n - (idx + 1)) * sizeof(u64));
> 236
> 237         ca->n--;
> 238 }
> 
> idx is ca->n and ca->n is MAX_ELEMS-1, then the above if statement
> becomes true, therefore idx+1 is MAX_ELEMS which is just beyond
> the valid range.

Is that really the memmove() where we die?  It looks like
it has a special case for dealing with the last element.

But this:

296         ret = find_elem(ca, pfn, &to);
297         if (ret < 0) {
298                 /*
299                  * Shift range [to-end] to make room for one more element.
300                  */
301                 memmove((void *)&ca->array[to + 1],
302                         (void *)&ca->array[to],
303                         (ca->n - to) * sizeof(u64));
304

looks like it also needs a special case for when "to ==  MAX_ELEMS-1"
(we don't need to memmove).

-Tony

         reply	other threads:[~2019-04-17  1:53 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-16  1:20 [1/2] ras: fix an off-by-one error in __find_elem() Cong Wang
2019-04-16  1:20 ` [PATCH 1/2] " Cong Wang
2019-04-16  1:20 ` [2/2] ras: close the race condition with timer Cong Wang
2019-04-16  1:20   ` [PATCH 2/2] " Cong Wang
2019-04-16  9:58   ` [2/2] " Borislav Petkov
2019-04-16  9:58     ` [PATCH 2/2] " Borislav Petkov
2019-04-16 17:09     ` [2/2] " Cong Wang
2019-04-16 17:09       ` [PATCH 2/2] " Cong Wang
2019-04-16 17:42       ` [2/2] " Borislav Petkov
2019-04-16 17:42         ` [PATCH 2/2] " Borislav Petkov
2019-04-16 18:00         ` [2/2] " Cong Wang
2019-04-16 18:00           ` [PATCH 2/2] " Cong Wang
2019-04-16 18:06           ` [2/2] " Cong Wang
2019-04-16 18:06             ` [PATCH 2/2] " Cong Wang
2019-04-16  9:07 ` [1/2] ras: fix an off-by-one error in __find_elem() Borislav Petkov
2019-04-16  9:07   ` [PATCH 1/2] " Borislav Petkov
2019-04-16 17:01   ` [1/2] " Cong Wang
2019-04-16 17:01     ` [PATCH 1/2] " Cong Wang
2019-04-16 22:18   ` [1/2] " Luck, Tony
2019-04-16 22:18     ` [PATCH 1/2] " Luck, Tony
2019-04-16 23:18     ` [1/2] " Cong Wang
2019-04-16 23:18       ` [PATCH 1/2] " Cong Wang
2019-04-16 23:28       ` [1/2] " Luck, Tony
2019-04-16 23:28         ` [PATCH 1/2] " Luck, Tony
2019-04-16 23:47         ` [1/2] " Cong Wang
2019-04-16 23:47           ` [PATCH 1/2] " Cong Wang
2019-04-17  1:53           ` Luck, Tony [this message]
2019-04-17  1:53             ` Luck, Tony
2019-04-17  2:31             ` [1/2] " Cong Wang
2019-04-17  2:31               ` [PATCH 1/2] " Cong Wang
2019-04-17  2:37               ` [1/2] " Cong Wang
2019-04-17  2:37                 ` [PATCH 1/2] " Cong Wang
2019-04-17 21:15                 ` [1/2] " Luck, Tony
2019-04-17 21:15                   ` [PATCH 1/2] " Luck, Tony
2019-04-18 22:54                   ` [1/2] " Cong Wang
2019-04-18 22:54                     ` [PATCH 1/2] " Cong Wang

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=20190417015351.GA28490@agluck-desk \
    --to=tony.luck@intel.com \
    --cc=bp@alien8.de \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=xiyou.wangcong@gmail.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