Skip to contentSkip to conversation

ipvsadm: Fix svc->pe_name conditional

PATCH Superseded Ryan O'Hara 3 participants 8 messages Aug 18, 2013 – Aug 20, 2013 IPVS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipvsadm: Fix svc->pe_name conditional

The pe_name in ipvs_service_t is an array, so comparing it NULL has no effect. Use strlen to see if pe_name is set.

---
 libipvs/libipvs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libipvs/libipvs.c +1 -1
index c3c3b0a..ebc46e9 100644
@@ -229,7 +229,7 @@ static int ipvs_nl_fill_service_attr(struct nl_msg *msg, ipvs_service_t *svc)
 	}
 
 	NLA_PUT_STRING(msg, IPVS_SVC_ATTR_SCHED_NAME, svc->sched_name);
-	if (svc->pe_name)
+	if (strlen(svc->pe_name))
 		NLA_PUT_STRING(msg, IPVS_SVC_ATTR_PE_NAME, svc->pe_name);
 	NLA_PUT(msg, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags);
 	NLA_PUT_U32(msg, IPVS_SVC_ATTR_TIMEOUT, svc->timeout);
Signature · 1 line
1.8.1.4
maintainer Acked-by on v1 1/1
#1 lore raw

Hello,

Quoted 4 lines · Ryan O'Hara

The pe_name in ipvs_service_t is an array, so comparing it NULL has no effect. Use strlen to see if pe_name is set.

Looks good to me.

	Or may be we can avoid strlen? Eg. svc->pe_name[0] ?

	It looks like CHECK_PE has similar problem and more:

- Do we really work without NL support if CHECK_PE always succeeds in 'if (s->pe_name)'? I have a doubt.

- CHECK_PE and CHECK_IPV4 as part of CHECK_COMPAT_SVC use 'return' and we can leak svc in ipvs_get_service()

- in ipvs_get_service() CHECK_PE does not need to be called, it is already part of CHECK_COMPAT_SVC

- ipvs_get_service uses malloc but later calls CHECK_PE, may be malloc should be changed with calloc

Quoted 19 lines
---
 libipvs/libipvs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libipvs/libipvs.c +1 -1
index c3c3b0a..ebc46e9 100644
@@ -229,7 +229,7 @@ static int ipvs_nl_fill_service_attr(struct nl_msg *msg, ipvs_service_t *svc)
 	}
 
 	NLA_PUT_STRING(msg, IPVS_SVC_ATTR_SCHED_NAME, svc->sched_name);
-	if (svc->pe_name)
+	if (strlen(svc->pe_name))
 		NLA_PUT_STRING(msg, IPVS_SVC_ATTR_PE_NAME, svc->pe_name);
 	NLA_PUT(msg, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags);
 	NLA_PUT_U32(msg, IPVS_SVC_ATTR_TIMEOUT, svc->timeout);
Signature · 1 line
1.8.1.4

Regards

--
Julian Anastasov <[email protected]>

#2 lore raw
Quoted 8 lines · Julian Anastasov

Hello,

Quoted 3 lines · Ryan O'Hara

The pe_name in ipvs_service_t is an array, so comparing it NULL has no effect. Use strlen to see if pe_name is set.

Quoted 7 lines
Quoted 1 line

Looks good to me.

	Or may be we can avoid strlen? Eg. svc->pe_name[0] ?

Agree. I'll resend the patch without strlen.

Quoted 4 lines

It looks like CHECK_PE has similar problem and more:

- Do we really work without NL support if CHECK_PE always succeeds in 'if (s->pe_name)'? I have a doubt.

Not sure about this. I've always been under the impression that NL is absolutely required.

Quoted 5 lines

- CHECK_PE and CHECK_IPV4 as part of CHECK_COMPAT_SVC use 'return' and we can leak svc in ipvs_get_service()

- in ipvs_get_service() CHECK_PE does not need to be called, it is already part of CHECK_COMPAT_SVC

Yes. I'm tempted to remove these macros due to the 'return' issue. Thoughts?

Quoted 2 lines

- ipvs_get_service uses malloc but later calls CHECK_PE, may be malloc should be changed with calloc

