Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kernel memory leak in pNotifShare #655

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/nvidia/src/kernel/rmapi/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ eventInit_IMPL
*pppEventNotification = inotifyGetNotificationListPtr(pNotifierShare->pNotifier);
}

serverRefShare(&g_resServ, staticCast(pNotifierShare, RsShared));
pEvent->pNotifierShare = pNotifierShare;

// RS-TODO these can be looked up from share
Expand Down Expand Up @@ -427,6 +426,7 @@ notifyGetOrAllocNotifShare_IMPL
if (pNotifierShare == NULL)
{
RsShared *pShare;
// serverAllocShare() sets pNotifierShare->refCount to 1.
status = serverAllocShare(&g_resServ, classInfo(NotifShare), &pShare);
if (status != NV_OK)
return status;
Expand All @@ -437,6 +437,14 @@ notifyGetOrAllocNotifShare_IMPL
pNotifierShare->hNotifierResource = hNotifierResource;
inotifySetNotificationShare(staticCast(pNotifier, INotifier), pNotifierShare);
}
else
{
// Move serverRefShare() from eventInit_IMPL to here, so that |pNotifierShare|
// can be refcounted correctly.
//
// serverRefShare() increments pNotifierShare->refCount.
serverRefShare(&g_resServ, staticCast(pNotifierShare, RsShared));
}

if (ppNotifierShare)
*ppNotifierShare = pNotifierShare;
Expand Down
6 changes: 6 additions & 0 deletions src/nvidia/src/kernel/rmapi/event_notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,4 +1109,10 @@ shrnotifDestruct_IMPL
NotifShare *pNotifShare
)
{
// pNotifier->pNotifierShare should be set to NULL, or inotifyGetNotificationShare() would
// return invalid/wild pointer and cause kernel crash.
if (pNotifShare->pNotifier != NULL)
{
inotifySetNotificationShare(pNotifShare->pNotifier, NULL);
}
}