Skip to content

Commit d3d3cf0

Browse files
author
Linus Torvalds
committed
Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6: [EBTABLES]: Clean up vmalloc usage in net/bridge/netfilter/ebtables.c [NET]: Add skb->truesize assertion checking. [TCP]: Account skb overhead in tcp_fragment [SUNGEM]: Marvell PHY suspend. [LLC]: Use pskb_trim_rcsum() in llc_fixup_skb(). [NET]: sockfd_lookup_light() returns random error for -EBADFD
2 parents a6db522 + 18bc89a commit d3d3cf0

9 files changed

Lines changed: 40 additions & 22 deletions

File tree

‎drivers/net/sungem_phy.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static int bcm5411_init(struct mii_phy* phy)
275275
return 0;
276276
}
277277

278-
static int bcm5411_suspend(struct mii_phy* phy)
278+
static int generic_suspend(struct mii_phy* phy)
279279
{
280280
phy_write(phy, MII_BMCR, BMCR_PDOWN);
281281

@@ -738,7 +738,7 @@ static struct mii_phy_def bcm5401_phy_def = {
738738
/* Broadcom BCM 5411 */
739739
static struct mii_phy_ops bcm5411_phy_ops = {
740740
.init = bcm5411_init,
741-
.suspend = bcm5411_suspend,
741+
.suspend = generic_suspend,
742742
.setup_aneg = bcm54xx_setup_aneg,
743743
.setup_forced = bcm54xx_setup_forced,
744744
.poll_link = genmii_poll_link,
@@ -757,7 +757,7 @@ static struct mii_phy_def bcm5411_phy_def = {
757757
/* Broadcom BCM 5421 */
758758
static struct mii_phy_ops bcm5421_phy_ops = {
759759
.init = bcm5421_init,
760-
.suspend = bcm5411_suspend,
760+
.suspend = generic_suspend,
761761
.setup_aneg = bcm54xx_setup_aneg,
762762
.setup_forced = bcm54xx_setup_forced,
763763
.poll_link = genmii_poll_link,
@@ -776,7 +776,7 @@ static struct mii_phy_def bcm5421_phy_def = {
776776
/* Broadcom BCM 5421 built-in K2 */
777777
static struct mii_phy_ops bcm5421k2_phy_ops = {
778778
.init = bcm5421_init,
779-
.suspend = bcm5411_suspend,
779+
.suspend = generic_suspend,
780780
.setup_aneg = bcm54xx_setup_aneg,
781781
.setup_forced = bcm54xx_setup_forced,
782782
.poll_link = genmii_poll_link,
@@ -795,7 +795,7 @@ static struct mii_phy_def bcm5421k2_phy_def = {
795795
/* Broadcom BCM 5462 built-in Vesta */
796796
static struct mii_phy_ops bcm5462V_phy_ops = {
797797
.init = bcm5421_init,
798-
.suspend = bcm5411_suspend,
798+
.suspend = generic_suspend,
799799
.setup_aneg = bcm54xx_setup_aneg,
800800
.setup_forced = bcm54xx_setup_forced,
801801
.poll_link = genmii_poll_link,
@@ -816,6 +816,7 @@ static struct mii_phy_def bcm5462V_phy_def = {
816816
* would be useful here) --BenH.
817817
*/
818818
static struct mii_phy_ops marvell_phy_ops = {
819+
.suspend = generic_suspend,
819820
.setup_aneg = marvell_setup_aneg,
820821
.setup_forced = marvell_setup_forced,
821822
.poll_link = genmii_poll_link,

‎include/linux/skbuff.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ extern void skb_over_panic(struct sk_buff *skb, int len,
344344
void *here);
345345
extern void skb_under_panic(struct sk_buff *skb, int len,
346346
void *here);
347+
extern void skb_truesize_bug(struct sk_buff *skb);
348+
349+
static inline void skb_truesize_check(struct sk_buff *skb)
350+
{
351+
if (unlikely((int)skb->truesize < sizeof(struct sk_buff) + skb->len))
352+
skb_truesize_bug(skb);
353+
}
347354

348355
extern int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb,
349356
int getfrag(void *from, char *to, int offset,

‎include/net/sock.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ static inline void sk_stream_set_owner_r(struct sk_buff *skb, struct sock *sk)
454454

455455
static inline void sk_stream_free_skb(struct sock *sk, struct sk_buff *skb)
456456
{
457+
skb_truesize_check(skb);
457458
sock_set_flag(sk, SOCK_QUEUE_SHRUNK);
458459
sk->sk_wmem_queued -= skb->truesize;
459460
sk->sk_forward_alloc += skb->truesize;

‎net/bridge/netfilter/ebtables.c‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ static int translate_table(struct ebt_replace *repl,
831831
return -ENOMEM;
832832
for_each_possible_cpu(i) {
833833
newinfo->chainstack[i] =
834-
vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
834+
vmalloc(udc_cnt * sizeof(*(newinfo->chainstack[0])));
835835
if (!newinfo->chainstack[i]) {
836836
while (i)
837837
vfree(newinfo->chainstack[--i]);
@@ -841,8 +841,7 @@ static int translate_table(struct ebt_replace *repl,
841841
}
842842
}
843843

844-
cl_s = (struct ebt_cl_stack *)
845-
vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
844+
cl_s = vmalloc(udc_cnt * sizeof(*cl_s));
846845
if (!cl_s)
847846
return -ENOMEM;
848847
i = 0; /* the i'th udc */
@@ -944,8 +943,7 @@ static int do_replace(void __user *user, unsigned int len)
944943

945944
countersize = COUNTER_OFFSET(tmp.nentries) *
946945
(highest_possible_processor_id()+1);
947-
newinfo = (struct ebt_table_info *)
948-
vmalloc(sizeof(struct ebt_table_info) + countersize);
946+
newinfo = vmalloc(sizeof(*newinfo) + countersize);
949947
if (!newinfo)
950948
return -ENOMEM;
951949

@@ -967,8 +965,7 @@ static int do_replace(void __user *user, unsigned int len)
967965
/* the user wants counters back
968966
the check on the size is done later, when we have the lock */
969967
if (tmp.num_counters) {
970-
counterstmp = (struct ebt_counter *)
971-
vmalloc(tmp.num_counters * sizeof(struct ebt_counter));
968+
counterstmp = vmalloc(tmp.num_counters * sizeof(*counterstmp));
972969
if (!counterstmp) {
973970
ret = -ENOMEM;
974971
goto free_entries;
@@ -1148,8 +1145,7 @@ int ebt_register_table(struct ebt_table *table)
11481145

11491146
countersize = COUNTER_OFFSET(table->table->nentries) *
11501147
(highest_possible_processor_id()+1);
1151-
newinfo = (struct ebt_table_info *)
1152-
vmalloc(sizeof(struct ebt_table_info) + countersize);
1148+
newinfo = vmalloc(sizeof(*newinfo) + countersize);
11531149
ret = -ENOMEM;
11541150
if (!newinfo)
11551151
return -ENOMEM;
@@ -1247,8 +1243,7 @@ static int update_counters(void __user *user, unsigned int len)
12471243
if (hlp.num_counters == 0)
12481244
return -EINVAL;
12491245

1250-
if ( !(tmp = (struct ebt_counter *)
1251-
vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
1246+
if (!(tmp = vmalloc(hlp.num_counters * sizeof(*tmp)))) {
12521247
MEMPRINT("Update_counters && nomemory\n");
12531248
return -ENOMEM;
12541249
}
@@ -1377,8 +1372,7 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
13771372
BUGPRINT("Num_counters wrong\n");
13781373
return -EINVAL;
13791374
}
1380-
counterstmp = (struct ebt_counter *)
1381-
vmalloc(nentries * sizeof(struct ebt_counter));
1375+
counterstmp = vmalloc(nentries * sizeof(*counterstmp));
13821376
if (!counterstmp) {
13831377
MEMPRINT("Couldn't copy counters, out of memory\n");
13841378
return -ENOMEM;

‎net/core/skbuff.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ void skb_under_panic(struct sk_buff *skb, int sz, void *here)
112112
BUG();
113113
}
114114

115+
void skb_truesize_bug(struct sk_buff *skb)
116+
{
117+
printk(KERN_ERR "SKB BUG: Invalid truesize (%u) "
118+
"len=%u, sizeof(sk_buff)=%Zd\n",
119+
skb->truesize, skb->len, sizeof(struct sk_buff));
120+
}
121+
EXPORT_SYMBOL(skb_truesize_bug);
122+
115123
/* Allocate a new skbuff. We do this ourselves so we can fill in a few
116124
* 'private' fields and also do memory statistics to find all the
117125
* [BEEP] leaks.

‎net/core/stream.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ void sk_stream_rfree(struct sk_buff *skb)
176176
{
177177
struct sock *sk = skb->sk;
178178

179+
skb_truesize_check(skb);
179180
atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
180181
sk->sk_forward_alloc += skb->truesize;
181182
}

‎net/ipv4/tcp_output.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss
533533
struct tcp_sock *tp = tcp_sk(sk);
534534
struct sk_buff *buff;
535535
int nsize, old_factor;
536+
int nlen;
536537
u16 flags;
537538

538539
BUG_ON(len > skb->len);
@@ -552,8 +553,10 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss
552553
if (buff == NULL)
553554
return -ENOMEM; /* We'll just try again later. */
554555

555-
buff->truesize = skb->len - len;
556-
skb->truesize -= buff->truesize;
556+
sk_charge_skb(sk, buff);
557+
nlen = skb->len - len - nsize;
558+
buff->truesize += nlen;
559+
skb->truesize -= nlen;
557560

558561
/* Correct the sequence numbers. */
559562
TCP_SKB_CB(buff)->seq = TCP_SKB_CB(skb)->seq + len;
@@ -1039,7 +1042,8 @@ static int tso_fragment(struct sock *sk, struct sk_buff *skb, unsigned int len,
10391042
if (unlikely(buff == NULL))
10401043
return -ENOMEM;
10411044

1042-
buff->truesize = nlen;
1045+
sk_charge_skb(sk, buff);
1046+
buff->truesize += nlen;
10431047
skb->truesize -= nlen;
10441048

10451049
/* Correct the sequence numbers. */

‎net/llc/llc_input.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ static inline int llc_fixup_skb(struct sk_buff *skb)
118118
u16 pdulen = eth_hdr(skb)->h_proto,
119119
data_size = ntohs(pdulen) - llc_len;
120120

121-
skb_trim(skb, data_size);
121+
if (unlikely(pskb_trim_rcsum(skb, data_size)))
122+
return 0;
122123
}
123124
return 1;
124125
}

‎net/socket.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
490490
struct file *file;
491491
struct socket *sock;
492492

493+
*err = -EBADF;
493494
file = fget_light(fd, fput_needed);
494495
if (file) {
495496
sock = sock_from_file(file, err);

0 commit comments

Comments
 (0)