Page MenuHomeFreeBSD

Fix possible memory leak on error return in krpc_portmap
AbandonedPublic

Authored by j-nitrology.com on Aug 4 2016, 6:41 AM.
Tags
None
Referenced Files
F81968341: D7413.id.diff
Fri, Dec 13, 7:15 PM
Unknown Object (File)
Sat, Dec 7, 11:18 AM
Unknown Object (File)
Tue, Nov 19, 12:51 PM
Unknown Object (File)
Fri, Nov 15, 10:01 PM
Unknown Object (File)
Thu, Nov 14, 8:42 AM
Unknown Object (File)
Nov 12 2024, 4:43 PM
Unknown Object (File)
Nov 12 2024, 11:37 AM
Unknown Object (File)
Nov 11 2024, 1:23 AM
Subscribers

Details

Reviewers
None
Summary

If krpc_call failed in krpc_portmap this could have caused a leak of m

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

j-nitrology.com retitled this revision from to Fix possible memory leak on error return in krpc_portmap.
j-nitrology.com updated this object.
j-nitrology.com edited the test plan for this revision. (Show Details)
j-nitrology.com added a reviewer: sbruno.

Seems sensible. I've asked Rick Macklem to verify.

If you look at krpc_call(), it does an m_freem(mhead) for most error cases.
For some of these, mhead->m_next = m, so this patch is not safe and
can result in multiple frees, for an error return after this point in the function.

I think krpc_call() can be fixed by adding this one line after #279:
279: mhead->m_next = *data;
add-> *data = NULL;

With this one line change, I think the above patch is safe.

However, I think it might be preferable to have all the m_freem() calls in krpc_call() instead for the error return
cases that preceed "mhead->m_next = *data, since it already frees the mbuf chain passed in for subsequent
cases? (Basically the first 4 error return cases, 2 which do return and two which do "goto out".)

rick

j-nitrology.com edited edge metadata.
j-nitrology.com removed rS FreeBSD src repository - subversion as the repository for this revision.

Allow krpc_call() to do all freeing in out: to avoid possible double-frees

Sorry for the delay, this had dropped off my radar until sbruno prodded me about it. Thanks for taking the time to review, looking over the goto outs in krpc_call() reveals the possible double-frees as you've mentioned.

I believe this represents what you were speaking to, simply freeing before the return on the first 2 error cases.

Sorry, but this patch would be worse than a leak. "mhead" is not assigned at
this point in the code (unless there is some other patch already assumed).
mhead is set NULL at line#216, after the first m_freem(mhead) this patch adds.
The code must m_freem(*data); for these cases.

Also, there are three places where there is a "goto out" before mhead->m_next
is set to "*data". These cases (line#s 235, 246 and 268) also need a "m_freem(*data)"
in front of them.

Btw, I think this code is only executed during mounting of an NFS root fs, so a
leak is probably harmless.

rick

j-nitrology.com removed a reviewer: sbruno.
j-nitrology.com removed a subscriber: imp.

This will be reworked in the future to be proper, abandoning for now. Thank you for the follow up.