* [PATCH 0/4] RFC: tipc int vs size_t fixes
@ 2010-10-27 19:13 Paul Gortmaker
[not found] ` <1288206816-23025-2-git-send-email-paul.gortmaker@windriver.com>
0 siblings, 1 reply; 4+ messages in thread
From: Paul Gortmaker @ 2010-10-27 19:13 UTC (permalink / raw)
To: davem; +Cc: netdev, allan.stephens, drosenberg, jon.maloy, security
This is a starting point for fixing up the mix of int vs. size_t
usage that Dan spotted in TIPC as being open to possible exploits.
Open questions I had remaining with these patches were whether we could
trim out some of the unrequired casts, and whether we wanted to use a
size_t for everything that at any time was based on or compared to
an iov_len, including all instances of num_sect, when things like
iov_length() in <linux/uio.h> use unsigned long for looping over segments.
Also, whether we should give up at INT_MAX or LONG_MAX...
Please suggest changes as required, and I'll integrate them into this
pass1 of draft of patches from Al and resend as required until we've
got a final acceptable solution.
Thanks,
Paul.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 0/4] RFC: tipc int vs size_t fixes
@ 2010-10-27 19:29 Paul Gortmaker
2010-10-27 19:29 ` [PATCH 1/4] tipc: Fix bugs in tipc_msg_calc_data_size() Paul Gortmaker
0 siblings, 1 reply; 4+ messages in thread
From: Paul Gortmaker @ 2010-10-27 19:29 UTC (permalink / raw)
To: davem; +Cc: netdev, allan.stephens, drosenberg, jon.maloy, torvalds, security
[apologies if you get this 2x ; a bogus Status: header caused them
to fail vger's sanity check for netdev, so resending.]
This is a starting point for fixing up the mix of int vs. size_t
usage that Dan spotted in TIPC as being open to possible exploits.
Open questions I had remaining with these patches were whether we could
trim out some of the unrequired casts, and whether we wanted to use a
size_t for everything that at any time was based on or compared to
an iov_len, including all instances of num_sect, when things like
iov_length() in <linux/uio.h> use unsigned long for looping over segments.
Also, whether we should give up at INT_MAX or LONG_MAX...
Please suggest changes as required, and I'll integrate them into this
pass1 of draft of patches from Al and resend as required until we've
got a final acceptable solution.
Thanks,
Paul.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/4] tipc: Fix bugs in tipc_msg_calc_data_size()
2010-10-27 19:29 [PATCH 0/4] RFC: tipc int vs size_t fixes Paul Gortmaker
@ 2010-10-27 19:29 ` Paul Gortmaker
2010-10-28 14:07 ` Neil Horman
0 siblings, 1 reply; 4+ messages in thread
From: Paul Gortmaker @ 2010-10-27 19:29 UTC (permalink / raw)
To: davem; +Cc: netdev, allan.stephens, drosenberg, jon.maloy, torvalds, security
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/4] tipc: Fix bugs in tipc_msg_calc_data_size()
2010-10-27 19:29 ` [PATCH 1/4] tipc: Fix bugs in tipc_msg_calc_data_size() Paul Gortmaker
@ 2010-10-28 14:07 ` Neil Horman
0 siblings, 0 replies; 4+ messages in thread
From: Neil Horman @ 2010-10-28 14:07 UTC (permalink / raw)
To: Paul Gortmaker
Cc: davem, netdev, allan.stephens, drosenberg, jon.maloy, torvalds,
security
On Wed, Oct 27, 2010 at 03:29:30PM -0400, Paul Gortmaker wrote:
> 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
>
You should probably roll this patch together with your second one. The caller
tipc_msg_build will otherwise throw a warning when you build, as it assigns the
return value with this patch (a size_t) to a signed integer. It probably won't
matter since you limit dsz to TIPC_MAX_USER_MSG_SIZE which is small in
comparison to the size of an int, but nevertheless, the two patches are related,
so you can merge them.
Neil
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-10-28 14:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
-- strict thread matches above, loose matches on Subject: below --
2010-10-27 19:29 [PATCH 0/4] RFC: tipc int vs size_t fixes Paul Gortmaker
2010-10-27 19:29 ` [PATCH 1/4] tipc: Fix bugs in tipc_msg_calc_data_size() Paul Gortmaker
2010-10-28 14:07 ` Neil Horman
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).