Skip to content

Commit 602a9ef

Browse files
committed
Make LOAD of an already-loaded library into a no-op, instead of attempting
to unload and re-load the library. The difficulty with unloading a library is that we haven't defined safe protocols for doing so. In particular, there's no safe mechanism for getting out of a "hook" function pointer unless libraries are unloaded in reverse order of loading. And there's no mechanism at all for undefining a custom GUC variable, so GUC would be left with a pointer to an old value that might or might not still be valid, and very possibly wouldn't be in the same place anymore. While the unload and reload behavior had some usefulness in easing development of new loadable libraries, it's of no use whatever to normal users, so just disabling it isn't giving up that much. Someday we might care to expend the effort to develop safe unload protocols; but even if we did, there'd be little certainty that every third-party loadable module was following them, so some security restrictions would still be needed. Back-patch to 8.2; before that, LOAD was superuser-only anyway. Security: unprivileged users could crash backend. CVE not assigned yet
1 parent 187e5d8 commit 602a9ef

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

doc/src/sgml/ref/create_function.sgml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.84 2008/12/31 02:25:03 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.85 2009/09/03 22:11:07 tgl Exp $
33
-->
44

55
<refentry id="SQL-CREATEFUNCTION">
@@ -528,8 +528,7 @@ CREATE FUNCTION foo(int, int default 42) ...
528528
When repeated <command>CREATE FUNCTION</command> calls refer to
529529
the same object file, the file is only loaded once per session.
530530
To unload and
531-
reload the file (perhaps during development), use the <xref
532-
linkend="sql-load" endterm="sql-load-title"> command.
531+
reload the file (perhaps during development), start a new session.
533532
</para>
534533

535534
<para>

doc/src/sgml/ref/load.sgml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/load.sgml,v 1.25 2008/11/14 10:22:47 petere Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/load.sgml,v 1.26 2009/09/03 22:11:07 tgl Exp $
33
-->
44

55
<refentry id="SQL-LOAD">
@@ -11,7 +11,7 @@ $PostgreSQL: pgsql/doc/src/sgml/ref/load.sgml,v 1.25 2008/11/14 10:22:47 petere
1111

1212
<refnamediv>
1313
<refname>LOAD</refname>
14-
<refpurpose>load or reload a shared library file</refpurpose>
14+
<refpurpose>load a shared library file</refpurpose>
1515
</refnamediv>
1616

1717
<indexterm zone="sql-load">
@@ -29,13 +29,12 @@ LOAD '<replaceable class="PARAMETER">filename</replaceable>'
2929

3030
<para>
3131
This command loads a shared library file into the <productname>PostgreSQL</>
32-
server's address space. If the file had been loaded previously,
33-
it is first unloaded. This command is primarily useful to unload
34-
and reload a shared library file that has been changed since the
35-
server first loaded it. To make use of the shared library,
36-
function(s) in it need to be declared using the <xref
37-
linkend="sql-createfunction" endterm="sql-createfunction-title">
38-
command.
32+
server's address space. If the file has been loaded already,
33+
the command does nothing. Shared library files that contain C functions
34+
are automatically loaded whenever one of their functions is called.
35+
Therefore, an explicit <command>LOAD</> is usually only needed to
36+
load a library that modifies the server's behavior through <quote>hooks</>
37+
rather than providing a set of functions.
3938
</para>
4039

4140
<para>

doc/src/sgml/xfunc.sgml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.138 2009/05/27 01:18:06 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.139 2009/09/03 22:11:07 tgl Exp $ -->
22

33
<sect1 id="xfunc">
44
<title>User-Defined Functions</title>
@@ -1481,9 +1481,7 @@ PG_MODULE_MAGIC;
14811481
file is retained in memory. Future calls in the same session to
14821482
the function(s) in that file will only incur the small overhead of
14831483
a symbol table lookup. If you need to force a reload of an object
1484-
file, for example after recompiling it, use the <xref
1485-
linkend="sql-load" endterm="sql-load-title"> command or begin a
1486-
fresh session.
1484+
file, for example after recompiling it, begin a fresh session.
14871485
</para>
14881486

14891487
<indexterm zone="xfunc-c-dynload">
@@ -1509,8 +1507,8 @@ PG_MODULE_MAGIC;
15091507
unloading the file. Likewise, the function receives no parameters and
15101508
should return void. Note that <function>_PG_fini</> will only be called
15111509
during an unload of the file, not during process termination.
1512-
(Presently, an unload only happens in the context of re-loading
1513-
the file due to an explicit <command>LOAD</> command.)
1510+
(Presently, unloads are disabled and will never occur, but this may
1511+
change in the future.)
15141512
</para>
15151513

15161514
</sect2>

src/backend/utils/fmgr/dfmgr.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.99 2009/06/11 14:49:05 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.100 2009/09/03 22:11:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -385,10 +385,17 @@ incompatible_module_error(const char *libname,
385385
* Unload the specified dynamic-link library file, if it is loaded.
386386
*
387387
* Note: libname is expected to be an exact name for the library file.
388+
*
389+
* XXX for the moment, this is disabled, resulting in LOAD of an already-loaded
390+
* library always being a no-op. We might re-enable it someday if we can
391+
* convince ourselves we have safe protocols for un-hooking from hook function
392+
* pointers, releasing custom GUC variables, and perhaps other things that
393+
* are definitely unsafe currently.
388394
*/
389395
static void
390396
internal_unload_library(const char *libname)
391397
{
398+
#ifdef NOT_USED
392399
DynamicFileList *file_scanner,
393400
*prv,
394401
*nxt;
@@ -436,6 +443,7 @@ internal_unload_library(const char *libname)
436443
else
437444
prv = file_scanner;
438445
}
446+
#endif /* NOT_USED */
439447
}
440448

441449
static bool

0 commit comments

Comments
 (0)