mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: martin@dalecki.de
Cc: Linus Torvalds <torvalds@transmeta.com>,
	Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] 2.5.27 read_write
Date: 22 Jul 2002 18:04:49 +0100	[thread overview]
Message-ID: <1027357489.32299.53.camel@irongate.swansea.linux.org.uk> (raw)
In-Reply-To: <3D3C11DE.7010000@evision.ag>

On Mon, 2002-07-22 at 15:08, Marcin Dalecki wrote:
> - This is making the read_write.c C.
> 
> - It is fixing completely confused wild casting to 32 bits.
> 
> - Actually adding a comment explaining the obscure code, which is
>    relying on integer arithmetics overflow.

This is the 2.4 patch. This passes the SuS LSB validation tests and gets
32/64bit behaviour as well as sign rules for iov_len elements right. At
least I hope it does.

--- linux-2.5.27/fs/read_write.c	Sat Jul 20 20:11:25 2002
+++ linux-2.5.27-ac1/fs/read_write.c	Mon Jul 22 15:43:46 2002
@@ -301,17 +301,23 @@
 	if (copy_from_user(iov, vector, count*sizeof(*vector)))
 		goto out;
 
-	/* BSD readv/writev returns EINVAL if one of the iov_len
-	   values < 0 or tot_len overflowed a 32-bit integer. -ink */
+	/*
+	 * Single unix specification:
+	 * We should -EINVAL if an element length is not >= 0 and fitting an ssize_t
+	 * The total length is fitting an ssize_t
+	 *
+	 * Be careful here because iov_len is a size_t not an ssize_t
+	 */
+	 
 	tot_len = 0;
 	ret = -EINVAL;
 	for (i = 0 ; i < count ; i++) {
-		size_t tmp = tot_len;
-		int len = iov[i].iov_len;
-		if (len < 0)
+		ssize_t tmp = tot_len;
+		ssize_t len = (ssize_t)iov[i].iov_len;
+		if (len < 0)	/* size_t not fitting an ssize_t .. */
 			goto out;
-		(u32)tot_len += len;
-		if (tot_len < tmp || tot_len < (u32)len)
+		tot_len += len;
+		if (tot_len < tmp) /* maths overflow on the ssize_t */
 			goto out;
 	}
 

      parent reply	other threads:[~2002-07-22 15:49 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-20 19:22 Linux-2.5.27 Linus Torvalds
2002-07-22 10:42 ` [PATCH] 2.5.27 sysctl Marcin Dalecki
2002-07-22 10:53   ` Christoph Hellwig
2002-07-22 10:56     ` Marcin Dalecki
2002-07-22 11:02       ` Christoph Hellwig
2002-07-22 11:03         ` Marcin Dalecki
2002-07-22 12:51           ` Alexander Viro
2002-07-22 13:02             ` Marcin Dalecki
2002-07-22 11:13       ` Christoph Hellwig
2002-07-22 11:19       ` Dave Jones
2002-07-22 11:19       ` bart
2002-07-22 11:21       ` BALBIR SINGH
2002-07-22 12:30       ` Alan Cox
2002-07-22 11:21         ` Marcin Dalecki
2002-07-22 15:57   ` Daniel Egger
2002-07-22 10:43 ` [PATCH] 2.5.27 devfs Marcin Dalecki
2002-07-22 17:28   ` Richard Gooch
2002-07-22 18:03     ` Marcin Dalecki
2002-07-22 18:19       ` Alexander Viro
2002-07-22 18:46         ` Marcin Dalecki
2002-07-23  5:04       ` Richard Gooch
2002-07-22 10:45 ` [PATCH] 2.5.27 sched Marcin Dalecki
2002-07-22 10:47 ` [PATCH] 2.5.27 smbiod Marcin Dalecki
2002-07-22 22:29   ` Albert D. Cahalan
2002-07-22 10:50 ` [PATCH] 2.5.27 spinlock Marcin Dalecki
2002-07-24  4:40   ` Rusty Russell
2002-07-22 10:51 ` [PATCH] 2.5.27 wait Marcin Dalecki
2002-07-22 10:53 ` [PATCH] 2.5.27 enum Marcin Dalecki
2002-07-22 20:01   ` Benjamin LaHaise
2002-07-23  2:11     ` David S. Miller
2002-07-23  2:55       ` Alexander Viro
2002-07-24  6:44       ` James H. Cloos Jr.
2002-07-23 12:27     ` Dave Jones
2002-07-23 12:41       ` Marcin Dalecki
2002-07-23 13:05       ` Bartlomiej Zolnierkiewicz
2002-07-24  4:49       ` Rusty Russell
2002-07-24  9:47         ` Dave Jones
2002-07-22 14:08 ` [PATCH] 2.5.27 read_write Marcin Dalecki
2002-07-22 16:55   ` Alan Cox
2002-07-22 16:15     ` [PATCH] 2.5.27 read_write - take 2 Marcin Dalecki
2002-07-22 17:04   ` Alan Cox [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=1027357489.32299.53.camel@irongate.swansea.linux.org.uk \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin@dalecki.de \
    --cc=torvalds@transmeta.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

all inboxes | Powered by JetHome®