8000 Ignore SECURITY DEFINER and SET attributes for a PL's call handler. · jcsston/postgres@b53c7c3 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit b53c7c3

Browse files
committed
Ignore SECURITY DEFINER and SET attributes for a PL's call handler.
It's not very sensible to set such attributes on a handler function; but if one were to do so, fmgr.c went into infinite recursion because it would call fmgr_security_definer instead of the handler function proper. There is no way for fmgr_security_definer to know that it ought to call the handler and not the original function referenced by the FmgrInfo's fn_oid, so it tries to do the latter, causing the whole process to start over again. Ordinarily such misconfiguration of a procedural language's handler could be written off as superuser error. However, because we allow non-superuser database owners to create procedural languages and the handler for such a language becomes owned by the database owner, it is possible for a database owner to crash the backend, which ideally shouldn't be possible without superuser privileges. In 9.2 and up we will adjust things so that the handler functions are always owned by superusers, but in existing branches this is a minor security fix. Problem noted by Noah Misch (after several of us had failed to detect it :-(). This is CVE-2012-2655.
1 parent 9b0875a commit b53c7c3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/backend/utils/fmgr/fmgr.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fmgr_lookupByName(const char *name)
153153
void
154154
fmgr_info(Oid functionId, FmgrInfo *finfo)
155155
{
156-
fmgr_info_cxt(functionId, finfo, CurrentMemoryContext);
156+
fmgr_info_cxt_security(functionId, finfo, CurrentMemoryContext, false);
157157
}
158158

159159
/*
@@ -168,7 +168,7 @@ fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
168168

169169
/*
170170
* This one does the actual work. ignore_security is ordinarily false
171-
* but is set to true by fmgr_security_definer to avoid recursion.
171+
* but is set to true when we need to avoid recursion.
172172
*/
173173
static void
174174
fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt,
@@ -218,7 +218,7 @@ fmgr_info_cxt_security(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt,
218218
/*
219219
* If it has prosecdef set, or non-null proconfig, use
220220
* fmgr_security_definer call handler --- unless we are being called again
221-
* by fmgr_security_definer.
221+
* by fmgr_security_definer or fmgr_info_other_lang.
222222
*
223223
* When using fmgr_security_definer, function stats tracking is always
224224
* disabled at the outer level, and instead we set the flag properly in
@@ -399,7 +399,13 @@ fmgr_info_other_lang(Oid functionId, FmgrInfo *finfo, HeapTuple procedureTuple)
399399
elog(ERROR, "cache lookup failed for language %u", language);
400400
languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
401401

402-
fmgr_info(languageStruct->lanplcallfoid, &plfinfo);
402+
/*
403+
* Look up the language's call handler function, ignoring any attributes
404+
* that would normally cause insertion of fmgr_security_definer. We
405+
* need to get back a bare pointer to the actual C-language function.
406+
*/
407+
fmgr_info_cxt_security(languageStruct->lanplcallfoid, &plfinfo,
408+
CurrentMemoryContext, true);
403409
finfo->fn_addr = plfinfo.fn_addr;
404410

405411
/*

0 commit comments

Comments
 (0)
0