[mpls-linux-devel] [PATCH] mpls_instr.c fix
Status: Beta
Brought to you by:
jleu
From: Igor M. <ig...@et...> - 2011-09-26 15:17:34
|
Hi all, In mpls kernel I restricted number of ops that could be part of instructions stack. In every instruction stack we can only have one op of each kind, except of ops POP and PUSH. Also I added check if number of ops is larger than MPLS_NUM_OPS. If that is true, without that check we would have kernel Oops. Also I put check so we can't have ops behind ops that should be last. Also op DLV should be only one in instructions stack. Signed-off-by: Igor Maravic <ig...@et...> --- --- linux-2.6.38.8-mpls/net/mpls/mpls_instr.c.orig 2011-09-26 11:34:31.000000000 +0200 +++ linux-2.6.38.8-mpls/net/mpls/mpls_instr.c 2011-09-26 16:41:33.448970254 +0200 @@ -126,17 +126,46 @@ mpls_instrs_build (struct mpls_instr_ele struct mpls_instr *mi; /* MPLS Instruction Iterator */ void *data; int ret = -ENXIO; + int ops_counter[MPLS_OP_MAX]={0}; MPLS_ENTER; MPLS_ASSERT(*instr == NULL); - + if(length > MPLS_NUM_OPS){ + printk (KERN_ERR "MPLS: To many ops, max is %d and you had %d\n", MPLS_NUM_OPS, length); + goto rollback; + } /* Iterate the instr set */ - for (i = 0; i < length; i++) { + for (i = 0; i < length; i++) { + if (last_able){ + printk (KERN_ERR "MPLS: No ops are allowed after op %s\n", mpls_ops[opcode].msg); + goto rollback; + } + opcode = mie[i].mir_opcode; - f = mpls_ops[opcode].build; + if (opcode == MPLS_OP_DLV && i!=0){ + printk (KERN_ERR "MPLS: Op %s can exist only alone\n", mpls_ops[opcode].msg); + goto rollback; + } + + ops_counter[opcode]++; + switch(opcode){ + case MPLS_OP_POP: + case MPLS_OP_PUSH: + /*This 2 ops are only 2 ops that can be caled more then once + in instruction stack*/ + break; + default: + if(ops_counter[opcode]>1){ + printk (KERN_ERR "MPLS: There can be only one op %s\n", mpls_ops[opcode].msg); + goto rollback; + } + break; + } + + f = mpls_ops[opcode].build; if (unlikely(!f)) goto rollback; - mi = mpls_instr_alloc(opcode); + mi = mpls_instr_alloc(opcode); if (unlikely(!mi)) goto rollback; @@ -172,7 +201,7 @@ mpls_instrs_build (struct mpls_instr_ele mpls_proto_cache_flush_all(&init_net); MPLS_EXIT; return i; - + rollback: mi = *instr; mpls_instrs_free(mi); |