linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>,
	linux-kernel@vger.kernel.org,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: [GIT PULL 7/7] stm class: Prevent division by zero
Date: Thu, 21 Feb 2019 15:49:59 +0200	[thread overview]
Message-ID: <20190221134959.15121-8-alexander.shishkin@linux.intel.com> (raw)
In-Reply-To: <20190221134959.15121-1-alexander.shishkin@linux.intel.com>

Using STP_POLICY_ID_SET ioctl command with dummy_stm device, or any STM
device that supplies zero mmio channel size, will trigger a division by
zero bug in the kernel.

Prevent this by disallowing channel widths other than 1 for such devices.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 drivers/hwtracing/stm/core.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c
index c80b064224f6..c7ba8acfd4d5 100644
--- a/drivers/hwtracing/stm/core.c
+++ b/drivers/hwtracing/stm/core.c
@@ -735,7 +735,7 @@ static int stm_char_policy_set_ioctl(struct stm_file *stmf, void __user *arg)
 	struct stm_device *stm = stmf->stm;
 	struct stp_policy_id *id;
 	char *ids[] = { NULL, NULL };
-	int ret = -EINVAL;
+	int ret = -EINVAL, wlimit = 1;
 	u32 size;
 
 	if (stmf->output.nr_chans)
@@ -763,8 +763,10 @@ static int stm_char_policy_set_ioctl(struct stm_file *stmf, void __user *arg)
 	if (id->__reserved_0 || id->__reserved_1)
 		goto err_free;
 
-	if (id->width < 1 ||
-	    id->width > PAGE_SIZE / stm->data->sw_mmiosz)
+	if (stm->data->sw_mmiosz)
+		wlimit = PAGE_SIZE / stm->data->sw_mmiosz;
+
+	if (id->width < 1 || id->width > wlimit)
 		goto err_free;
 
 	ids[0] = id->id;
-- 
2.20.1


  parent reply	other threads:[~2019-02-21 13:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-21 13:49 [GIT PULL 0/7] stm class/intel_th: Updates for v5.1 Alexander Shishkin
2019-02-21 13:49 ` [GIT PULL 1/7] intel_th: Update ABI documentation Alexander Shishkin
2019-02-21 13:49 ` [GIT PULL 2/7] intel_th: Mark expected switch fall-throughs Alexander Shishkin
2019-02-21 13:49 ` [GIT PULL 3/7] intel_th: Only create useful device nodes Alexander Shishkin
2019-02-21 13:49 ` [GIT PULL 4/7] intel_th: pti: Use sysfs_match_string() helper Alexander Shishkin
2019-02-21 13:49 ` [GIT PULL 5/7] intel_th: Don't reference unassigned outputs Alexander Shishkin
2019-02-21 14:41   ` Greg Kroah-Hartman
2019-02-21 13:49 ` [GIT PULL 6/7] stm class: Fix an endless loop in channel allocation Alexander Shishkin
2019-02-21 14:42   ` Greg Kroah-Hartman
2019-02-21 13:49 ` Alexander Shishkin [this message]
2019-02-21 14:42   ` [GIT PULL 7/7] stm class: Prevent division by zero Greg Kroah-Hartman
2019-02-21 14:52     ` Alexander Shishkin

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=20190221134959.15121-8-alexander.shishkin@linux.intel.com \
    --to=alexander.shishkin@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.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).