netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 9/9 v2] net: Add sysctl to trust checksum_complete
@ 2014-04-26 21:26 Tom Herbert
  2014-04-26 21:58 ` Ben Hutchings
  2014-04-27  2:31 ` Stephen Hemminger
  0 siblings, 2 replies; 8+ messages in thread
From: Tom Herbert @ 2014-04-26 21:26 UTC (permalink / raw)
  To: davem, netdev

Currently if a device provides CHECKSUM_COMPLETE but the checksum
is calculated to be invalid we recompute the checksum and try
again in software. On the other hand, if device returns
CHECKSUM_UNNECESSARY we implicitly trust it and don't verify what it
did. This seems backwards!

Add a sysctl to trust the device and report an invalid checksum when
CHECKSUM_COMPLETE shows it is incorrect. sysctl defaults to enabled.

Signed-off-by: Tom Herbert <therbert@google.com>
---
 include/linux/skbuff.h     | 7 ++++++-
 net/core/dev.c             | 3 +++
 net/core/sysctl_net_core.c | 7 +++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 3b14acc..f3c6018 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2763,6 +2763,8 @@ static inline __sum16 __skb_checksum_validate_unnecessary(struct sk_buff *skb,
 	return 1;
 }
 
+extern int sysctl_trust_dev_checksum;
+
 /*
  * Validate (init) checksum based on checksum complete.
  *
@@ -2775,9 +2777,12 @@ static inline __sum16 __skb_checksum_validate_complete(struct sk_buff *skb,
 						       __wsum psum)
 {
 	if (skb->ip_summed == CHECKSUM_COMPLETE) {
-		if (!csum_fold(csum_add(psum, skb->csum))) {
+		__sum16 csum = csum_fold(csum_add(psum, skb->csum));
+		if (!csum) {
 			skb->ip_summed = CHECKSUM_UNNECESSARY;
 			return 0;
+		} else if (sysctl_trust_dev_checksum) {
+			return csum;
 		}
 	}
 
diff --git a/net/core/dev.c b/net/core/dev.c
index 11d70e3..4f7980a 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2918,6 +2918,9 @@ int netdev_tstamp_prequeue __read_mostly = 1;
 int netdev_budget __read_mostly = 300;
 int weight_p __read_mostly = 64;            /* old backlog weight */
 
+int sysctl_trust_dev_checksum = 1;
+EXPORT_SYMBOL(sysctl_trust_dev_checksum);
+
 /* Called with irq disabled */
 static inline void ____napi_schedule(struct softnet_data *sd,
 				     struct napi_struct *napi)
diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index cf9cd13..246b9e3 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -263,6 +263,13 @@ static struct ctl_table net_core_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec
 	},
+	{
+		.procname	= "trust_dev_checksum",
+		.data		= &sysctl_trust_dev_checksum,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
 #ifdef CONFIG_BPF_JIT
 	{
 		.procname	= "bpf_jit_enable",
-- 
1.9.1.423.g4596e3a

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

end of thread, other threads:[~2014-04-28  4:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-26 21:26 [PATCH 9/9 v2] net: Add sysctl to trust checksum_complete Tom Herbert
2014-04-26 21:58 ` Ben Hutchings
2014-04-27  2:31 ` Stephen Hemminger
2014-04-27 17:03   ` Tom Herbert
2014-04-28  3:32     ` David Miller
2014-04-28  4:07       ` Tom Herbert
2014-04-28  4:15         ` David Miller
2014-04-28  4:22           ` Tom Herbert

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).