Issue 8698 - ppolicy: responses from pwdCheckModule discarded when using an extended password modify
Summary: ppolicy: responses from pwdCheckModule discarded when using an extended passw...
Status: VERIFIED FIXED
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: overlays (show other issues)
Version: 2.4.42
Hardware: All All
: --- normal
Target Milestone: 2.5.3
Assignee: Ondřej Kuzník
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-26 11:36 UTC by tim@bishnet.net
Modified: 2023-01-27 03:20 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description tim@bishnet.net 2017-07-26 11:36:46 UTC
Full_Name: Tim Bishop
Version: 2.4.42
OS: Ubuntu 16.04
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (2001:630:340:1141::13)


Whilst this issue was discovered on OpenLDAP 2.4.42, the code is unchanged on
the latest version, so I believe it is still applicable there.

The high-level overview of the problem is that when using the ppolicy overlay
with an external pwdCheckModule, and a password is changed using the LDAPv3
Password Modify (RFC 3062) extended operation (ie. ldappasswd), the message
returned by the pwdCheckModule is not passed back to the user. All other failure
messages generated in ppolicy are returned correctly.

I've looked into this and discovered the cause of the problem. We can start by
looking at where the message is returned:

https://github.com/openldap/openldap/blob/OPENLDAP_REL_ENG_2_4_42/servers/slapd/overlays/ppolicy.c#L1941

The check_password_quality function calls out to the pwdCheckModule which sets
txt to point at a malloc'd string. Here we set rs->sr_text to point to that, and
make a note to free it later. This is the exception, in all other cases, as can
be seen a few lines below, rs->sr_text is set to a static string.

Later on, the result is returned to the user:

https://github.com/openldap/openldap/blob/OPENLDAP_REL_ENG_2_4_42/servers/slapd/overlays/ppolicy.c#L2203

And then after that, it is free'd.

This all works fine for a normal password modify operation. The problem occurs
when we wrap this in an extended password modify:

https://github.com/openldap/openldap/blob/OPENLDAP_REL_ENG_2_4_42/servers/slapd/extended.c#L222

This line is where the call into ppolicy originates (with a few steps in
between), and then on line 237 below we see a call to send_ldap_extended (which
returns rs->sr_text to the user) that includes a pointer to rs. In cases where
rs->sr_text is a static string this is fine, but where we've set it to a
response from pwdCheckModule it has at this point been free'd and set to NULL
before send_ldap_extended gets a chance to send it.

The result is that confusingly the response from pwdCheckModule is returned for
non-extended password changes, but not for extended ones.

I don't have a fix for this since I'm not familiar enough with the slapd code.
But I'd imagine it'd require setting a flag either in rs or op to note when
free'ing of rs->sr_text is required, and then move that free call as far out as
necessary (back to where rs is created in connection.c?) so that rs->sr_text is
always available.
Comment 2 Quanah Gibson-Mount 2021-03-30 14:59:17 UTC
Commits: 
  • 0df931b9 
by Ondřej Kuzník at 2021-03-30T02:10:19+00:00 
ITS#8698 Only remove our own callback


  • 51c444b0 
by Ondřej Kuzník at 2021-03-30T02:10:19+00:00 
ITS#8698 Defer policy checker cleanup if it's a pw extop
Comment 3 subbarao@computer.org 2023-01-26 22:56:52 UTC
Part of the fix for this change breaks exop overlay callbacks. Fortunately the fix is simple, just revert the change to passwd.c. The rest works fine. Please see ITS#9990 for more details:

https://bugs.openldap.org/show_bug.cgi?id=9990