linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Helge Deller <deller@gmx.de>
To: Ard Biesheuvel <ardb@kernel.org>,
	Douglas Anderson <dianders@chromium.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Subject: [PATCH] crypto: xor - avoid division by zero crash
Date: Sun, 24 Jan 2021 15:28:06 +0100	[thread overview]
Message-ID: <20210124142806.GA29180@ls3530.fritz.box> (raw)

On some of my parisc machines, this patch c055e3eae0f1 ("crypto: xor -
use ktime for template benchmarking") triggers a dividy-by-zero
exception because "min" becomes zero, which then leads to a kernel
crash.

It's not clear yet, why I see the issue only on some machines. At least
on those the measured time to run the xor speed tests becomes zero
nanoseconds. Maybe it's because gcc-10 optimizes the speed test out, or
because of some other changes in the time keeping routines.

In either case, the kernel should not crash.

This patch adds a workaround by reporting such cases with a kernel
warning and continues as if the xor tests would have run in 1 ns.

Signed-off-by: Helge Deller <deller@gmx.de>
Cc: stable@vger.kernel.org # 5.10+

---

diff --git a/crypto/xor.c b/crypto/xor.c
index eacbf4f93990..3639341bac7e 100644
--- a/crypto/xor.c
+++ b/crypto/xor.c
@@ -100,6 +100,8 @@ do_xor_speed(struct xor_block_template *tmpl, void *b1, void *b2)
 			mb();
 		}
 		diff = ktime_sub(ktime_get(), start);
+		if (WARN_ON(diff == 0))
+			diff = 1;
 		if (diff < min)
 			min = diff;
 	}

             reply	other threads:[~2021-01-24 14:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-24 14:28 Helge Deller [this message]
2021-01-24 14:30 ` [PATCH] crypto: xor - avoid division by zero crash Ard Biesheuvel
2021-01-24 20:38   ` Helge Deller

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=20210124142806.GA29180@ls3530.fritz.box \
    --to=deller@gmx.de \
    --cc=ardb@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dianders@chromium.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-parisc@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;
as well as URLs for NNTP newsgroup(s).