All of lore.kernel.org
 help / color / mirror / Atom feed
From: Evgeny Novikov <novikov@ispras.ru>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Evgeny Novikov <novikov@ispras.ru>,
	Johan Hovold <johan@kernel.org>, Nikolay Kyx <knv418@gmail.com>,
	Dinghao Liu <dinghao.liu@zju.edu.cn>,
	Abheek Dhawan <adawesomeguy222@gmail.com>,
	Lee Gibson <leegib@gmail.com>,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	ldv-project@linuxtesting.org
Subject: [PATCH] staging: fwserial: Fix potential NULL pointer dereferences
Date: Fri, 21 May 2021 14:43:39 +0300	[thread overview]
Message-ID: <20210521114339.8469-1-novikov@ispras.ru> (raw)

If fwtty_install() will be invoked with such tty->index that will be
not less than MAX_TOTAL_PORTS then fwtty_port_get() will return NULL and
fwtty_install() will either assign it to tty->driver_data or dereference
in fwtty_port_put() (if tty_standard_install() will fail). The similar
situation is with fwloop_install(). The patch fixes both cases.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
---
 drivers/staging/fwserial/fwserial.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index 1ee6382cafc4..d0810896511e 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -1069,6 +1069,9 @@ static int fwtty_install(struct tty_driver *driver, struct tty_struct *tty)
 	struct fwtty_port *port = fwtty_port_get(tty->index);
 	int err;
 
+	if (!port)
+		return -ENODEV;
+
 	err = tty_standard_install(driver, tty);
 	if (!err)
 		tty->driver_data = port;
@@ -1082,6 +1085,9 @@ static int fwloop_install(struct tty_driver *driver, struct tty_struct *tty)
 	struct fwtty_port *port = fwtty_port_get(table_idx(tty->index));
 	int err;
 
+	if (!port)
+		return -ENODEV;
+
 	err = tty_standard_install(driver, tty);
 	if (!err)
 		tty->driver_data = port;
-- 
2.26.2


             reply	other threads:[~2021-05-21 11:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-21 11:43 Evgeny Novikov [this message]
2021-05-21 11:52 ` [PATCH] staging: fwserial: Fix potential NULL pointer dereferences Greg Kroah-Hartman
     [not found]   ` <219911622016850@mail.yandex.ru>
2021-05-26  8:45     ` Greg Kroah-Hartman

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=20210521114339.8469-1-novikov@ispras.ru \
    --to=novikov@ispras.ru \
    --cc=adawesomeguy222@gmail.com \
    --cc=dinghao.liu@zju.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=knv418@gmail.com \
    --cc=ldv-project@linuxtesting.org \
    --cc=leegib@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    /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.