svn commit: r193438 - in stable/7/sys: . contrib/pf dev/ath/ath_hal dev/cxgb kern

Konstantin Belousov kib at FreeBSD.org
Thu Jun 4 15:10:30 UTC 2009


Author: kib
Date: Thu Jun  4 15:10:29 2009
New Revision: 193438
URL: http://svn.freebsd.org/changeset/base/193438

Log:
  MFC r192094:
  Do not advance req->oldidx when sysctl_old_user returning an
  error due to copyout failure or short buffer.
  
  MFC r192144:
  Revert r192094. The revision caused problems for sysctl(3) consumers
  that expect that oldlen is filled with required buffer length even when
  supplied buffer is too short and returned error is ENOMEM.
  
  Redo the fix for kern.proc.filedesc, by reverting the req->oldidx when
  remaining buffer space is too short for the current kinfo_file structure.
  Also, only ignore ENOMEM. We have to convert ENOMEM to no error condition
  to keep existing interface for the sysctl, though.

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/dev/ath/ath_hal/   (props changed)
  stable/7/sys/dev/cxgb/   (props changed)
  stable/7/sys/kern/kern_descrip.c

Modified: stable/7/sys/kern/kern_descrip.c
==============================================================================
--- stable/7/sys/kern/kern_descrip.c	Thu Jun  4 14:49:27 2009	(r193437)
+++ stable/7/sys/kern/kern_descrip.c	Thu Jun  4 15:10:29 2009	(r193438)
@@ -2866,6 +2866,7 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER
 	struct file *fp;
 	struct proc *p;
 	int vfslocked;
+	size_t oldidx;
 
 	name = (int *)arg1;
 	if ((p = pfind((pid_t)name[0])) == NULL)
@@ -3032,14 +3033,26 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER
 		    strlen(kif->kf_path) + 1;
 		kif->kf_structsize = roundup(kif->kf_structsize,
 		    sizeof(uint64_t));
+		oldidx = req->oldidx;
 		error = SYSCTL_OUT(req, kif, kif->kf_structsize);
-		if (error)
+		if (error) {
+			if (error == ENOMEM) {
+				/*
+				 * The hack to keep the ABI of sysctl
+				 * kern.proc.filedesc intact, but not
+				 * to account a partially copied
+				 * kinfo_file into the oldidx.
+				 */
+				req->oldidx = oldidx;
+				error = 0;
+			}
 			break;
+		}
 	}
 	FILEDESC_SUNLOCK(fdp);
 	fddrop(fdp);
 	free(kif, M_TEMP);
-	return (0);
+	return (error);
 }
 
 static SYSCTL_NODE(_kern_proc, KERN_PROC_FILEDESC, filedesc, CTLFLAG_RD,


More information about the svn-src-all mailing list