Skip to contentSkip to conversation

set l2specific_len based on l2specific_type

PATCH Superseded Lorenzo Bianconi 2 participants 7 messages Jan 10, 2018

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover set l2specific_len based on l2specific_type

Do not rely on l2specific_len value provided by userspace but set sublayer length according to l2specific_type.

Lorenzo Bianconi (3):
l2tp: fix switch default error handling in
l2tp_nl_cmd_session_create()
l2tp: configure l2specific_len according to l2specific_type
l2tp: mark L2TP_ATTR_L2SPEC_LEN as not used

 include/uapi/linux/l2tp.h |  2 +-
 net/l2tp/l2tp_netlink.c   | 23 +++++++++++++++++------
 2 files changed, 18 insertions(+), 7 deletions(-)
Signature · 1 line
2.13.6
#1 lore raw

PATCH 1/3 l2tp: fix switch default error handling in l2tp_nl_cmd_session_create()

Although this issue is harmless since that code path is protected by the check on l2tp_nl_cmd_ops[]/l2tp_nl_cmd_ops[]->session_create(), fix error handling for L2TP_PWTYPE_IP/default case in l2tp_nl_cmd_session_create()

---
 net/l2tp/l2tp_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/l2tp/l2tp_netlink.c +1 -1
index e1ca29f79821..48b5bf30ec50 100644
@@ -635,7 +635,7 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf
 	case L2TP_PWTYPE_IP:
 	default:
 		ret = -EPROTONOSUPPORT;
-		break;
+		goto out_tunnel;
 	}
 
 	ret = l2tp_nl_cmd_ops[cfg.pw_type]->session_create(net, tunnel,
Signature · 1 line
2.13.6
#2 lore raw

PATCH 2/3 l2tp: configure l2specific_len according to l2specific_type

In reply to Lorenzo Bianconi

Set l2specific_len according to the L2-Specific Sublayer type specified by the userspace and not rely on a user supplied value for sublayer len since invalid usage of L2TP_ATTR_L2SPEC_LEN allows leaking memory on the network and sending corrupted frames.
Moreover add a sanity check on l2specific_type provided by userspace

---
 net/l2tp/l2tp_netlink.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
net/l2tp/l2tp_netlink.c +16 -5
index 48b5bf30ec50..404e5482c4e7 100644
@@ -550,13 +550,24 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf
 		if (info->attrs[L2TP_ATTR_DATA_SEQ])
 			cfg.data_seq = nla_get_u8(info->attrs[L2TP_ATTR_DATA_SEQ]);
 
-		cfg.l2specific_type = L2TP_L2SPECTYPE_DEFAULT;
-		if (info->attrs[L2TP_ATTR_L2SPEC_TYPE])
+		if (info->attrs[L2TP_ATTR_L2SPEC_TYPE]) {
 			cfg.l2specific_type = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_TYPE]);
 
-		cfg.l2specific_len = 4;
-		if (info->attrs[L2TP_ATTR_L2SPEC_LEN])
-			cfg.l2specific_len = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_LEN]);
+			switch (cfg.l2specific_type) {
+			case L2TP_L2SPECTYPE_DEFAULT:
+				cfg.l2specific_len = 4;
+				break;
+			case L2TP_L2SPECTYPE_NONE:
+				cfg.l2specific_len = 0;
+				break;
+			default:
+				ret = -EINVAL;
+				goto out_tunnel;
+			}
+		} else {
+			cfg.l2specific_type = L2TP_L2SPECTYPE_DEFAULT;
+			cfg.l2specific_len = 4;
+		}
 
 		if (info->attrs[L2TP_ATTR_COOKIE]) {
 			u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]);
Signature · 1 line
2.13.6
#5 lore raw

PATCH 3/3 l2tp: mark L2TP_ATTR_L2SPEC_LEN as not used

In reply to Lorenzo Bianconi
---
 include/uapi/linux/l2tp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/l2tp.h +1 -1
index 71e62795104d..ec609a017691 100644
@@ -97,7 +97,7 @@ enum {
 	L2TP_ATTR_OFFSET,		/* u16 (not used) */
 	L2TP_ATTR_DATA_SEQ,		/* u16 */
 	L2TP_ATTR_L2SPEC_TYPE,		/* u8, enum l2tp_l2spec_type */
-	L2TP_ATTR_L2SPEC_LEN,		/* u8, enum l2tp_l2spec_type */
+	L2TP_ATTR_L2SPEC_LEN,		/* u8, (not used) */
 	L2TP_ATTR_PROTO_VERSION,	/* u8 */
 	L2TP_ATTR_IFNAME,		/* string */
 	L2TP_ATTR_CONN_ID,		/* u32 */
Signature · 1 line
2.13.6
#3 lore raw

Re: [PATCH net-next 2/3] l2tp: configure l2specific_len according to l2specific_type

In reply to Lorenzo Bianconi
Quoted 36 lines · Lorenzo Bianconi

Set l2specific_len according to the L2-Specific Sublayer type specified by the userspace and not rely on a user supplied value for sublayer len since invalid usage of L2TP_ATTR_L2SPEC_LEN allows leaking memory on the network and sending corrupted frames.
Moreover add a sanity check on l2specific_type provided by userspace

---
 net/l2tp/l2tp_netlink.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
net/l2tp/l2tp_netlink.c +9 -5
index 48b5bf30ec50..404e5482c4e7 100644
@@ -550,13 +550,24 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf
 		if (info->attrs[L2TP_ATTR_DATA_SEQ])
 			cfg.data_seq = nla_get_u8(info->attrs[L2TP_ATTR_DATA_SEQ]);
 
-		cfg.l2specific_type = L2TP_L2SPECTYPE_DEFAULT;
-		if (info->attrs[L2TP_ATTR_L2SPEC_TYPE])
+		if (info->attrs[L2TP_ATTR_L2SPEC_TYPE]) {
 			cfg.l2specific_type = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_TYPE]);
 
