dccp qpolicy: Parameter checking of cmsg qpolicy parameters

Ensure that cmsg->cmsg_type value is valid for qpolicy 
that is currently in use.

Signed-off-by: Tomasz Grobelny <tomasz@grobelny.oswiecenia.net>
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
This commit is contained in:
Tomasz Grobelny 2008-09-04 07:30:19 +02:00 committed by Gerrit Renker
parent d6da3511d6
commit 7d1af6a8d9
3 changed files with 22 additions and 6 deletions

View File

@ -242,6 +242,7 @@ extern bool dccp_qpolicy_full(struct sock *sk);
extern void dccp_qpolicy_drop(struct sock *sk, struct sk_buff *skb); extern void dccp_qpolicy_drop(struct sock *sk, struct sk_buff *skb);
extern struct sk_buff *dccp_qpolicy_top(struct sock *sk); extern struct sk_buff *dccp_qpolicy_top(struct sock *sk);
extern struct sk_buff *dccp_qpolicy_pop(struct sock *sk); extern struct sk_buff *dccp_qpolicy_pop(struct sock *sk);
extern bool dccp_qpolicy_param_ok(struct sock *sk, __be32 param);
/* /*
* TX Packet Output and TX Timers * TX Packet Output and TX Timers

View File

@ -735,6 +735,10 @@ static int dccp_msghdr_parse(struct msghdr *msg, struct sk_buff *skb)
if (cmsg->cmsg_level != SOL_DCCP) if (cmsg->cmsg_level != SOL_DCCP)
continue; continue;
if (cmsg->cmsg_type <= DCCP_SCM_QPOLICY_MAX &&
!dccp_qpolicy_param_ok(skb->sk, cmsg->cmsg_type))
return -EINVAL;
switch (cmsg->cmsg_type) { switch (cmsg->cmsg_type) {
case DCCP_SCM_PRIORITY: case DCCP_SCM_PRIORITY:
if (cmsg->cmsg_len != CMSG_LEN(sizeof(__u32))) if (cmsg->cmsg_len != CMSG_LEN(sizeof(__u32)))

View File

@ -73,17 +73,20 @@ static struct dccp_qpolicy_operations {
void (*push) (struct sock *sk, struct sk_buff *skb); void (*push) (struct sock *sk, struct sk_buff *skb);
bool (*full) (struct sock *sk); bool (*full) (struct sock *sk);
struct sk_buff* (*top) (struct sock *sk); struct sk_buff* (*top) (struct sock *sk);
__be32 params;
} qpol_table[DCCPQ_POLICY_MAX] = { } qpol_table[DCCPQ_POLICY_MAX] = {
[DCCPQ_POLICY_SIMPLE] = { [DCCPQ_POLICY_SIMPLE] = {
.push = qpolicy_simple_push, .push = qpolicy_simple_push,
.full = qpolicy_simple_full, .full = qpolicy_simple_full,
.top = qpolicy_simple_top, .top = qpolicy_simple_top,
.params = 0,
}, },
[DCCPQ_POLICY_PRIO] = { [DCCPQ_POLICY_PRIO] = {
.push = qpolicy_simple_push, .push = qpolicy_simple_push,
.full = qpolicy_prio_full, .full = qpolicy_prio_full,
.top = qpolicy_prio_best_skb, .top = qpolicy_prio_best_skb,
.params = DCCP_SCM_PRIORITY,
}, },
}; };
@ -124,3 +127,11 @@ struct sk_buff *dccp_qpolicy_pop(struct sock *sk)
skb_unlink(skb, &sk->sk_write_queue); skb_unlink(skb, &sk->sk_write_queue);
return skb; return skb;
} }
bool dccp_qpolicy_param_ok(struct sock *sk, __be32 param)
{
/* check if exactly one bit is set */
if (!param || (param & (param - 1)))
return false;
return (qpol_table[dccp_sk(sk)->dccps_qpolicy].params & param) == param;
}