From b17dcb99726427b6f7a26be8c46023c5d7d15e08 Mon Sep 17 00:00:00 2001 From: Alexander Duyck Date: Fri, 13 Jul 2012 09:55:29 -0700 Subject: ethtool: Resolve use of uninitialized memory in rxclass_get_dev_info The ethtool function for getting the rule count was not zeroing out the data field before passing it to the kernel. As a result the value started uninitialized and was incorrectly returning a result indicating that devices supported setting new rule indexes. In order to correct this I am adding a one line fix that sets data to zero before we pass the command to the kernel. Signed-off-by: Alexander Duyck Signed-off-by: Ben Hutchings --- rxclass.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rxclass.c b/rxclass.c index 4d49aa6..e1633a8 100644 --- a/rxclass.c +++ b/rxclass.c @@ -207,6 +207,7 @@ static int rxclass_get_dev_info(struct cmd_context *ctx, __u32 *count, int err; nfccmd.cmd = ETHTOOL_GRXCLSRLCNT; + nfccmd.data = 0; err = send_ioctl(ctx, &nfccmd); *count = nfccmd.rule_cnt; if (driver_select) -- cgit v1.2.1 From b982755ffffb67ef8c5738707fbf8a1a8685d99b Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Mon, 16 Jul 2012 21:48:39 +0100 Subject: Remove bogus error message when changing offload settings on Linux < 2.6.39 We should not be checking for fixed features when we have no information about which are fixed. Signed-off-by: Ben Hutchings --- ethtool.c | 60 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/ethtool.c b/ethtool.c index 3c34273..b424756 100644 --- a/ethtool.c +++ b/ethtool.c @@ -1962,39 +1962,45 @@ static int do_sfeatures(struct cmd_context *ctx) if (!old_state) return 1; - /* For each offload that the user specified, update any - * related features that the user did not specify and that - * are not fixed. Warn if all related features are fixed. - */ - for (i = 0; i < ARRAY_SIZE(off_flag_def); i++) { - int fixed = 1; - - if (!(off_flags_mask & off_flag_def[i].value)) - continue; + if (efeatures) { + /* For each offload that the user specified, update any + * related features that the user did not specify and that + * are not fixed. Warn if all related features are fixed. + */ + for (i = 0; i < ARRAY_SIZE(off_flag_def); i++) { + int fixed = 1; - for (j = 0; j < defs->n_features; j++) { - if (defs->def[j].off_flag_index != i || - !FEATURE_BIT_IS_SET(old_state->features.features, - j, available) || - FEATURE_BIT_IS_SET(old_state->features.features, - j, never_changed)) + if (!(off_flags_mask & off_flag_def[i].value)) continue; - fixed = 0; - if (!FEATURE_BIT_IS_SET(efeatures->features, j, valid)) { - FEATURE_BIT_SET(efeatures->features, j, valid); - if (off_flags_wanted & off_flag_def[i].value) - FEATURE_BIT_SET(efeatures->features, j, - requested); + for (j = 0; j < defs->n_features; j++) { + if (defs->def[j].off_flag_index != i || + !FEATURE_BIT_IS_SET( + old_state->features.features, + j, available) || + FEATURE_BIT_IS_SET( + old_state->features.features, + j, never_changed)) + continue; + + fixed = 0; + if (!FEATURE_BIT_IS_SET(efeatures->features, + j, valid)) { + FEATURE_BIT_SET(efeatures->features, + j, valid); + if (off_flags_wanted & + off_flag_def[i].value) + FEATURE_BIT_SET( + efeatures->features, + j, requested); + } } - } - if (fixed) - fprintf(stderr, "Cannot change %s\n", - off_flag_def[i].long_name); - } + if (fixed) + fprintf(stderr, "Cannot change %s\n", + off_flag_def[i].long_name); + } - if (efeatures) { err = send_ioctl(ctx, efeatures); if (err < 0) { perror("Cannot set device feature settings"); -- cgit v1.2.1 From 1cddbe64cfc66b58988c85086d6df3a77c0c61a5 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Mon, 16 Jul 2012 22:56:05 +0100 Subject: Fix reporting of VLAN tag offload flags on Linux < 2.6.37 These kernel versions implement ETHTOOL_GFLAGS but do not include the flags for VLAN tag offload (and do not implement ETHTOOL_GFEATURES). Since the VLAN tag offload features were already defined and implemented by many drivers, we shouldn't assume they are off. Instead, since these feature flag values were stable, read them from sysfs. Signed-off-by: Ben Hutchings --- ethtool.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ethtool.c b/ethtool.c index b424756..9991ce2 100644 --- a/ethtool.c +++ b/ethtool.c @@ -33,6 +33,8 @@ #include #include #include +#include +#include #include #include @@ -1417,6 +1419,31 @@ static struct feature_defs *get_feature_defs(struct cmd_context *ctx) return defs; } +static int get_netdev_attr(struct cmd_context *ctx, const char *name, + char *buf, size_t buf_len) +{ +#ifdef TEST_ETHTOOL + errno = ENOENT; + return -1; +#else + char path[40 + IFNAMSIZ]; + ssize_t len; + int fd; + + len = snprintf(path, sizeof(path), "/sys/class/net/%s/%s", + ctx->devname, name); + assert(len < sizeof(path)); + fd = open(path, O_RDONLY); + if (fd < 0) + return fd; + len = read(fd, buf, buf_len - 1); + if (len >= 0) + buf[len] = 0; + close(fd); + return len; +#endif +} + static int do_gdrv(struct cmd_context *ctx) { int err; @@ -1858,6 +1885,20 @@ get_features(struct cmd_context *ctx, const struct feature_defs *defs) perror("Cannot get device generic features"); else allfail = 0; + } else { + /* We should have got VLAN tag offload flags through + * ETHTOOL_GFLAGS. However, prior to Linux 2.6.37 + * they were not exposed in this way - and since VLAN + * tag offload was defined and implemented by many + * drivers, we shouldn't assume they are off. + * Instead, since these feature flag values were + * stable, read them from sysfs. + */ + char buf[20]; + if (get_netdev_attr(ctx, "features", buf, sizeof(buf)) > 0) + state->off_flags |= + strtoul(buf, NULL, 0) & + (ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN); } if (allfail) { -- cgit v1.2.1 From 033c782976469f95128d146e85cbd02f3ff46c10 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Mon, 16 Jul 2012 23:31:28 +0100 Subject: Release version 3.4.2. Signed-off-by: Ben Hutchings --- NEWS | 9 +++++++++ configure.ac | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index b72df24..78bd0d7 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,12 @@ +Version 3.4.2 - July 16, 2012 + + * Fix: Fix regression in RX NFC rule insertion for drivers that do + not select rule locations (-N/-U option) + * Fix: Remove bogus error message when changing offload settings + on Linux < 2.6.39 (-K option) + * Fix: Use alternate method to check for VLAN tag offload on Linux + < 2.6.37 (-k option) + Version 3.4.1 - June 13, 2012 * Fix: Work around failure of ETHTOOL_GSSET_INFO for unprivileged diff --git a/configure.ac b/configure.ac index 11b4935..16d8e62 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl Process this file with autoconf to produce a configure script. -AC_INIT(ethtool, 3.4.1, netdev@vger.kernel.org) +AC_INIT(ethtool, 3.4.2, netdev@vger.kernel.org) AC_PREREQ(2.52) AC_CONFIG_SRCDIR([ethtool.c]) AM_INIT_AUTOMAKE([gnu]) -- cgit v1.2.1