public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sun Peng <sun_peng@topsec.com.cn>
Cc: Jiri Slaby <jslaby@suse.com>,
	linux-kernel@vger.kernel.org, security@kernel.org,
	Tony Lindgren <tony@atomide.com>,
	Lars Poeschel <poeschel@lemonage.de>,
	Sascha Hauer <s.hauer@pengutronix.de>
Subject: [PATCH 1/4] tty: n_gsm: add some locking around gsm_mux[]
Date: Thu, 26 Apr 2018 08:52:35 +0300	[thread overview]
Message-ID: <20180426055235.GA15229@mwanda> (raw)
In-Reply-To: <20180420083028.7fq3hw2mjjd7nrra@mwanda>

We should take "gsm_mux_lock" when we access gsm_mux[].

Reported-by: Sun Peng <sun_peng@topsec.com.cn>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 3b3e1f6632d7..cc7f68814200 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2898,18 +2898,22 @@ static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty)
 	bool alloc = false;
 	int ret;
 
-	line = line & 0x3F;
 
 	if (mux >= MAX_MUX)
 		return -ENXIO;
-	/* FIXME: we need to lock gsm_mux for lifetimes of ttys eventually */
-	if (gsm_mux[mux] == NULL)
-		return -EUNATCH;
+
+	line = line & 0x3F;
 	if (line == 0 || line > 61)	/* 62/63 reserved */
 		return -ECHRNG;
+
+	spin_lock(&gsm_mux_lock);
 	gsm = gsm_mux[mux];
+	spin_unlock(&gsm_mux_lock);
+	if (!gsm)
+		return -EUNATCH;
 	if (gsm->dead)
 		return -EL2HLT;
+
 	/* If DLCI 0 is not yet fully open return an error.
 	This is ok from a locking
 	perspective as we don't have to worry about this

       reply	other threads:[~2018-04-26  5:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20180420083028.7fq3hw2mjjd7nrra@mwanda>
2018-04-26  5:52 ` Dan Carpenter [this message]
2018-04-26  9:27   ` [PATCH 1/4] tty: n_gsm: add some locking around gsm_mux[] Dan Carpenter
2018-04-26  5:53 ` [PATCH 2/4] tty: n_gsm: Prevent a potential use after free Dan Carpenter
2018-04-27 18:50   ` Tony Lindgren
2018-04-26  5:53 ` [PATCH 3/4] tty: n_gsm: Remove an unused lock Dan Carpenter
2018-04-26  5:54 ` [PATCH 4/4] tty: n_gsm: Fix the test for if DLCI0 is open Dan Carpenter

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=20180426055235.GA15229@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=poeschel@lemonage.de \
    --cc=s.hauer@pengutronix.de \
    --cc=security@kernel.org \
    --cc=sun_peng@topsec.com.cn \
    --cc=tony@atomide.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