LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH net] ethtool: fix application of verbose no_mask bitset
@ 2020-02-15  0:55 Michal Kubecek
  2020-02-17  3:29 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Michal Kubecek @ 2020-02-15  0:55 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, netdev; +Cc: linux-kernel

A bitset without mask in a _SET request means we want exactly the bits in
the bitset to be set. This works correctly for compact format but when
verbose format is parsed, ethnl_update_bitset32_verbose() only sets the
bits present in the request bitset but does not clear the rest. This can
cause incorrect results like

  lion:~ # ethtool eth0 | grep Wake
          Supports Wake-on: pumbg
          Wake-on: g
  lion:~ # ethtool -s eth0 wol u
  lion:~ # ethtool eth0 | grep Wake
          Supports Wake-on: pumbg
          Wake-on: ug

when the second ethtool command issues request

ETHTOOL_MSG_WOL_SET
    ETHTOOL_A_WOL_HEADER
        ETHTOOL_A_HEADER_DEV_NAME = "eth0"
    ETHTOOL_A_WOL_MODES
        ETHTOOL_A_BITSET_NOMASK
        ETHTOOL_A_BITSET_BITS
            ETHTOOL_A_BITSET_BITS_BIT
                ETHTOOL_BITSET_BIT_INDEX = 1

Fix the logic by clearing the whole target bitmap before we start iterating
through the request bits.

Fixes: 10b518d4e6dd ("ethtool: netlink bitset handling")
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 net/ethtool/bitset.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/ethtool/bitset.c b/net/ethtool/bitset.c
index fce45dac4205..8977fe1f3946 100644
--- a/net/ethtool/bitset.c
+++ b/net/ethtool/bitset.c
@@ -447,7 +447,10 @@ ethnl_update_bitset32_verbose(u32 *bitmap, unsigned int nbits,
 				    "mask only allowed in compact bitset");
 		return -EINVAL;
 	}
+
 	no_mask = tb[ETHTOOL_A_BITSET_NOMASK];
+	if (no_mask)
+		ethnl_bitmap32_clear(bitmap, 0, nbits, mod);
 
 	nla_for_each_nested(bit_attr, tb[ETHTOOL_A_BITSET_BITS], rem) {
 		bool old_val, new_val;
-- 
2.25.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net] ethtool: fix application of verbose no_mask bitset
  2020-02-15  0:55 [PATCH net] ethtool: fix application of verbose no_mask bitset Michal Kubecek
@ 2020-02-17  3:29 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-02-17  3:29 UTC (permalink / raw)
  To: mkubecek; +Cc: kuba, netdev, linux-kernel

From: Michal Kubecek <mkubecek@suse.cz>
Date: Sat, 15 Feb 2020 01:55:53 +0100 (CET)

> A bitset without mask in a _SET request means we want exactly the bits in
> the bitset to be set. This works correctly for compact format but when
> verbose format is parsed, ethnl_update_bitset32_verbose() only sets the
> bits present in the request bitset but does not clear the rest. This can
> cause incorrect results like
> 
>   lion:~ # ethtool eth0 | grep Wake
>           Supports Wake-on: pumbg
>           Wake-on: g
>   lion:~ # ethtool -s eth0 wol u
>   lion:~ # ethtool eth0 | grep Wake
>           Supports Wake-on: pumbg
>           Wake-on: ug
> 
> when the second ethtool command issues request
> 
> ETHTOOL_MSG_WOL_SET
>     ETHTOOL_A_WOL_HEADER
>         ETHTOOL_A_HEADER_DEV_NAME = "eth0"
>     ETHTOOL_A_WOL_MODES
>         ETHTOOL_A_BITSET_NOMASK
>         ETHTOOL_A_BITSET_BITS
>             ETHTOOL_A_BITSET_BITS_BIT
>                 ETHTOOL_BITSET_BIT_INDEX = 1
> 
> Fix the logic by clearing the whole target bitmap before we start iterating
> through the request bits.
> 
> Fixes: 10b518d4e6dd ("ethtool: netlink bitset handling")
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>

Applied, thanks Michal.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-15  0:55 [PATCH net] ethtool: fix application of verbose no_mask bitset Michal Kubecek
2020-02-17  3:29 ` David Miller

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git