From: Julian Anastasov <ja@ssi.bg>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
Simon Horman <horms@verge.net.au>,
Pablo Neira Ayuso <pablo@netfilter.org>,
Jozsef Kadlecsik <kadlec@netfilter.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, lvs-devel@vger.kernel.org,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net] ipvs: prevent integer overflow in do_ip_vs_get_ctl()
Date: Sat, 8 Mar 2025 14:06:53 +0200 (EET) [thread overview]
Message-ID: <a89fe1a8-989d-c2b7-f039-63670d099b67@ssi.bg> (raw)
In-Reply-To: <6dddcc45-78db-4659-80a2-3a2758f491a6@stanley.mountain>
Hello,
On Fri, 7 Mar 2025, Dan Carpenter wrote:
> The get->num_services variable is an unsigned int which is controlled by
> the user. The struct_size() function ensures that the size calculation
> does not overflow an unsigned long, however, we are saving the result to
> an int so the calculation can overflow.
>
> Save the result from struct_size() type size_t to fix this integer
> overflow bug.
>
> Cc: stable@vger.kernel.org
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> net/netfilter/ipvs/ip_vs_ctl.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
> index 7d13110ce188..801d65fd8a81 100644
> --- a/net/netfilter/ipvs/ip_vs_ctl.c
> +++ b/net/netfilter/ipvs/ip_vs_ctl.c
> @@ -3091,12 +3091,12 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
> case IP_VS_SO_GET_SERVICES:
> {
> struct ip_vs_get_services *get;
> - int size;
> + size_t size;
>
> get = (struct ip_vs_get_services *)arg;
> size = struct_size(get, entrytable, get->num_services);
Both are GET operations. The problem that can happen only
on 64-bit platforms is that user will attempt copy_to_user() with
shorter buffer and will get EFAULT if there are so many entries to
return. On 32-bit size will be -1 and will not match *len (EINVAL).
So, I assume the issue is not critical, right?
> if (*len != size) {
> - pr_err("length: %u != %u\n", *len, size);
> + pr_err("length: %u != %lu\n", *len, size);
%zu, %lu fails on 32-bit platforms. Please, send v2
fixing the format.
> ret = -EINVAL;
> goto out;
> }
> @@ -3132,12 +3132,12 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
> case IP_VS_SO_GET_DESTS:
> {
> struct ip_vs_get_dests *get;
> - int size;
> + size_t size;
>
> get = (struct ip_vs_get_dests *)arg;
> size = struct_size(get, entrytable, get->num_dests);
> if (*len != size) {
> - pr_err("length: %u != %u\n", *len, size);
> + pr_err("length: %u != %lu\n", *len, size);
> ret = -EINVAL;
> goto out;
> }
> --
> 2.47.2
Regards
--
Julian Anastasov <ja@ssi.bg>
next prev parent reply other threads:[~2025-03-08 12:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-07 13:44 [PATCH net] ipvs: prevent integer overflow in do_ip_vs_get_ctl() Dan Carpenter
2025-03-07 14:06 ` Jan Engelhardt
2025-03-08 12:06 ` Julian Anastasov [this message]
2025-03-08 19:03 ` kernel test robot
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=a89fe1a8-989d-c2b7-f039-63670d099b67@ssi.bg \
--to=ja@ssi.bg \
--cc=coreteam@netfilter.org \
--cc=dan.carpenter@linaro.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gustavo@embeddedor.com \
--cc=horms@verge.net.au \
--cc=kadlec@netfilter.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvs-devel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.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).