netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
To: ddecotig-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: ben-/+tVBieCtBitmTQ+vhA3Yw@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org,
	fcoe-devel-s9riP+hp16TNLxjTenLetw@public.gmane.org,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org,
	tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	edumazet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	eugenia-VPRAkNaXOzVS1MOuV/RT9w@public.gmane.org,
	ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
	idos-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
	joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org,
	saeedm-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
	_govind-KK0ffGbhmjU@public.gmane.org,
	VenkatKumar.Duvvuru-iH1Dq9VlAzfQT0dZR+AlfA@public.gmane.org,
	jeffrey.t.kirsher-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	pshelar-l0M0P4e3n4LQT0dZR+AlfA@public.gmane.org,
	eswierk-FilZDy9cOaHkQYj/0HfcvtBPR1lH4CV8@public.gmane.org,
	robert.w.love-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	JBottomley-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org,
	Yuval.Mintz-h88ZbnxC6KDQT0dZR+AlfA@public.gmane.org,
	linux-qQsb+v5E8BnlAoU/VqSP6n9LOBIZ5rWg@public.gmane.org,
	decot-Ypc/8FJVVoBWk0Htik3J/w@public.gmane.org
Subject: Re: [PATCH net-next v5 05/19] net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API
Date: Wed, 16 Dec 2015 11:38:14 -0500 (EST)	[thread overview]
Message-ID: <20151216.113814.2025166082777387327.davem@davemloft.net> (raw)
In-Reply-To: <1450127046-4573-6-git-send-email-ddecotig-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

From: David Decotigny <ddecotig-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Mon, 14 Dec 2015 13:03:52 -0800

> +static int ethtool_get_ksettings(struct net_device *dev, void __user *useraddr)
> +{
 ...
> +	if (__ETHTOOL_LINK_MODE_MASK_NU32
> +	    != ksettings.parent.link_mode_masks_nwords) {
> +		/* wrong link mode nbits requested */
> +		memset(&ksettings, 0, sizeof(ksettings));
> +		/* keep cmd field reset to 0 */
> +		/* send back number of words required as negative val */
> +		compiletime_assert(__ETHTOOL_LINK_MODE_MASK_NU32 <= S8_MAX,
> +				   "need too many bits for link modes!");
> +		ksettings.parent.link_mode_masks_nwords
> +			= -((s8)__ETHTOOL_LINK_MODE_MASK_NU32);

I'm trying to understand how this can work.

Supposedly, the link_mode_masks_nwords field is there so that we can
add new link modes yet still work with tools built against any
particular link mode list in the UAPI header files.

But here you're forcing the value of link_mode_masks_nwords and then
copying that amount back to userspace.  If the user allocated less
space than the the link mode list in the kernel supports, we will
overwrite past the end of the user's usettings object.

You cannot unconditionally copy sizeof(usettings) back to the user,
as store_ksettings_for_user() will do.

I think you have to truncate here, copying only the array elements the
user's structure actually has space for.  That's the only way this can
work.

  parent reply	other threads:[~2015-12-16 16:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-14 21:03 [PATCH net-next v5 00/19] new ETHTOOL_GSETTINGS/SSETTINGS API David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 01/19] lib/bitmap.c: conversion routines to/from u32 array David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 02/19] test_bitmap: unit tests for lib/bitmap.c David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 03/19] net: usnic: remove unused call to ethtool_ops::get_settings David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 04/19] net: usnic: use __ethtool_get_settings David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 05/19] net: ethtool: add new ETHTOOL_GSETTINGS/SSETTINGS API David Decotigny
     [not found]   ` <1450127046-4573-6-git-send-email-ddecotig-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-12-16 16:38     ` David Miller [this message]
2015-12-17  0:26       ` David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 06/19] tx4939: use __ethtool_get_ksettings David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 07/19] net: usnic: " David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 08/19] net: bonding: " David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 09/19] net: ipvlan: " David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 10/19] net: macvlan: " David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 11/19] net: team: " David Decotigny
2015-12-14 21:03 ` [PATCH net-next v5 12/19] net: fcoe: " David Decotigny
2015-12-14 21:04 ` [PATCH net-next v5 13/19] net: rdma: " David Decotigny
2015-12-14 21:04 ` [PATCH net-next v5 14/19] net: 8021q: " David Decotigny
2015-12-14 21:04 ` [PATCH net-next v5 15/19] net: bridge: " David Decotigny
     [not found] ` <1450127046-4573-1-git-send-email-ddecotig-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-12-14 21:04   ` [PATCH net-next v5 16/19] net: core: " David Decotigny
2015-12-14 21:04 ` [PATCH net-next v5 17/19] net: ethtool: remove unused __ethtool_get_settings David Decotigny
2015-12-14 21:04 ` [PATCH net-next v5 18/19] net: mlx4: convenience predicate for debug messages David Decotigny
2015-12-14 21:04 ` [PATCH net-next v5 19/19] net: mlx4: use new ETHTOOL_G/SSETTINGS API David Decotigny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151216.113814.2025166082777387327.davem@davemloft.net \
    --to=davem-ft/pcqaiutieiz0/mpfg9q@public.gmane.org \
    --cc=JBottomley-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org \
    --cc=VenkatKumar.Duvvuru-iH1Dq9VlAzfQT0dZR+AlfA@public.gmane.org \
    --cc=Yuval.Mintz-h88ZbnxC6KDQT0dZR+AlfA@public.gmane.org \
    --cc=_govind-KK0ffGbhmjU@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=ben-/+tVBieCtBitmTQ+vhA3Yw@public.gmane.org \
    --cc=ddecotig-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=decot-Ypc/8FJVVoBWk0Htik3J/w@public.gmane.org \
    --cc=edumazet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=eswierk-FilZDy9cOaHkQYj/0HfcvtBPR1lH4CV8@public.gmane.org \
    --cc=eugenia-VPRAkNaXOzVS1MOuV/RT9w@public.gmane.org \
    --cc=fcoe-devel-s9riP+hp16TNLxjTenLetw@public.gmane.org \
    --cc=idos-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=jeffrey.t.kirsher-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=joe-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org \
    --cc=linux-qQsb+v5E8BnlAoU/VqSP6n9LOBIZ5rWg@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=pshelar-l0M0P4e3n4LQT0dZR+AlfA@public.gmane.org \
    --cc=robert.w.love-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=saeedm-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).