mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vineet Gupta <Vineet.Gupta1@synopsys.com>
To: "arc-linux-dev@synopsys.com" <arc-linux-dev@synopsys.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Mischa Jonker <Mischa.Jonker@synopsys.com>
Subject: Re: [arc-linux-dev] [PATCH] ARC: Fix array-out-of-bounds issue in tlb overlap handler
Date: Thu, 26 Sep 2013 14:26:22 +0000	[thread overview]
Message-ID: <C2D7FE5348E1B147BCA15975FBA2307514E9B0@IN01WEMBXA.internal.synopsys.com> (raw)
In-Reply-To: <1380203182-5982-1-git-send-email-mjonker@synopsys.com>

On 09/26/2013 07:36 PM, Mischa Jonker wrote:
> Even after fixing the issue, GCC 4.8 still complains with a warning,
> but with the fix, I think it's a false positive. Therefore I have
> also added a #pragma to ignore the warning.
>
> Signed-off-by: Mischa Jonker <mjonker@synopsys.com>
> ---
>  arch/arc/mm/tlb.c |    9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arc/mm/tlb.c b/arch/arc/mm/tlb.c
> index 129af50..5af7c98 100644
> --- a/arch/arc/mm/tlb.c
> +++ b/arch/arc/mm/tlb.c
> @@ -635,13 +635,20 @@ void do_tlb_overlap_fault(unsigned long cause, unsigned long address,
>  			continue;
>  
>  		/* Scan the set for duplicate ways: needs a nested loop */
> -		for (way = 0; way < mmu->ways; way++) {
> +		for (way = 0; way < (mmu->ways - 1); way++) {
>  			if (!pd0[way])
>  				continue;

While the fix is correct, it's not fixing out-of-bound array access since that is
not what was happening. For the last way, the nested loop will not enter at all -
your fix prevents it from trying to do that - so please fix the changlog.

>  			for (n = way + 1; n < mmu->ways; n++) {
> +/*
> + * GCC 4.8 does not understand that way < (mmu->ways - 1), and as such
> + * n < mmu->ways. So, ignore the warning
> + */
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Warray-bounds"
>  				if ((pd0[way] & PAGE_MASK) ==
>  				    (pd0[n] & PAGE_MASK)) {
> +#pragma GCC diagnostic pop
>  
>  					if (dup_pd_verbose) {
>  						pr_info("Duplicate PD's @"

I'd prefer the following as it's less uglier.

-       unsigned int pd0[4], pd1[4];    /* assume max 4 ways */
        unsigned long flags, is_valid;
        struct cpuinfo_arc_mmu *mmu = &cpuinfo_arc700[smp_processor_id()].mmu;
+      unsigned int pd0[mmu->ways], pd1[mmu->ways];
 
-Vineet

      reply	other threads:[~2013-09-26 14:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-26 13:46 Mischa Jonker
2013-09-26 14:26 ` Vineet Gupta [this message]

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=C2D7FE5348E1B147BCA15975FBA2307514E9B0@IN01WEMBXA.internal.synopsys.com \
    --to=vineet.gupta1@synopsys.com \
    --cc=Mischa.Jonker@synopsys.com \
    --cc=arc-linux-dev@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    /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®