Fix: fixing security issue with ngx_palloc in set_to_pam_env#32
Open
StepanGulyaev wants to merge 2 commits intosto:masterfrom
Open
Fix: fixing security issue with ngx_palloc in set_to_pam_env#32StepanGulyaev wants to merge 2 commits intosto:masterfrom
StepanGulyaev wants to merge 2 commits intosto:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello! I was analyzing your module with Svace SAST tool and found vulnerability in
set_to_pam_envfunction. The problem isngx_pallocfunction return value not being checked though it should. Here is source code:ngx_http_auth_pam_module/ngx_http_auth_pam_module.c
Lines 240 to 250 in d9429ba
ngx_pallocis guaranteed not to return NULL only if free space exists for the variable in one of the existing pools in the linked list (refer to howngx_palloc_smallworks). We cannot guarantee with absolute certainty that such space will always be available. If space is unavailable, memory allocation will be triggered: firstngx_palloc_blockwill be called, followed byngx_memalign, which internally allocates memory viaposix_memalignormemalign. These functions may return NULL. Therefore,ngx_pallocand functions using it should always be checked.However because
set_to_pam_envis static void function we can't just put NULL check because we should return value. Because of that my patch changes return type of two functions:set_to_pam_envandadd_request_info_to_pam_envand also adds check intongx_http_auth_pam_authenticate. I've tested it and everything works fine. Ifadd_request_info_to_pam_envreturns NGX_ERROR server will sent INTERNAL SERVER ERROR:Found by Linux Verification Center (linuxtesting.org) with SVACE.