All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jiri Slaby <jirislaby@gmail.com>
Cc: alan@lxorguk.ukuu.org.uk, linux-kernel@vger.kernel.org,
	jirislaby@gmail.com, eibach@gdsys.de
Subject: Re: [PATCH 1/1] Char: moxa, prevent opening unavailable ports
Date: Tue, 9 Jun 2009 12:27:35 -0700	[thread overview]
Message-ID: <20090609122735.9a915cbf.akpm@linux-foundation.org> (raw)
In-Reply-To: <1244557981-9443-1-git-send-email-jirislaby@gmail.com>

On Tue,  9 Jun 2009 16:33:01 +0200
Jiri Slaby <jirislaby@gmail.com> wrote:

> From: Dirk Eibach <eibach@gdsys.de>
> 
> In moxa.c there are 32 minor numbers reserved for each device. The
> number of ports actually available per device is stored in
> moxa_board_conf->numPorts. This number is not considered in moxa_open().
> Opening a port that is not available results in a kernel oops.
> This patch adds a test to moxa_open() that prevents opening unavailable
> ports.
> 
> Signed-off-by: Dirk Eibach <eibach@gdsys.de>
> Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
> ---
>  drivers/char/moxa.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
> index 4a4cab7..65b6ff2 100644
> --- a/drivers/char/moxa.c
> +++ b/drivers/char/moxa.c
> @@ -1184,6 +1184,11 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
>  		return -ENODEV;
>  	}
>  
> +	if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) {
> +		mutex_unlock(&moxa_openlock);
> +		return -ENODEV;
> +	}
> +
>  	ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
>  	ch->port.count++;
>  	tty->driver_data = ch;

Looks good to me.  But please, let's avoid adding the
multiple-return-statement hand grenade?

--- a/drivers/char/moxa.c~char-moxa-prevent-opening-unavailable-ports
+++ a/drivers/char/moxa.c
@@ -1184,6 +1184,11 @@ static int moxa_open(struct tty_struct *
 		return -ENODEV;
 	}
 
+	if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) {
+		retval = -ENODEV;
+		goto out_unlock;
+	}
+
 	ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
 	ch->port.count++;
 	tty->driver_data = ch;
@@ -1208,8 +1213,8 @@ static int moxa_open(struct tty_struct *
 				moxa_close_port(tty);
 	} else
 		ch->port.flags |= ASYNC_NORMAL_ACTIVE;
+out_unlock:
 	mutex_unlock(&moxa_openlock);
-
 	return retval;
 }
 
_



btw, what's this code in moxa_open() doing?

	if (port == MAX_PORTS) {
		return capable(CAP_SYS_ADMIN) ? 0 : -EPERM;
	}

why does it return 0 if CAP_SYS_ADMIN?				

  reply	other threads:[~2009-06-09 19:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-09 14:33 [PATCH 1/1] Char: moxa, prevent opening unavailable ports Jiri Slaby
2009-06-09 19:27 ` Andrew Morton [this message]
2009-06-09 19:36   ` Jiri Slaby
2009-06-09 23:34   ` Alan Cox

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=20090609122735.9a915cbf.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=eibach@gdsys.de \
    --cc=jirislaby@gmail.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 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.