Skip to content

Conversation

ldennington
Copy link
Contributor

Multiple Linux users have reported that they are unable to use Secret Service as their credential store, as GCM throws the following error:

sec_free: Assertion `cell->requested > 0' failed.

The root cause is that we're using the libsecret secret_value_get function to obtain secret data, then attempting to free the string with secret_password_free. It appears that secret_password_free is only meant to be used to free nonpageable memory [1], however. Removing this call fixes the issue, as verified with a successful git-credential-manager diagnose (which was previously failing with the above error).

[1] secret_password_free manpage
https://www.manpagez.com/html/libsecret-1/libsecret-1-0.18.6/libsecret-Password-storage.php#secret-password-free

Fixes #793

Multiple Linux users have reported that they are unable to use Secret
Service as their credential store, as GCM throws the following error:

sec_free: Assertion `cell->requested > 0' failed.

The root cause is that we're using the libsecret secret_value_get()
function to obtain secret data, then attempting to free the string with
secret_password_free(). It appears that secret_password_free() is only
meant to be used to free nonpageable memory [1], however. Removing this
call fixes the issue, as verified with a successful git-credential-manager
diagnose (which was previously failing with the above error).

[1] secret_password_free manpage
https://www.manpagez.com/html/libsecret-1/libsecret-1-0.18.6/libsecret-Password-storage.php#secret-password-free
@ldennington ldennington self-assigned this Dec 16, 2022
Copy link
Contributor

@dscho dscho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make so many libsecret users happy!

@ldennington ldennington merged commit 21b1c38 into git-ecosystem:main Dec 16, 2022
Copy link
Contributor

@mjcheetham mjcheetham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job finding this!

if (accountKeyPtr != IntPtr.Zero) Marshal.FreeHGlobal(accountKeyPtr);
if (serviceKeyPtr != IntPtr.Zero) Marshal.FreeHGlobal(serviceKeyPtr);
if (value != null) secret_value_unref(value);
if (passwordPtr != IntPtr.Zero) secret_password_free(passwordPtr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow! How did I miss this? Great job

@js6pak
Copy link

js6pak commented Dec 16, 2022

Nice job finding this!

Thanks :)

only meant to be used to free nonpageable memory

You have to free pageable memory too, its just that GCM doesn't use secret_password_lookup apis for whatever reason

@ldennington
Copy link
Contributor Author

Lol indeed I can't take credit for identifying the fix. I just followed @js6pak's suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libsecret: sec_free: Assertion `cell->requested > 0' failed
4 participants