diff options
author | David S. Miller <davem@davemloft.net> | 2011-02-13 19:50:45 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-02-13 19:51:37 -0500 |
commit | c978e7bb77dfd2cd3d1f547fa4e395cfe47f02b2 (patch) | |
tree | b77cb1058d7821a9cdb8fcc7a8d6d3759f63743e /drivers/isdn | |
parent | ab60707ffe9920b66b4fff5181b44b14cd091472 (diff) |
hisax: Fix unchecked alloc_skb() return.
Jesper Juhl noticed that l2_pull_iqueue() does not
check to see if alloc_skb() fails.
Fix this by first trying to reallocate the headroom
if necessary, rather than later after we've made hard
to undo state changes.
Reported-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/isdn')
-rw-r--r-- | drivers/isdn/hisax/isdnl2.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/drivers/isdn/hisax/isdnl2.c b/drivers/isdn/hisax/isdnl2.c index 0858791978d8..98ac835281fe 100644 --- a/drivers/isdn/hisax/isdnl2.c +++ b/drivers/isdn/hisax/isdnl2.c | |||
@@ -1243,14 +1243,21 @@ l2_st7_tout_203(struct FsmInst *fi, int event, void *arg) | |||
1243 | st->l2.rc = 0; | 1243 | st->l2.rc = 0; |
1244 | } | 1244 | } |
1245 | 1245 | ||
1246 | static int l2_hdr_space_needed(struct Layer2 *l2) | ||
1247 | { | ||
1248 | int len = test_bit(FLG_LAPD, &l2->flag) ? 2 : 1; | ||
1249 | |||
1250 | return len + (test_bit(FLG_LAPD, &l2->flag) ? 2 : 1); | ||
1251 | } | ||
1252 | |||
1246 | static void | 1253 | static void |
1247 | l2_pull_iqueue(struct FsmInst *fi, int event, void *arg) | 1254 | l2_pull_iqueue(struct FsmInst *fi, int event, void *arg) |
1248 | { | 1255 | { |
1249 | struct PStack *st = fi->userdata; | 1256 | struct PStack *st = fi->userdata; |
1250 | struct sk_buff *skb, *oskb; | 1257 | struct sk_buff *skb; |
1251 | struct Layer2 *l2 = &st->l2; | 1258 | struct Layer2 *l2 = &st->l2; |
1252 | u_char header[MAX_HEADER_LEN]; | 1259 | u_char header[MAX_HEADER_LEN]; |
1253 | int i; | 1260 | int i, hdr_space_needed; |
1254 | int unsigned p1; | 1261 | int unsigned p1; |
1255 | u_long flags; | 1262 | u_long flags; |
1256 | 1263 | ||
@@ -1261,6 +1268,16 @@ l2_pull_iqueue(struct FsmInst *fi, int event, void *arg) | |||
1261 | if (!skb) | 1268 | if (!skb) |
1262 | return; | 1269 | return; |
1263 | 1270 | ||
1271 | hdr_space_needed = l2_hdr_space_needed(l2); | ||
1272 | if (hdr_space_needed > skb_headroom(skb)) { | ||
1273 | struct sk_buff *orig_skb = skb; | ||
1274 | |||
1275 | skb = skb_realloc_headroom(skb, hdr_space_needed); | ||
1276 | if (!skb) { | ||
1277 | dev_kfree_skb(orig_skb); | ||
1278 | return; | ||
1279 | } | ||
1280 | } | ||
1264 | spin_lock_irqsave(&l2->lock, flags); | 1281 | spin_lock_irqsave(&l2->lock, flags); |
1265 | if(test_bit(FLG_MOD128, &l2->flag)) | 1282 | if(test_bit(FLG_MOD128, &l2->flag)) |
1266 | p1 = (l2->vs - l2->va) % 128; | 1283 | p1 = (l2->vs - l2->va) % 128; |
@@ -1285,19 +1302,7 @@ l2_pull_iqueue(struct FsmInst *fi, int event, void *arg) | |||
1285 | l2->vs = (l2->vs + 1) % 8; | 1302 | l2->vs = (l2->vs + 1) % 8; |
1286 | } | 1303 | } |
1287 | spin_unlock_irqrestore(&l2->lock, flags); | 1304 | spin_unlock_irqrestore(&l2->lock, flags); |
1288 | p1 = skb->data - skb->head; | 1305 | memcpy(skb_push(skb, i), header, i); |
1289 | if (p1 >= i) | ||
1290 | memcpy(skb_push(skb, i), header, i); | ||
1291 | else { | ||
1292 | printk(KERN_WARNING | ||
1293 | "isdl2 pull_iqueue skb header(%d/%d) too short\n", i, p1); | ||
1294 | oskb = skb; | ||
1295 | skb = alloc_skb(oskb->len + i, GFP_ATOMIC); | ||
1296 | memcpy(skb_put(skb, i), header, i); | ||
1297 | skb_copy_from_linear_data(oskb, | ||
1298 | skb_put(skb, oskb->len), oskb->len); | ||
1299 | dev_kfree_skb(oskb); | ||
1300 | } | ||
1301 | st->l2.l2l1(st, PH_PULL | INDICATION, skb); | 1306 | st->l2.l2l1(st, PH_PULL | INDICATION, skb); |
1302 | test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag); | 1307 | test_and_clear_bit(FLG_ACK_PEND, &st->l2.flag); |
1303 | if (!test_and_set_bit(FLG_T200_RUN, &st->l2.flag)) { | 1308 | if (!test_and_set_bit(FLG_T200_RUN, &st->l2.flag)) { |