-		cfg.l2specific_len = 4;
-		if (info->attrs[L2TP_ATTR_L2SPEC_LEN])
-			cfg.l2specific_len = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_LEN]);
+			switch (cfg.l2specific_type) {
+			case L2TP_L2SPECTYPE_DEFAULT:
+				cfg.l2specific_len = 4;
+				break;
+			case L2TP_L2SPECTYPE_NONE:
+				cfg.l2specific_len = 0;
+				break;
+			default:

net/l2tp/l2tp_netlink.c static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf · line 573

Quoted 10 lines
net/l2tp/l2tp_netlink.c +7 -0
+				ret = -EINVAL;
+				goto out_tunnel;
+			}
+		} else {
+			cfg.l2specific_type = L2TP_L2SPECTYPE_DEFAULT;
+			cfg.l2specific_len = 4;
+		}
 
 		if (info->attrs[L2TP_ATTR_COOKIE]) {
 			u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]);

I think we can go one step further and remove .l2specific_len from struct l2tp_session and struct l2tp_session_cfg. We never need this information. Then we can start ignoring the L2TP_ATTR_L2SPEC_LEN attribute just like we've done with L2TP_ATTR_OFFSET.

#6 lore raw

Re: [PATCH net-next 3/3] l2tp: mark L2TP_ATTR_L2SPEC_LEN as not used

In reply to Lorenzo Bianconi
Quoted 10 lines · Lorenzo Bianconi
---
 include/uapi/linux/l2tp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/l2tp.h +0 -0
index 71e62795104d..ec609a017691 100644

include/uapi/linux/l2tp.h enum { · line 101

Quoted 6 lines
include/uapi/linux/l2tp.h +1 -1
@@ -97,7 +97,7 @@ enum {
 	L2TP_ATTR_OFFSET,		/* u16 (not used) */
 	L2TP_ATTR_DATA_SEQ,		/* u16 */
 	L2TP_ATTR_L2SPEC_TYPE,		/* u8, enum l2tp_l2spec_type */
-	L2TP_ATTR_L2SPEC_LEN,		/* u8, enum l2tp_l2spec_type */
+	L2TP_ATTR_L2SPEC_LEN,		/* u8, (not used) */
 

Nitpick: if you repost this series, you can remove the comma between 'u8' and '(not used)' (to keep the format used by L2TP_ATTR_OFFSET).

#4 lore raw

Re: [PATCH net-next 2/3] l2tp: configure l2specific_len according to l2specific_type

In reply to Guillaume Nault
Quoted 44 lines · Lorenzo Bianconi
Quoted 43 lines

Set l2specific_len according to the L2-Specific Sublayer type specified by the userspace and not rely on a user supplied value for sublayer len since invalid usage of L2TP_ATTR_L2SPEC_LEN allows leaking memory on the network and sending corrupted frames.
Moreover add a sanity check on l2specific_type provided by userspace

---
 net/l2tp/l2tp_netlink.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
net/l2tp/l2tp_netlink.c +16 -5
index 48b5bf30ec50..404e5482c4e7 100644
@@ -550,13 +550,24 @@ static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf
              if (info->attrs[L2TP_ATTR_DATA_SEQ])
                      cfg.data_seq = nla_get_u8(info->attrs[L2TP_ATTR_DATA_SEQ]);
 
-             cfg.l2specific_type = L2TP_L2SPECTYPE_DEFAULT;
-             if (info->attrs[L2TP_ATTR_L2SPEC_TYPE])
+             if (info->attrs[L2TP_ATTR_L2SPEC_TYPE]) {
                      cfg.l2specific_type = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_TYPE]);
 
-             cfg.l2specific_len = 4;
-             if (info->attrs[L2TP_ATTR_L2SPEC_LEN])
-                     cfg.l2specific_len = nla_get_u8(info->attrs[L2TP_ATTR_L2SPEC_LEN]);
+                     switch (cfg.l2specific_type) {
+                     case L2TP_L2SPECTYPE_DEFAULT:
+                             cfg.l2specific_len = 4;
+                             break;
+                     case L2TP_L2SPECTYPE_NONE:
+                             cfg.l2specific_len = 0;
+                             break;
+                     default:
+                             ret = -EINVAL;
+                             goto out_tunnel;
+                     }
+             } else {
+                     cfg.l2specific_type = L2TP_L2SPECTYPE_DEFAULT;
+                     cfg.l2specific_len = 4;
+             }
 
Quoted 7 lines

net/l2tp/l2tp_netlink.c static int l2tp_nl_cmd_session_create(struct sk_buff *skb, struct genl_info *inf · line 573

Quoted 3 lines
net/l2tp/l2tp_netlink.c +0 -0
              if (info->attrs[L2TP_ATTR_COOKIE]) {
                      u16 len = nla_len(info->attrs[L2TP_ATTR_COOKIE]);

I think we can go one step further and remove .l2specific_len from struct l2tp_session and struct l2tp_session_cfg. We never need this information. Then we can start ignoring the L2TP_ATTR_L2SPEC_LEN attribute just like we've done with L2TP_ATTR_OFFSET.

Hi Guillaume,

I was thinking about it, let's way for some feedbacks and then I can respin a v2.
Regards,

Lorenzo