Aside from the fact that CHECK_PE could return without freeing memory, I don't see the problem here.

Ryan

Quoted 24 lines
Quoted 19 lines
---
 libipvs/libipvs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libipvs/libipvs.c +1 -1
index c3c3b0a..ebc46e9 100644
@@ -229,7 +229,7 @@ static int ipvs_nl_fill_service_attr(struct nl_msg *msg, ipvs_service_t *svc)
 	}
 
 	NLA_PUT_STRING(msg, IPVS_SVC_ATTR_SCHED_NAME, svc->sched_name);
-	if (svc->pe_name)
+	if (strlen(svc->pe_name))
 		NLA_PUT_STRING(msg, IPVS_SVC_ATTR_PE_NAME, svc->pe_name);
 	NLA_PUT(msg, IPVS_SVC_ATTR_FLAGS, sizeof(flags), &flags);
 	NLA_PUT_U32(msg, IPVS_SVC_ATTR_TIMEOUT, svc->timeout);
Signature · 1 line
1.8.1.4

Regards

--
Julian Anastasov <[email protected]>

maintainer
#3 lore raw

Hello,

Quoted 10 lines · Ryan O'Hara
Quoted 5 lines · Julian Anastasov

- CHECK_PE and CHECK_IPV4 as part of CHECK_COMPAT_SVC use 'return' and we can leak svc in ipvs_get_service()

- in ipvs_get_service() CHECK_PE does not need to be called, it is already part of CHECK_COMPAT_SVC

Yes. I'm tempted to remove these macros due to the 'return' issue. Thoughts?

	May be they can use 'goto' instead of 'return':

	if (condition) {
		errno = XXX;
		goto out_err;
	}

	and funcs can have such exit point:

out_err:

	free stuff on error
	return ret;
Quoted 5 lines
Quoted 2 lines

- ipvs_get_service uses malloc but later calls CHECK_PE, may be malloc should be changed with calloc

Aside from the fact that CHECK_PE could return without freeing memory, I don't see the problem here.

malloc does not initialize the memory and checking of
svc->pe_name[0] in CHECK_PE would give random results.

Regards

--
Julian Anastasov <[email protected]>

#4 lore raw
Quoted 25 lines · Julian Anastasov

Hello,

Quoted 10 lines · Ryan O'Hara
Quoted 5 lines · Julian Anastasov

- CHECK_PE and CHECK_IPV4 as part of CHECK_COMPAT_SVC use 'return' and we can leak svc in ipvs_get_service()

- in ipvs_get_service() CHECK_PE does not need to be called, it is already part of CHECK_COMPAT_SVC

Yes. I'm tempted to remove these macros due to the 'return' issue. Thoughts?

	May be they can use 'goto' instead of 'return':

	if (condition) {
		errno = XXX;
		goto out_err;
	}

	and funcs can have such exit point:
Quoted 3 lines

out_err:

	free stuff on error
	return ret;

OK. It looks like ipvs_get_service() is the only function with a potential leak. The other functions that call any of the CHECK_* macros will just get an 'out_err: return -1'.

I also noticed that CHECK_COMPAT_DEST can be removed. This macro simply calls CHECK_IPV4, which is also called by CHECK_COMPAT_SVC. I noticed that CHECK_COMPAT_DEST is only called after CHECK_COMPAT_SVC, so this macro can be removed entirely. Agree?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

- ipvs_get_service uses malloc but later calls CHECK_PE, may be malloc should be changed with calloc

Aside from the fact that CHECK_PE could return without freeing memory, I don't see the problem here.

malloc does not initialize the memory and checking of
svc->pe_name[0] in CHECK_PE would give random results.

I see. Thanks.

Ryan

maintainer
#5 lore raw
Quoted 30 lines · Ryan O'Hara
Quoted 25 lines · Julian Anastasov

Hello,

Quoted 10 lines · Ryan O'Hara
Quoted 5 lines · Julian Anastasov

- CHECK_PE and CHECK_IPV4 as part of CHECK_COMPAT_SVC use 'return' and we can leak svc in ipvs_get_service()

