Bug 235296

Summary: www/nginx: spnego-http-auth-nginx-module crashes worker process due to read-after-free
Product: Ports & Packages Reporter: topical <topical>
Component: Individual Port(s)Assignee: Jochen Neumeister <joneum>
Status: Closed FIXED    
Severity: Affects Some People CC: andris, chris, joneum, osa, pi
Priority: --- Flags: bugzilla: maintainer-feedback? (joneum)
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Patch to remove obsolete (broken) putenv() code.
none
2 minute stuck after init 6
none
stuck on sync none

Description topical 2019-01-29 14:01:26 UTC
The current version uses putenv() to pass the name of the keytab to GSS.

Incorrectly, it assumes that putenv() creates a copy of the passed string. This leads to corruption of environment variables and eventually to a core dump. Usually, this happens unnoticed due to the auto-recovery feature of nginx work process.

Actually, putenv isn't really needed anymore and the affected code can be removed safely.
Comment 1 topical 2019-01-29 14:04:01 UTC
Created attachment 201506 [details]
Patch to remove obsolete (broken) putenv() code.

Need to add the following files to "Makefile.extmod" to activate patch:

HTTP_AUTH_KRB5_EXTRA_PATCHES=   ${PATCHDIR}/extra-patch-spnego-http-auth-nginx-module-config \
                                ${PATCHDIR}/extra-patch-spnego-http-auth-nginx-no-putenv
Comment 2 topical 2019-02-26 16:35:51 UTC
Is there anything else needed to apply the patch to the ports tree?
Comment 3 topical 2019-07-22 11:26:54 UTC
Hi there!

When I updated to the new quarterly ports release, I still had to see that the putenv() bug is still in there.

Is there anyone who can finally please apply the patch? This would be great.
Comment 4 commit-hook freebsd_committer freebsd_triage 2019-11-16 19:36:39 UTC
A commit references this bug:

Author: osa
Date: Sat Nov 16 19:36:15 UTC 2019
New revision: 517770
URL: https://svnweb.freebsd.org/changeset/ports/517770

Log:
  When nginx compiled with third-party spnego module, a worker process
  may crash due to read-after-free operation.  This third-party module
  update fix the issue.

  Bump PORTREVISION.

  PR:	235296

Changes:
  head/www/nginx-devel/Makefile
  head/www/nginx-devel/Makefile.extmod
  head/www/nginx-devel/distinfo
Comment 5 Sergey A. Osokin freebsd_committer freebsd_triage 2019-11-16 19:40:20 UTC
Hi there,

thanks for the report and the patch.

I've found the patch has been committed to the upstream as https://github.com/stnoonan/spnego-http-auth-nginx-module/commit/21bb963666480ca87e8051459bcd7cd35cc46df4, so I've just updated the third-party module version to 21bb963 for www/nginx-devel port.


I believe Jochen will commit the update soon.

Thanks.
Comment 6 topical 2019-11-18 12:30:57 UTC
Great! Thanks a lot
Comment 7 commit-hook freebsd_committer freebsd_triage 2019-11-26 16:33:25 UTC
A commit references this bug:

Author: joneum
Date: Tue Nov 26 16:32:39 UTC 2019
New revision: 518471
URL: https://svnweb.freebsd.org/changeset/ports/518471

Log:
  When nginx compiled with third-party spnego module, a worker process
  may crash due to read-after-free operation.  This third-party module
  update fix the issue.

  PR:	235296
  Sponsored by:	Netzkommune GmbH

Changes:
  head/www/nginx/Makefile
  head/www/nginx/Makefile.extmod
  head/www/nginx/distinfo
Comment 8 Andris Vasers 2019-12-13 20:08:35 UTC
root@web1:~ # kill -9 1106
root@web1:~ # kill -9 1106
root@web1:~ # kill -9 1106
root@web1:~ # kill -9 1106
root@web1:~ # kill -9 1106
root@web1:~ # kill -9 1104
root@web1:~ # kill -9 1104
root@web1:~ # kill -9 1104
root@web1:~ # kill -9 1104
root@web1:~ # kill -9 1104
root@web1:~ # kill -9 1104


kill doesn't help

tryiing restart:

root@web1:~ # /usr/local/etc/rc.d/nginx restart
Performing sanity check on nginx configuration:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
Stopping nginx.
Waiting for PIDS: 1103

and stuck on PID 1103
Comment 9 Andris Vasers 2019-12-13 20:13:18 UTC
Created attachment 209921 [details]
2 minute stuck after init 6
Comment 10 Andris Vasers 2019-12-13 20:14:25 UTC
Created attachment 209922 [details]
stuck on sync

after stuck sync process begun and now it's still syncing infinite way
Comment 11 Sergey A. Osokin freebsd_committer freebsd_triage 2019-12-13 20:18:22 UTC
(In reply to Andris Vasers from comment #8)
Hi Andris,

thanks for the report.

Hope it's possible to recompile nginx from ports tree with debugging information and reproduce the case.
Also, it's possible to use dtrace for research, http://nginx.org/en/docs/nginx_dtrace_pid_provider.html

I'd like to ask you to inform the vendor of the third-party module about the issue.

Thank you.
Comment 12 Jochen Neumeister freebsd_committer freebsd_triage 2019-12-14 12:30:49 UTC
hmmm .... is this the same Problem?
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=242626