kern/179999: [ofed] [patch] Bug assigning HCA from IB to ETH

Shahar Klein shahark at
Thu Jul 4 12:50:02 UTC 2013

The following reply was made to PR kern/179999; it has been noted by GNATS.

From: Shahar Klein <shahark at>
To: John Baldwin <jhb at>, "bug-followup at"
	<bug-followup at>
Cc: Orit Moskovich <oritm at>, Oded Shanoon <odeds at>
Subject: RE: kern/179999: [ofed] [patch] Bug assigning HCA from IB to ETH
Date: Thu, 4 Jul 2013 12:34:09 +0000

 Thanks John
 I've tested this version and it works fine.
 Shahar Klein
 -----Original Message-----
 From: John Baldwin [mailto:jhb at]=20
 Sent: Friday, June 28, 2013 12:20 AM
 To: bug-followup at; Shahar Klein
 Subject: Re: kern/179999: [ofed] [patch] Bug assigning HCA from IB to ETH
 Thanks, I think the sysfs fix has a few issues though (it writes to buf[] e=
 ven if the copyin() fails, and it doesn't enforce a bounds check).  It does=
  seem that this should probably be using sysctl_handle_string() instead of =
 doing it by hand, but for now I've just adjusted your patch.  Can you pleas=
 e test this version?
 Index: ofed/drivers/net/mlx4/main.c
 --- ofed/drivers/net/mlx4/main.c	(revision 252306)
 +++ ofed/drivers/net/mlx4/main.c	(working copy)
 @@ -479,11 +479,11 @@
  	int i;
  	int err =3D 0;
 -	if (!strcmp(buf, "ib\n"))
 +	if (!strcmp(buf, "ib"))
  		info->tmp_type =3D MLX4_PORT_TYPE_IB;
 -	else if (!strcmp(buf, "eth\n"))
 +	else if (!strcmp(buf, "eth"))
  		info->tmp_type =3D MLX4_PORT_TYPE_ETH;
 -	else if (!strcmp(buf, "auto\n"))
 +	else if (!strcmp(buf, "auto"))
  		info->tmp_type =3D MLX4_PORT_TYPE_AUTO;
  	else {
  		mlx4_err(mdev, "%s is not supported port type\n", buf);
 Index: ofed/include/linux/sysfs.h
 --- ofed/include/linux/sysfs.h	(revision 252306)
 +++ ofed/include/linux/sysfs.h	(working copy)
 @@ -104,10 +104,15 @@
  	error =3D SYSCTL_OUT(req, buf, len);
  	if (error || !req->newptr || ops->store =3D=3D NULL)
  		goto out;
 -	error =3D SYSCTL_IN(req, buf, PAGE_SIZE);
 +	len =3D req->newlen - req->newidx;
 +	if (len >=3D PAGE_SIZE)
 +		error =3D EINVAL;
 +	else=20
 +		error =3D SYSCTL_IN(req, buf, len);
  	if (error)
  		goto out;
 -	len =3D ops->store(kobj, attr, buf, req->newlen);
 +	((char *)buf)[len] =3D '\0';
 +	len =3D ops->store(kobj, attr, buf, len);
  	if (len < 0)
  		error =3D -len;
 John Baldwin

More information about the freebsd-net mailing list