diff options
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/mqueue.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ipc/mqueue.c b/ipc/mqueue.c index 3c72a05dc326..076399ce363a 100644 --- a/ipc/mqueue.c +++ b/ipc/mqueue.c | |||
@@ -676,6 +676,9 @@ static void remove_notification(struct mqueue_inode_info *info) | |||
676 | 676 | ||
677 | static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr) | 677 | static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr) |
678 | { | 678 | { |
679 | int mq_treesize; | ||
680 | unsigned long total_size; | ||
681 | |||
679 | if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0) | 682 | if (attr->mq_maxmsg <= 0 || attr->mq_msgsize <= 0) |
680 | return 0; | 683 | return 0; |
681 | if (capable(CAP_SYS_RESOURCE)) { | 684 | if (capable(CAP_SYS_RESOURCE)) { |
@@ -690,9 +693,11 @@ static int mq_attr_ok(struct ipc_namespace *ipc_ns, struct mq_attr *attr) | |||
690 | /* check for overflow */ | 693 | /* check for overflow */ |
691 | if (attr->mq_msgsize > ULONG_MAX/attr->mq_maxmsg) | 694 | if (attr->mq_msgsize > ULONG_MAX/attr->mq_maxmsg) |
692 | return 0; | 695 | return 0; |
693 | if ((unsigned long)(attr->mq_maxmsg * (attr->mq_msgsize | 696 | mq_treesize = attr->mq_maxmsg * sizeof(struct msg_msg) + |
694 | + sizeof (struct msg_msg *))) < | 697 | min_t(unsigned int, attr->mq_maxmsg, MQ_PRIO_MAX) * |
695 | (unsigned long)(attr->mq_maxmsg * attr->mq_msgsize)) | 698 | sizeof(struct posix_msg_tree_node); |
699 | total_size = attr->mq_maxmsg * attr->mq_msgsize; | ||
700 | if (total_size + mq_treesize < total_size) | ||
696 | return 0; | 701 | return 0; |
697 | return 1; | 702 | return 1; |
698 | } | 703 | } |