From 3dc87905fa8340ae8086229b208923194531bf8b Mon Sep 17 00:00:00 2001 From: kib Date: Tue, 15 Oct 2013 06:33:10 +0000 Subject: [PATCH] Similar to debug.iosize_max_clamp sysctl, introduce devfs_iosize_max_clamp sysctl, which allows/disables SSIZE_MAX-sized i/o requests on the devfs files. Sponsored by: The FreeBSD Foundation Reminded by: Dmitry Sivachenko MFC after: 1 week --- sys/fs/devfs/devfs_vnops.c | 4 ++++ sys/kern/sys_generic.c | 4 ++++ sys/sys/systm.h | 2 ++ 3 files changed, 10 insertions(+) diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c index dcc10c877676..a05299a8e703 100644 --- a/sys/fs/devfs/devfs_vnops.c +++ b/sys/fs/devfs/devfs_vnops.c @@ -1178,6 +1178,8 @@ devfs_read_f(struct file *fp, struct uio *uio, struct ucred *cred, struct cdevsw *dsw; struct file *fpop; + if (uio->uio_resid > DEVFS_IOSIZE_MAX) + return (EINVAL); fpop = td->td_fpop; error = devfs_fp_check(fp, &dev, &dsw, &ref); if (error) @@ -1653,6 +1655,8 @@ devfs_write_f(struct file *fp, struct uio *uio, struct ucred *cred, struct cdevsw *dsw; struct file *fpop; + if (uio->uio_resid > DEVFS_IOSIZE_MAX) + return (EINVAL); fpop = td->td_fpop; error = devfs_fp_check(fp, &dev, &dsw, &ref); if (error) diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index d4d6293034ab..13ccb585f580 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -78,6 +78,10 @@ __FBSDID("$FreeBSD$"); int iosize_max_clamp = 1; SYSCTL_INT(_debug, OID_AUTO, iosize_max_clamp, CTLFLAG_RW, &iosize_max_clamp, 0, "Clamp max i/o size to INT_MAX"); +int devfs_iosize_max_clamp = 1; +SYSCTL_INT(_debug, OID_AUTO, devfs_iosize_max_clamp, CTLFLAG_RW, + &devfs_iosize_max_clamp, 0, "Clamp max i/o size to INT_MAX for devices"); + /* * Assert that the return value of read(2) and write(2) syscalls fits * into a register. If not, an architecture will need to provide the diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 2000e92a9dd3..b86f7a2357bd 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -146,7 +146,9 @@ extern const void *zero_region; /* address space maps to a zeroed page */ extern int unmapped_buf_allowed; extern int iosize_max_clamp; +extern int devfs_iosize_max_clamp; #define IOSIZE_MAX (iosize_max_clamp ? INT_MAX : SSIZE_MAX) +#define DEVFS_IOSIZE_MAX (devfs_iosize_max_clamp ? INT_MAX : SSIZE_MAX) /* * General function declarations.