Skip to contentSkip to conversation

s390: qeth: Fix potential array overrun in cmd/rc lookup

PATCH Jean Delvare 1 participant 1 message Sep 10, 2018 1 message not in the archive s390

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi Ursula,

Quoted 32 lines · Ursula Braun
Quoted 31 lines · Jean Delvare

Functions qeth_get_ipa_msg and qeth_get_ipa_cmd_name are modifying the last member of global arrays without any locking that I can see. If two instances of either function are running at the same time, it could cause a race ultimately leading to an array overrun (the contents of the last entry of the array is the only guarantee that the loop will ever stop).

Performing the lookups without modifying the arrays is admittedly slower (two comparisons per iteration instead of one) but these are operations which are rare (should only be needed in error cases or when debugging, not during successful operation) and it seems still less costly than introducing a mutex to protect the arrays in question.

As a side bonus, it allows us to declare both arrays as const data.

Cc Julian Wiedmann <[email protected]>
Cc Ursula Braun <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>

---
Note: build-tested only.
(...)

(quoted diff) +1 -1
-static struct ipa_cmd_names qeth_ipa_cmd_names[] = {
+static const struct ipa_cmd_names qeth_ipa_cmd_names[] = {
 	{IPA_CMD_STARTLAN,	"startlan"},
 	{IPA_CMD_STOPLAN,	"stoplan"},
 	{IPA_CMD_SETVMAC,	"setvmac"},
@@ -263,14 +264,14 @@ static struct ipa_cmd_names qeth_ipa_cmd
 	{IPA_CMD_REGISTER_LOCAL_ADDR,	"register_local_addr"},
Quoted 8 lines

Review static struct ipa_cmd_names qeth_ipa_cmd · line 266

Quoted 3 lines
(quoted diff) +0 -1
 	{IPA_CMD_UNREGISTER_LOCAL_ADDR,	"unregister_local_addr"},
 	{IPA_CMD_ADDRESS_CHANGE_NOTIF, "address_change_notification"},
-	{IPA_CMD_UNKNOWN,	"unknown"},  

Why is this line removed? Doesn't the last line of function qeth_get_ipa_cmd_name() still refer to this line?
And if IPA_CMD_UNKNOWN is really removed, then make sure its definition is removed from qeth_core_mpc.h as well.

That's a bug in the patch, sorry about that, I will resend :(

In an earlier version of the patch, IPA_CMD_UNKNOWN was removed, but then I found it was more elegant to keep it so that the code in qeth_get_ipa_cmd_name() and qeth_get_ipa_msg() would be the same. I restored the definition in qeth_core_mpc.h but forgot to also restore the last entry of qeth_ipa_cmd_names[].

Thanks for catching it and sorry again,

Signature · 2 lines
Jean Delvare
SUSE L3 Support