Author: markj
Date: Tue Feb 26 14:59:41 2019
New Revision: 344582
URL: https://svnweb.freebsd.org/changeset/base/344582

Log:
  MFC r344307:
  Limit the number of entries allocated for a REPORT_ZONES command.
  
  admbug:       807

Modified:
  stable/11/sys/geom/geom_dev.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/geom/geom_dev.c
==============================================================================
--- stable/11/sys/geom/geom_dev.c       Tue Feb 26 14:56:01 2019        
(r344581)
+++ stable/11/sys/geom/geom_dev.c       Tue Feb 26 14:59:41 2019        
(r344582)
@@ -592,8 +592,10 @@ g_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data
                alloc_size = 0;
 
                if (zone_args->zone_cmd == DISK_ZONE_REPORT_ZONES) {
-
                        rep = &zone_args->zone_params.report;
+#define        MAXENTRIES      (MAXPHYS / sizeof(struct disk_zone_rep_entry))
+                       if (rep->entries_allocated > MAXENTRIES)
+                               rep->entries_allocated = MAXENTRIES;
                        alloc_size = rep->entries_allocated *
                            sizeof(struct disk_zone_rep_entry);
                        if (alloc_size != 0)
@@ -603,15 +605,11 @@ g_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data
                        rep->entries = new_entries;
                }
                error = g_io_zonecmd(zone_args, cp);
-               if ((zone_args->zone_cmd == DISK_ZONE_REPORT_ZONES)
-                && (alloc_size != 0)
-                && (error == 0)) {
+               if (zone_args->zone_cmd == DISK_ZONE_REPORT_ZONES &&
+                   alloc_size != 0 && error == 0)
                        error = copyout(new_entries, old_entries, alloc_size);
-               }
-               if ((old_entries != NULL)
-                && (rep != NULL))
+               if (old_entries != NULL && rep != NULL)
                        rep->entries = old_entries;
-
                if (new_entries != NULL)
                        g_free(new_entries);
                break;
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to