linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Kay Sievers <kay@vrfy.org>
Cc: Joe Perches <joe@perches.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	devel@driverdev.osuosl.org, alsa-devel@alsa-project.org,
	Kay Sievers <kay.sievers@vrfy.org>
Subject: Re: [PATCH 0/8] Rework KERN_<LEVEL>
Date: Tue, 5 Jun 2012 16:09:33 -0700	[thread overview]
Message-ID: <20120605160933.6fd5bc90.akpm@linux-foundation.org> (raw)
In-Reply-To: <1338936900.1157.3.camel@mop>

On Wed, 06 Jun 2012 00:55:00 +0200
Kay Sievers <kay@vrfy.org> wrote:

> On Tue, 2012-06-05 at 14:28 -0700, Andrew Morton wrote:
> 
> > devkmsg_writev() does weird and wonderful things with
> > facilities/levels.  That function incorrectly returns "success" when
> > copy_from_user() faults, btw.
> 
> Oh. Better?
> 
> Thanks,
> Kay
> 
> 
> From: Kay Sievers <kay@vrfy.org>
> Subject: kmsg: /dev/kmsg - properly return possible copy_from_user() failure
> 
> Reported-By: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Kay Sievers <kay@vrfy.org
> ---
>  printk.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/printk.c b/kernel/printk.c
> index 32462d2..6bdacab 100644
> --- a/kernel/printk.c
> +++ b/kernel/printk.c
> @@ -365,8 +365,10 @@ static ssize_t devkmsg_writev(struct kiocb *iocb, const struct iovec *iv,
>  
>  	line = buf;
>  	for (i = 0; i < count; i++) {
> -		if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len))
> +		if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len)) {
> +			ret = -EFAULT;
>  			goto out;
> +		}
>  		line += iv[i].iov_len;
>  	}

Strictly speaking, when write() encounters an error it should return
number-of-bytes-written, or an errno if it wrote zero bytes.  So
something like

--- a/kernel/printk.c~a
+++ a/kernel/printk.c
@@ -355,7 +355,7 @@ static ssize_t devkmsg_writev(struct kio
 	int level = default_message_loglevel;
 	int facility = 1;	/* LOG_USER */
 	size_t len = iov_length(iv, count);
-	ssize_t ret = len;
+	ssize_t ret;
 
 	if (len > LOG_LINE_MAX)
 		return -EINVAL;
@@ -365,8 +365,12 @@ static ssize_t devkmsg_writev(struct kio
 
 	line = buf;
 	for (i = 0; i < count; i++) {
-		if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len))
+		if (copy_from_user(line, iv[i].iov_base, iv[i].iov_len)) {
+			ret = line - buf;
+			if (!ret)
+				ret = -EFAULT;
 			goto out;
+		}
 		line += iv[i].iov_len;
 	}
 
@@ -396,6 +400,7 @@ static ssize_t devkmsg_writev(struct kio
 	line[len] = '\0';
 
 	printk_emit(facility, level, NULL, 0, "%s", line);
+	ret = 0;
 out:
 	kfree(buf);
 	return ret;
_


      reply	other threads:[~2012-06-05 23:09 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-05  9:46 [PATCH 0/8] Rework KERN_<LEVEL> Joe Perches
2012-06-05  9:46 ` [PATCH 4/8] btrfs: Use printk_get_level and printk_skip_level, add __printf, fix fallout Joe Perches
2012-06-05 21:28 ` [PATCH 0/8] Rework KERN_<LEVEL> Andrew Morton
2012-06-05 21:53   ` Kay Sievers
2012-06-05 22:11   ` Joe Perches
2012-06-05 22:17     ` Andrew Morton
2012-06-05 22:49       ` Joe Perches
2012-06-05 23:29         ` Andrew Morton
2012-06-05 23:35           ` Joe Perches
2012-06-05 23:39             ` Kay Sievers
2012-06-05 23:43               ` Joe Perches
2012-06-05 23:48                 ` Kay Sievers
2012-06-05 23:52                   ` Joe Perches
2012-06-05 23:58                     ` Andrew Morton
2012-06-06  0:07                       ` Joe Perches
2012-06-06  0:13                         ` Kay Sievers
2012-06-06  0:19                           ` Joe Perches
2012-06-06  0:28                             ` Kay Sievers
2012-06-06  0:37                               ` Joe Perches
2012-06-06  0:37                               ` Andrew Morton
2012-06-06  0:40                                 ` Joe Perches
2012-06-06  0:46                                   ` Andrew Morton
2012-06-06  1:10                                     ` Kay Sievers
2012-06-06  2:06                                       ` Joe Perches
2012-06-06  3:04                                       ` [PATCH 9/8] printk: Only look for prefix levels in kernel messages Joe Perches
2012-06-05 23:48               ` [PATCH 0/8] Rework KERN_<LEVEL> Joe Perches
2012-06-05 22:55   ` Kay Sievers
2012-06-05 23:09     ` Andrew Morton [this message]

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=20120605160933.6fd5bc90.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=joe@perches.com \
    --cc=kay.sievers@vrfy.org \
    --cc=kay@vrfy.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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).