From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, allan.stephens@windriver.com,
drosenberg@vsecurity.com, jon.maloy@ericsson.com,
torvalds@linux-foundation.org, security@kernel.org
Subject: [PATCH 1/4] tipc: Fix bugs in tipc_msg_calc_data_size()
Date: Wed, 27 Oct 2010 15:29:30 -0400 [thread overview]
Message-ID: <1288207773-25448-2-git-send-email-paul.gortmaker@windriver.com> (raw)
In-Reply-To: <1288207773-25448-1-git-send-email-paul.gortmaker@windriver.com>
From: Allan Stephens <Allan.Stephens@windriver.com>
Enhances TIPC's computation of the amount of data to be sent so that
it works properly when large values are involved. Calculations are now
done using "size_t" instead of "int", and a check has been added to
handle cases where the total amount of data exceeds the range of "size_t".
Signed-off-by: Allan Stephens <Allan.Stephens@windriver.com>
---
net/tipc/msg.c | 17 ++++++++++++-----
net/tipc/msg.h | 2 +-
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/net/tipc/msg.c b/net/tipc/msg.c
index ecb532f..38360a9 100644
--- a/net/tipc/msg.c
+++ b/net/tipc/msg.c
@@ -72,15 +72,22 @@ void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type,
/**
* tipc_msg_calc_data_size - determine total data size for message
+ *
+ * Note: If total exceeds range of size_t returns largest possible value
*/
-int tipc_msg_calc_data_size(struct iovec const *msg_sect, u32 num_sect)
+size_t tipc_msg_calc_data_size(struct iovec const *msg_sect, size_t num_sect)
{
- int dsz = 0;
- int i;
+ size_t dsz = 0;
+ size_t len;
+ size_t i;
- for (i = 0; i < num_sect; i++)
- dsz += msg_sect[i].iov_len;
+ for (i = 0; i < num_sect; i++) {
+ len = msg_sect[i].iov_len;
+ if (len > (size_t)LONG_MAX - dsz)
+ return (size_t)LONG_MAX;
+ dsz += len;
+ }
return dsz;
}
diff --git a/net/tipc/msg.h b/net/tipc/msg.h
index 031aad1..a132800 100644
--- a/net/tipc/msg.h
+++ b/net/tipc/msg.h
@@ -711,7 +711,7 @@ static inline void msg_set_dataoctet(struct tipc_msg *m, u32 pos)
u32 tipc_msg_tot_importance(struct tipc_msg *m);
void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type,
u32 hsize, u32 destnode);
-int tipc_msg_calc_data_size(struct iovec const *msg_sect, u32 num_sect);
+size_t tipc_msg_calc_data_size(struct iovec const *msg_sect, size_t num_sect);
int tipc_msg_build(struct tipc_msg *hdr,
struct iovec const *msg_sect, u32 num_sect,
int max_size, int usrmem, struct sk_buff** buf);
--
1.7.1.GIT
next prev parent reply other threads:[~2010-10-27 19:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-27 19:29 [PATCH 0/4] RFC: tipc int vs size_t fixes Paul Gortmaker
2010-10-27 19:29 ` Paul Gortmaker [this message]
2010-10-28 14:07 ` [PATCH 1/4] tipc: Fix bugs in tipc_msg_calc_data_size() Neil Horman
2010-10-27 19:29 ` [PATCH 2/4] tipc: Fix bugs in tipc_msg_build() Paul Gortmaker
2010-10-28 14:19 ` Neil Horman
2010-10-27 19:29 ` [PATCH 3/4] tipc: Update arguments to use size_t for iovec array sizes Paul Gortmaker
2010-10-27 19:29 ` [PATCH 4/4] tipc: Fix bugs in sending of large amounts of byte-stream data Paul Gortmaker
-- strict thread matches above, loose matches on Subject: below --
2010-10-27 19:13 [PATCH 0/4] RFC: tipc int vs size_t fixes Paul Gortmaker
[not found] ` <1288206816-23025-2-git-send-email-paul.gortmaker@windriver.com>
2010-10-27 19:17 ` [PATCH 1/4] tipc: Fix bugs in tipc_msg_calc_data_size() David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1288207773-25448-2-git-send-email-paul.gortmaker@windriver.com \
--to=paul.gortmaker@windriver.com \
--cc=allan.stephens@windriver.com \
--cc=davem@davemloft.net \
--cc=drosenberg@vsecurity.com \
--cc=jon.maloy@ericsson.com \
--cc=netdev@vger.kernel.org \
--cc=security@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).