Author: kib
Date: Tue Oct 15 06:33:10 2013
New Revision: 256502
URL: http://svnweb.freebsd.org/changeset/base/256502

Log:
  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 <trtrmi...@gmail.com>
  MFC after:    1 week

Modified:
  head/sys/fs/devfs/devfs_vnops.c
  head/sys/kern/sys_generic.c
  head/sys/sys/systm.h

Modified: head/sys/fs/devfs/devfs_vnops.c
==============================================================================
--- head/sys/fs/devfs/devfs_vnops.c     Tue Oct 15 06:28:11 2013        
(r256501)
+++ head/sys/fs/devfs/devfs_vnops.c     Tue Oct 15 06:33:10 2013        
(r256502)
@@ -1178,6 +1178,8 @@ devfs_read_f(struct file *fp, struct uio
        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 ui
        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)

Modified: head/sys/kern/sys_generic.c
==============================================================================
--- head/sys/kern/sys_generic.c Tue Oct 15 06:28:11 2013        (r256501)
+++ head/sys/kern/sys_generic.c Tue Oct 15 06:33:10 2013        (r256502)
@@ -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

Modified: head/sys/sys/systm.h
==============================================================================
--- head/sys/sys/systm.h        Tue Oct 15 06:28:11 2013        (r256501)
+++ head/sys/sys/systm.h        Tue Oct 15 06:33:10 2013        (r256502)
@@ -146,7 +146,9 @@ extern const void *zero_region;     /* addre
 
 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.
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to