- in ipvs_get_service() CHECK_PE does not need to be called, it is already part of CHECK_COMPAT_SVC

Yes. I'm tempted to remove these macros due to the 'return' issue. Thoughts?

	May be they can use 'goto' instead of 'return':

	if (condition) {
		errno = XXX;
		goto out_err;
	}

	and funcs can have such exit point:
Quoted 3 lines

out_err:

	free stuff on error
	return ret;
Quoted 8 lines

OK. It looks like ipvs_get_service() is the only function with a potential leak. The other functions that call any of the CHECK_* macros will just get an 'out_err: return -1'.

I also noticed that CHECK_COMPAT_DEST can be removed. This macro simply calls CHECK_IPV4, which is also called by CHECK_COMPAT_SVC. I noticed that CHECK_COMPAT_DEST is only called after CHECK_COMPAT_SVC, so this macro can be removed entirely. Agree?

That sounds reasonable to me.

Quoted 14 lines
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

- ipvs_get_service uses malloc but later calls CHECK_PE, may be malloc should be changed with calloc

Aside from the fact that CHECK_PE could return without freeing memory, I don't see the problem here.

malloc does not initialize the memory and checking of
svc->pe_name[0] in CHECK_PE would give random results.

I see. Thanks.

Ryan

maintainer
#6 lore raw
In reply to Ryan O'Hara

Hello,

Quoted 11 lines · Ryan O'Hara
Quoted 10 lines · Julian Anastasov
	May be they can use 'goto' instead of 'return':

	if (condition) {
		errno = XXX;
		goto out_err;
	}

	and funcs can have such exit point:
Quoted 7 lines
Quoted 3 lines

out_err:

	free stuff on error
	return ret;

OK. It looks like ipvs_get_service() is the only function with a potential leak. The other functions that call any of the CHECK_* macros will just get an 'out_err: return -1'.

Yes

Quoted 4 lines

I also noticed that CHECK_COMPAT_DEST can be removed. This macro simply calls CHECK_IPV4, which is also called by CHECK_COMPAT_SVC. I noticed that CHECK_COMPAT_DEST is only called after CHECK_COMPAT_SVC, so this macro can be removed entirely. Agree?

No. It looks like the macros work with more
than one structure: svc and dest. Same was for CHECK_PE where both structs were supported: ipvs_service_entry_t and ipvs_service_t when CHECK_PE was called from CHECK_COMPAT_SVC.

	CHECK_COMPAT_SVC does not check the dest->af,

it checks svc->af. Without both checks, svc can come with address from AF_INET family while -r option has address from AF_INET6 family. IMHO, we need just the return->goto change.

Regards

--
Julian Anastasov <[email protected]>

#7 lore raw
Quoted 36 lines · Julian Anastasov

Hello,

Quoted 11 lines · Ryan O'Hara
Quoted 10 lines · Julian Anastasov
	May be they can use 'goto' instead of 'return':

	if (condition) {
		errno = XXX;
		goto out_err;
	}

	and funcs can have such exit point:
Quoted 7 lines
Quoted 3 lines

out_err:

	free stuff on error
	return ret;

OK. It looks like ipvs_get_service() is the only function with a potential leak. The other functions that call any of the CHECK_* macros will just get an 'out_err: return -1'.

Yes

Quoted 4 lines

I also noticed that CHECK_COMPAT_DEST can be removed. This macro simply calls CHECK_IPV4, which is also called by CHECK_COMPAT_SVC. I noticed that CHECK_COMPAT_DEST is only called after CHECK_COMPAT_SVC, so this macro can be removed entirely. Agree?

No. It looks like the macros work with more
than one structure: svc and dest. Same was for CHECK_PE where both structs were supported: ipvs_service_entry_t and ipvs_service_t when CHECK_PE was called from CHECK_COMPAT_SVC.

Quoted 5 lines
	CHECK_COMPAT_SVC does not check the dest->af,

it checks svc->af. Without both checks, svc can come with address from AF_INET family while -r option has address from AF_INET6 family. IMHO, we need just the return->goto change.

You're right. Not sure how I missed that.

Ryan