Skip to contentSkip to conversation

ipv6: Add ipv6_renew_options_kern() that accepts a kernel mem pointer.

RFC PATCH Superseded Huw Davies 2 participants 3 messages Jan 8, 2016 – Feb 11, 2016

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Huw Davies

author
#0 lore raw

RFC PATCH v2 8/18 ipv6: Add ipv6_renew_options_kern() that accepts a kernel mem pointer.

The functionality is equivalent to ipv6_renew_options() except that the newopt pointer is in kernel, not user, memory

The kernel memory implementation will be used by the CALIPSO network labelling engine, which needs to be able to set IPv6 hop-by-hop options.

---
 include/net/ipv6.h |  6 ++++++
 net/ipv6/exthdrs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
include/net/ipv6.h +6 -0
index 9a5c9f0..5a72ffd 100644
@@ -304,6 +304,12 @@ struct ipv6_txoptions *ipv6_renew_options(struct sock *sk,
 					  int newtype,
 					  struct ipv6_opt_hdr __user *newopt,
 					  int newoptlen);
+struct ipv6_txoptions *
+ipv6_renew_options_kern(struct sock *sk,
+			struct ipv6_txoptions *opt,
+			int newtype,
+			struct ipv6_opt_hdr *newopt,
+			int newoptlen);
 struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,
 					  struct ipv6_txoptions *opt);
 
net/ipv6/exthdrs.c +49 -0

61 lines not on this page · raw message

Signature · 1 line
1.8.0
#1 lore raw
Quoted 8 lines · Huw Davies

The functionality is equivalent to ipv6_renew_options() except that the newopt pointer is in kernel, not user, memory

The kernel memory implementation will be used by the CALIPSO network labelling engine, which needs to be able to set IPv6 hop-by-hop options.

...

Quoted 17 lines
net/ipv6/exthdrs.c +17 -0
+/**
+ * ipv6_renew_options_kern - replace a specific ext hdr with a new one.
+ *
+ * @sk: sock from which to allocate memory
+ * @opt: original options
+ * @newtype: option type to replace in @opt
+ * @newopt: new option of type @newtype to replace (kernel-mem)
+ * @newoptlen: length of @newopt
+ *
+ * See ipv6_renew_options().  The difference is that @newopt is
+ * kernel memory, rather than user memory.
+ */
+struct ipv6_txoptions *
+ipv6_renew_options_kern(struct sock *sk, struct ipv6_txoptions *opt,
+			int newtype, struct ipv6_opt_hdr *newopt,
+			int newoptlen)
+{

net/ipv6/exthdrs.c out: · line 880

Quoted 10 lines
net/ipv6/exthdrs.c +10 -0
+	struct ipv6_txoptions *ret_val;
+	const mm_segment_t old_fs = get_fs();
+
+	set_fs(KERNEL_DS);
+	ret_val = ipv6_renew_options(sk, opt, newtype,
+				     (struct ipv6_opt_hdr __user *)newopt,
+				     newoptlen);
+	set_fs(old_fs);
+	return ret_val;
+}

I should preface this by saying that I don't have a strong opinion on this either way, and given where the code lives it is really up to DaveM, but I wonder if it might be better to create ipv6_renew_options_kern() as the common helper function that is called by ipv6_renew_options().

Signature · 2 lines
paul moore
security @ redhat
author
#2 lore raw
Quoted 36 lines · Paul Moore
Quoted 8 lines · Huw Davies

The functionality is equivalent to ipv6_renew_options() except that the newopt pointer is in kernel, not user, memory

The kernel memory implementation will be used by the CALIPSO network labelling engine, which needs to be able to set IPv6 hop-by-hop options.

...

Quoted 24 lines
net/ipv6/exthdrs.c +24 -0
+/**
+ * ipv6_renew_options_kern - replace a specific ext hdr with a new one.
+ *
+ * @sk: sock from which to allocate memory
+ * @opt: original options
+ * @newtype: option type to replace in @opt
+ * @newopt: new option of type @newtype to replace (kernel-mem)
+ * @newoptlen: length of @newopt
+ *
+ * See ipv6_renew_options().  The difference is that @newopt is
+ * kernel memory, rather than user memory.
+ */
+struct ipv6_txoptions *
+ipv6_renew_options_kern(struct sock *sk, struct ipv6_txoptions *opt,
+			int newtype, struct ipv6_opt_hdr *newopt,
+			int newoptlen)
+{
+	struct ipv6_txoptions *ret_val;
+	const mm_segment_t old_fs = get_fs();
+
+	set_fs(KERNEL_DS);
+	ret_val = ipv6_renew_options(sk, opt, newtype,
+				     (struct ipv6_opt_hdr __user *)newopt,
+				     newoptlen);
Quoted 8 lines

net/ipv6/exthdrs.c out: · line 880

Quoted 3 lines
net/ipv6/exthdrs.c +3 -0
+	set_fs(old_fs);
+	return ret_val;
+}

I should preface this by saying that I don't have a strong opinion on this either way, and given where the code lives it is really up to DaveM, but I wonder if it might be better to create ipv6_renew_options_kern() as the common helper function that is called by ipv6_renew_options().

Ok, I'll leave this as it as for v3, and the network guys can shout if they want me to change it.

Huw.