<div dir="ltr">The internal addition of kfree and setting the pointer to NULL in<br>rds_rdma_extra_size makes the function more self‑consistent and secure.<br>After applying this patch, kfree(NULL) in rds_sendmsg is also safe and will<br>not cause a double‑free.<br><br>On 4/16/2616:20 Paolo Abeni <<a href="mailto:pabeni@redhat.com">pabeni@redhat.com</a>> wrote:<br>><br>> On 4/13/26 9:00 AM, Xiaobo Liu wrote:<br>> > @@ -595,11 +600,20 @@ int rds_rdma_extra_size(struct rds_rdma_args *args,<br>> >                * nr_pages for one entry is limited to (UINT_MAX>>PAGE_SHIFT)+1,<br>> >                * so tot_pages cannot overflow without first going negative.<br>> >                */<br>> > -             if (tot_pages < 0)<br>> > -                     return -EINVAL;<br>> > +             if (tot_pages < 0) {<br>> > +                     ret = -EINVAL;<br>> > +                     goto out;<br>> > +             }<br>> >       }<br>> ><br>> > -     return tot_pages * sizeof(struct scatterlist);<br>> > +     ret = tot_pages * sizeof(struct scatterlist);<br>> > +<br>> > +out:<br>> > +     if (ret < 0) {<br>> > +             kfree(iov->iov);<br>> > +             iov->iov = NULL;<br>><br>> Is this really needed?!? AFAICS rds_rdma_extra_size() is invoked only<br>> via: rds_sendmsg() -> rds_rm_size() -> rds_rdma_extra_size(), and the<br>> rds_sendmsg() error path already frees any non NULL iov.<br>><br>> /P</div>