aboutsummaryrefslogtreecommitdiff
path: root/sys/sys
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2016-03-29 19:57:11 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2016-03-29 19:57:11 +0000
commit9c64cfe56c46ac98eb5cb90a29ddf507b949d6d2 (patch)
tree274dd1a656932d8fc3c71925baabc2c7c736dd84 /sys/sys
parent0df87548b9a472ddf4132f62ad9467b20d4417cf (diff)
downloadsrc-9c64cfe56c46ac98eb5cb90a29ddf507b949d6d2.tar.gz
src-9c64cfe56c46ac98eb5cb90a29ddf507b949d6d2.zip
The sendfile(2) allows to send extra data from userspace before the file
data (headers). Historically the size of the headers was not checked against the socket buffer space. Application could easily overcommit the socket buffer space. With the new sendfile (r293439) the problem remained, but a KASSERT was inserted that checked that amount of data written to the socket matches its space. In case when size of headers is bigger that socket space, KASSERT fires. Without INVARIANTS the new sendfile won't panic, but would report incorrect amount of bytes sent. o With this change, the headers copyin is moved down into the cycle, after the sbspace() check. The uio size is trimmed by socket space there, which fixes the overcommit problem and its consequences. o The compatibility handling for FreeBSD 4 sendfile headers API is pushed up the stack to syscall wrappers. This required a copy and paste of the code, but in turn this allowed to remove extra stack carried parameter from fo_sendfile_t, and embrace entire compat code into #ifdef. If in future we got more fo_sendfile_t function, the copy and paste level would even reduce. Reviewed by: emax, gallatin, Maxim Dounin <mdounin mdounin.ru> Tested by: Vitalij Satanivskij <satan ukr.net> Sponsored by: Netflix
Notes
Notes: svn path=/head/; revision=297400
Diffstat (limited to 'sys/sys')
-rw-r--r--sys/sys/file.h6
-rw-r--r--sys/sys/socket.h1
2 files changed, 3 insertions, 4 deletions
diff --git a/sys/sys/file.h b/sys/sys/file.h
index 524c1cec1eb4..c30eb0584f70 100644
--- a/sys/sys/file.h
+++ b/sys/sys/file.h
@@ -112,7 +112,7 @@ typedef int fo_chown_t(struct file *fp, uid_t uid, gid_t gid,
struct ucred *active_cred, struct thread *td);
typedef int fo_sendfile_t(struct file *fp, int sockfd, struct uio *hdr_uio,
struct uio *trl_uio, off_t offset, size_t nbytes,
- off_t *sent, int flags, int kflags, struct thread *td);
+ off_t *sent, int flags, struct thread *td);
typedef int fo_seek_t(struct file *fp, off_t offset, int whence,
struct thread *td);
typedef int fo_fill_kinfo_t(struct file *fp, struct kinfo_file *kif,
@@ -376,11 +376,11 @@ fo_chown(struct file *fp, uid_t uid, gid_t gid, struct ucred *active_cred,
static __inline int
fo_sendfile(struct file *fp, int sockfd, struct uio *hdr_uio,
struct uio *trl_uio, off_t offset, size_t nbytes, off_t *sent, int flags,
- int kflags, struct thread *td)
+ struct thread *td)
{
return ((*fp->f_ops->fo_sendfile)(fp, sockfd, hdr_uio, trl_uio, offset,
- nbytes, sent, flags, kflags, td));
+ nbytes, sent, flags, td));
}
static __inline int
diff --git a/sys/sys/socket.h b/sys/sys/socket.h
index c20b07522c97..649ba0090236 100644
--- a/sys/sys/socket.h
+++ b/sys/sys/socket.h
@@ -594,7 +594,6 @@ struct sf_hdtr {
#define SF_FLAGS(rh, flags) (((rh) << 16) | (flags))
#ifdef _KERNEL
-#define SFK_COMPAT 0x00000001
#define SF_READAHEAD(flags) ((flags) >> 16)
#endif /* _KERNEL */