From: Jesper Juhl <juhl-lkml@dif.dk>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: "Jesper Juhl" <juhl-lkml@dif.dk>,
"Steve French" <sfrench@samba.org>,
"Steve French" <sfrench@us.ibm.com>,
samba-technical <samba-technical@lists.samba.org>,
"Jörn Engel" <joern@wohnheim.fh-wedel.de>,
"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: Re: [patch 1/3] copy_to_user check in fs/cifs/file.c
Date: Wed, 29 Dec 2004 00:48:01 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.61.0412290042480.3528@dragon.hygekrogen.localhost> (raw)
In-Reply-To: <1104104286.16545.7.camel@localhost.localdomain>
On Sun, 26 Dec 2004, Alan Cox wrote:
> On Sul, 2004-12-26 at 23:24, Jesper Juhl wrote:
> > Hi,
> >
> > Patch below adds a check for the copy_to_user return value and makes a few
> > whitespace cleanups in fs/cifs/file.c::cifs_user_read()
> > I hope bundling two different things together in one patch is OK when the
> > change is as small as this, but if you want it spplit in two patches, then
> > just say so.
>
> Corrupts the stats
> Fails to free smb_read_data where in some cases it was freed before
>
> I'm not sure the stats matter but I think you need something more like
>
Like this patch perhaps? :
It implements what you sugested except it breaks the loop when there's
some residue from the copy_to_user call, since the logic after the while
loop handles the return total_read ? total_read : -EFAULT; case if we
set rc and break (I've cut the diff with a few lines of extra context to
make this easy to verify).
Comments welcome as always.
Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
diff --unified=8 -p linux-2.6.10-orig/fs/cifs/file.c linux-2.6.10/fs/cifs/file.c
--- linux-2.6.10-orig/fs/cifs/file.c 2004-12-24 22:33:48.000000000 +0100
+++ linux-2.6.10/fs/cifs/file.c 2004-12-28 23:27:17.000000000 +0100
@@ -1142,16 +1142,17 @@ cifs_user_read(struct file * file, char
open_file = (struct cifsFileInfo *)file->private_data;
if((file->f_flags & O_ACCMODE) == O_WRONLY) {
cFYI(1,("attempting read on write only file instance"));
}
for (total_read = 0,current_offset=read_data; read_size > total_read;
total_read += bytes_read,current_offset+=bytes_read) {
+ unsigned residue;
current_read_size = min_t(const int,read_size - total_read,cifs_sb->rsize);
rc = -EAGAIN;
smb_read_data = NULL;
while(rc == -EAGAIN) {
if ((open_file->invalidHandle) && (!open_file->closePend)) {
rc = cifs_reopen_file(file->f_dentry->d_inode,
file,TRUE);
if(rc != 0)
@@ -1159,22 +1160,27 @@ cifs_user_read(struct file * file, char
}
rc = CIFSSMBRead(xid, pTcon,
open_file->netfid,
current_read_size, *poffset,
&bytes_read, &smb_read_data);
pSMBr = (struct smb_com_read_rsp *)smb_read_data;
- copy_to_user(current_offset,smb_read_data + 4/* RFC1001 hdr*/
+ residue = copy_to_user(current_offset, smb_read_data + 4 /* RFC1001 hdr */
+ le16_to_cpu(pSMBr->DataOffset), bytes_read);
if(smb_read_data) {
cifs_buf_release(smb_read_data);
smb_read_data = NULL;
}
+ if (residue) {
+ total_read += bytes_read - residue;
+ rc = -EFAULT;
+ break;
+ }
}
if (rc || (bytes_read == 0)) {
if (total_read) {
break;
} else {
FreeXid(xid);
return rc;
}
next prev parent reply other threads:[~2004-12-28 23:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-26 23:24 [patch] copy_to_user check and whitespace cleanups " Jesper Juhl
2004-12-26 23:38 ` Alan Cox
2004-12-27 1:21 ` Jesper Juhl
2004-12-28 23:48 ` Jesper Juhl [this message]
2004-12-28 22:45 ` [patch 1/3] copy_to_user check " Alan Cox
2004-12-28 23:52 ` [patch 2/3] whitespace cleanups " Jesper Juhl
2004-12-29 1:57 ` Jörn Engel
2004-12-29 2:59 ` Jesper Juhl
2004-12-29 12:29 ` Jörn Engel
2004-12-29 18:48 ` Domen Puncer
2004-12-29 13:42 ` [patch 2/3] " Horst von Brand
2004-12-29 14:48 ` Jörn Engel
2004-12-29 16:31 ` Horst von Brand
2004-12-29 9:51 ` Wichert Akkerman
2004-12-29 12:10 ` Jörn Engel
2005-01-03 12:01 ` Martin Waitz
2004-12-28 23:55 ` [patch 3/3] get rid of two unnessesary assignments " Jesper Juhl
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=Pine.LNX.4.61.0412290042480.3528@dragon.hygekrogen.localhost \
--to=juhl-lkml@dif.dk \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=joern@wohnheim.fh-wedel.de \
--cc=linux-kernel@vger.kernel.org \
--cc=samba-technical@lists.samba.org \
--cc=sfrench@samba.org \
--cc=sfrench@us.ibm.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®