From: Allison Henderson <achender@kernel.org>
To: Xiaobo Liu <cppcoffee@gmail.com>, Paolo Abeni <pabeni@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
rds-devel@oss.oracle.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2] RDS: Fix memory leak in rds_rdma_extra_size()
Date: Thu, 16 Apr 2026 15:18:05 -0700 [thread overview]
Message-ID: <8d25047d6fe36dda1a872ea710c5ce69adcfe2b9.camel@kernel.org> (raw)
In-Reply-To: <CAJeqHv+kCScdMLYgOPG0TaRwTH5-Vo-=HEPs+oX24OprbmtbwA@mail.gmail.com>
On Thu, 2026-04-16 at 18:00 +0800, Xiaobo Liu wrote:
> The internal addition of kfree and setting the pointer to NULL in
> rds_rdma_extra_size makes the function more self‑consistent and secure.
> After applying this patch, kfree(NULL) in rds_sendmsg is also safe and will
> not cause a double‑free.
Hi Xiaobo,
Paolo makes a good point that I had missed in that rds_sendmsg owns the
cleanup. So even though iov->iov isn't freed here, it isn't leaked
either. Self-consistency is fair as a style point, but it's not
strong enough to justify the change on its own since it isn't a bug
fix. That said, thank you for taking the time to look at this area;
we appreciate the effort to help track down and fix bugs.
Thanks,
Allison
>
> On 4/16/2616:20 Paolo Abeni <pabeni@redhat.com> wrote:
> >
> > On 4/13/26 9:00 AM, Xiaobo Liu wrote:
> > > @@ -595,11 +600,20 @@ int rds_rdma_extra_size(struct rds_rdma_args
> *args,
> > > * nr_pages for one entry is limited to
> (UINT_MAX>>PAGE_SHIFT)+1,
> > > * so tot_pages cannot overflow without first going
> negative.
> > > */
> > > - if (tot_pages < 0)
> > > - return -EINVAL;
> > > + if (tot_pages < 0) {
> > > + ret = -EINVAL;
> > > + goto out;
> > > + }
> > > }
> > >
> > > - return tot_pages * sizeof(struct scatterlist);
> > > + ret = tot_pages * sizeof(struct scatterlist);
> > > +
> > > +out:
> > > + if (ret < 0) {
> > > + kfree(iov->iov);
> > > + iov->iov = NULL;
> >
> > Is this really needed?!? AFAICS rds_rdma_extra_size() is invoked only
> > via: rds_sendmsg() -> rds_rm_size() -> rds_rdma_extra_size(), and the
> > rds_sendmsg() error path already frees any non NULL iov.
> >
> > /P
prev parent reply other threads:[~2026-04-16 22:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 7:00 [PATCH net v2] RDS: Fix memory leak in rds_rdma_extra_size() Xiaobo Liu
2026-04-14 0:15 ` Allison Henderson
2026-04-16 8:20 ` Paolo Abeni
[not found] ` <CAJeqHv+kCScdMLYgOPG0TaRwTH5-Vo-=HEPs+oX24OprbmtbwA@mail.gmail.com>
2026-04-16 22:18 ` Allison Henderson [this message]
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=8d25047d6fe36dda1a872ea710c5ce69adcfe2b9.camel@kernel.org \
--to=achender@kernel.org \
--cc=cppcoffee@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rds-devel@oss.oracle.com \
/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