Skip to content

Commit 048a7f8

Browse files
jdelvaredavem330
authored andcommitted
s390: qeth: Fix potential array overrun in cmd/rc lookup
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. Signed-off-by: Jean Delvare <[email protected]> Cc: Julian Wiedmann <[email protected]> Cc: Ursula Braun <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Heiko Carstens <[email protected]> Signed-off-by: Julian Wiedmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 065a2cd commit 048a7f8

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

drivers/s390/net/qeth_core_main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ static void qeth_put_reply(struct qeth_reply *reply)
610610
static void qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, int rc,
611611
struct qeth_card *card)
612612
{
613-
char *ipa_name;
613+
const char *ipa_name;
614614
int com = cmd->hdr.command;
615615
ipa_name = qeth_get_ipa_cmd_name(com);
616616
if (rc)

drivers/s390/net/qeth_core_mpc.c

+16-14
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ EXPORT_SYMBOL_GPL(IPA_PDU_HEADER);
148148

149149
struct ipa_rc_msg {
150150
enum qeth_ipa_return_codes rc;
151-
char *msg;
151+
const char *msg;
152152
};
153153

154-
static struct ipa_rc_msg qeth_ipa_rc_msg[] = {
154+
static const struct ipa_rc_msg qeth_ipa_rc_msg[] = {
155155
{IPA_RC_SUCCESS, "success"},
156156
{IPA_RC_NOTSUPP, "Command not supported"},
157157
{IPA_RC_IP_TABLE_FULL, "Add Addr IP Table Full - ipv6"},
@@ -219,22 +219,23 @@ static struct ipa_rc_msg qeth_ipa_rc_msg[] = {
219219

220220

221221

222-
char *qeth_get_ipa_msg(enum qeth_ipa_return_codes rc)
222+
const char *qeth_get_ipa_msg(enum qeth_ipa_return_codes rc)
223223
{
224-
int x = 0;
225-
qeth_ipa_rc_msg[ARRAY_SIZE(qeth_ipa_rc_msg) - 1].rc = rc;
226-
while (qeth_ipa_rc_msg[x].rc != rc)
227-
x++;
224+
int x;
225+
226+
for (x = 0; x < ARRAY_SIZE(qeth_ipa_rc_msg) - 1; x++)
227+
if (qeth_ipa_rc_msg[x].rc == rc)
228+
return qeth_ipa_rc_msg[x].msg;
228229
return qeth_ipa_rc_msg[x].msg;
229230
}
230231

231232

232233
struct ipa_cmd_names {
233234
enum qeth_ipa_cmds cmd;
234-
char *name;
235+
const char *name;
235236
};
236237

237-
static struct ipa_cmd_names qeth_ipa_cmd_names[] = {
238+
static const struct ipa_cmd_names qeth_ipa_cmd_names[] = {
238239
{IPA_CMD_STARTLAN, "startlan"},
239240
{IPA_CMD_STOPLAN, "stoplan"},
240241
{IPA_CMD_SETVMAC, "setvmac"},
@@ -266,11 +267,12 @@ static struct ipa_cmd_names qeth_ipa_cmd_names[] = {
266267
{IPA_CMD_UNKNOWN, "unknown"},
267268
};
268269

269-
char *qeth_get_ipa_cmd_name(enum qeth_ipa_cmds cmd)
270+
const char *qeth_get_ipa_cmd_name(enum qeth_ipa_cmds cmd)
270271
{
271-
int x = 0;
272-
qeth_ipa_cmd_names[ARRAY_SIZE(qeth_ipa_cmd_names) - 1].cmd = cmd;
273-
while (qeth_ipa_cmd_names[x].cmd != cmd)
274-
x++;
272+
int x;
273+
274+
for (x = 0; x < ARRAY_SIZE(qeth_ipa_cmd_names) - 1; x++)
275+
if (qeth_ipa_cmd_names[x].cmd == cmd)
276+
return qeth_ipa_cmd_names[x].name;
275277
return qeth_ipa_cmd_names[x].name;
276278
}

drivers/s390/net/qeth_core_mpc.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,8 @@ enum qeth_ipa_arp_return_codes {
797797
QETH_IPA_ARP_RC_Q_NO_DATA = 0x0008,
798798
};
799799

800-
extern char *qeth_get_ipa_msg(enum qeth_ipa_return_codes rc);
801-
extern char *qeth_get_ipa_cmd_name(enum qeth_ipa_cmds cmd);
800+
extern const char *qeth_get_ipa_msg(enum qeth_ipa_return_codes rc);
801+
extern const char *qeth_get_ipa_cmd_name(enum qeth_ipa_cmds cmd);
802802

803803
#define QETH_SETASS_BASE_LEN (sizeof(struct qeth_ipacmd_hdr) + \
804804
sizeof(struct qeth_ipacmd_setassparms_hdr))

0 commit comments

Comments
 (0)