Skip to content

Commit dd2c796

Browse files
Colin Ian Kingdavem330
authored andcommitted
cxgb4: Fix unintentional sign extension issues
The shifting of the u8 integers f->fs.nat_lip[] by 24 bits to the left will be promoted to a 32 bit signed int and then sign-extended to a u64. In the event that the top bit of the u8 is set then all then all the upper 32 bits of the u64 end up as also being set because of the sign-extension. Fix this by casting the u8 values to a u64 before the 24 bit left shift. Addresses-Coverity: ("Unintended sign extension") Fixes: 12b276f ("cxgb4: add support to create hash filters") Signed-off-by: Colin Ian King <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5b489fe commit dd2c796

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,31 +174,31 @@ static void set_nat_params(struct adapter *adap, struct filter_entry *f,
174174
WORD_MASK, f->fs.nat_lip[15] |
175175
f->fs.nat_lip[14] << 8 |
176176
f->fs.nat_lip[13] << 16 |
177-
f->fs.nat_lip[12] << 24, 1);
177+
(u64)f->fs.nat_lip[12] << 24, 1);
178178

179179
set_tcb_field(adap, f, tid, TCB_SND_UNA_RAW_W + 1,
180180
WORD_MASK, f->fs.nat_lip[11] |
181181
f->fs.nat_lip[10] << 8 |
182182
f->fs.nat_lip[9] << 16 |
183-
f->fs.nat_lip[8] << 24, 1);
183+
(u64)f->fs.nat_lip[8] << 24, 1);
184184

185185
set_tcb_field(adap, f, tid, TCB_SND_UNA_RAW_W + 2,
186186
WORD_MASK, f->fs.nat_lip[7] |
187187
f->fs.nat_lip[6] << 8 |
188188
f->fs.nat_lip[5] << 16 |
189-
f->fs.nat_lip[4] << 24, 1);
189+
(u64)f->fs.nat_lip[4] << 24, 1);
190190

191191
set_tcb_field(adap, f, tid, TCB_SND_UNA_RAW_W + 3,
192192
WORD_MASK, f->fs.nat_lip[3] |
193193
f->fs.nat_lip[2] << 8 |
194194
f->fs.nat_lip[1] << 16 |
195-
f->fs.nat_lip[0] << 24, 1);
195+
(u64)f->fs.nat_lip[0] << 24, 1);
196196
} else {
197197
set_tcb_field(adap, f, tid, TCB_RX_FRAG3_LEN_RAW_W,
198198
WORD_MASK, f->fs.nat_lip[3] |
199199
f->fs.nat_lip[2] << 8 |
200200
f->fs.nat_lip[1] << 16 |
201-
f->fs.nat_lip[0] << 24, 1);
201+
(u64)f->fs.nat_lip[0] << 25, 1);
202202
}
203203
}
204204

@@ -208,39 +208,39 @@ static void set_nat_params(struct adapter *adap, struct filter_entry *f,
208208
WORD_MASK, f->fs.nat_fip[15] |
209209
f->fs.nat_fip[14] << 8 |
210210
f->fs.nat_fip[13] << 16 |
211-
f->fs.nat_fip[12] << 24, 1);
211+
(u64)f->fs.nat_fip[12] << 24, 1);
212212

213213
set_tcb_field(adap, f, tid, TCB_RX_FRAG2_PTR_RAW_W + 1,
214214
WORD_MASK, f->fs.nat_fip[11] |
215215
f->fs.nat_fip[10] << 8 |
216216
f->fs.nat_fip[9] << 16 |
217-
f->fs.nat_fip[8] << 24, 1);
217+
(u64)f->fs.nat_fip[8] << 24, 1);
218218

219219
set_tcb_field(adap, f, tid, TCB_RX_FRAG2_PTR_RAW_W + 2,
220220
WORD_MASK, f->fs.nat_fip[7] |
221221
f->fs.nat_fip[6] << 8 |
222222
f->fs.nat_fip[5] << 16 |
223-
f->fs.nat_fip[4] << 24, 1);
223+
(u64)f->fs.nat_fip[4] << 24, 1);
224224

225225
set_tcb_field(adap, f, tid, TCB_RX_FRAG2_PTR_RAW_W + 3,
226226
WORD_MASK, f->fs.nat_fip[3] |
227227
f->fs.nat_fip[2] << 8 |
228228
f->fs.nat_fip[1] << 16 |
229-
f->fs.nat_fip[0] << 24, 1);
229+
(u64)f->fs.nat_fip[0] << 24, 1);
230230

231231
} else {
232232
set_tcb_field(adap, f, tid,
233233
TCB_RX_FRAG3_START_IDX_OFFSET_RAW_W,
234234
WORD_MASK, f->fs.nat_fip[3] |
235235
f->fs.nat_fip[2] << 8 |
236236
f->fs.nat_fip[1] << 16 |
237-
f->fs.nat_fip[0] << 24, 1);
237+
(u64)f->fs.nat_fip[0] << 24, 1);
238238
}
239239
}
240240

241241
set_tcb_field(adap, f, tid, TCB_PDU_HDR_LEN_W, WORD_MASK,
242242
(dp ? (nat_lp[1] | nat_lp[0] << 8) : 0) |
243-
(sp ? (nat_fp[1] << 16 | nat_fp[0] << 24) : 0),
243+
(sp ? (nat_fp[1] << 16 | (u64)nat_fp[0] << 24) : 0),
244244
1);
245245
}
246246

0 commit comments

Comments
 (0)