]> granicus.if.org Git - postgresql/commitdiff
Require update permission for the large object written by lo_put().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 7 Aug 2017 14:19:01 +0000 (10:19 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 7 Aug 2017 14:19:21 +0000 (10:19 -0400)
lo_put() surely should require UPDATE permission, the same as lowrite(),
but it failed to check for that, as reported by Chapman Flack.  Oversight
in commit c50b7c09d; backpatch to 9.4 where that was introduced.

Tom Lane and Michael Paquier

Security: CVE-2017-7548

src/backend/libpq/be-fsstubs.c
src/test/regress/expected/privileges.out
src/test/regress/sql/privileges.sql

index 89da68f9040676b9933549d5961e972a89f746ca..75e3b8da4be6cc73287796f3ed1a05d12427b329 100644 (file)
@@ -898,6 +898,18 @@ lo_put(PG_FUNCTION_ARGS)
        CreateFSContext();
 
        loDesc = inv_open(loOid, INV_WRITE, fscxt);
+
+       /* Permission check */
+       if (!lo_compat_privileges &&
+               pg_largeobject_aclcheck_snapshot(loDesc->id,
+                                                                                GetUserId(),
+                                                                                ACL_UPDATE,
+                                                                                loDesc->snapshot) != ACLCHECK_OK)
+               ereport(ERROR,
+                               (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+                                errmsg("permission denied for large object %u",
+                                               loDesc->id)));
+
        inv_seek(loDesc, offset, SEEK_SET);
        written = inv_write(loDesc, VARDATA_ANY(str), VARSIZE_ANY_EXHDR(str));
        Assert(written == VARSIZE_ANY_EXHDR(str));
index 9fbcfa7e6b6fa367d1a60dab8747098ff3ea73c6..37ecf5c1ac2c0c09cc325c3d80ebd835a627330d 100644 (file)
@@ -1220,6 +1220,14 @@ SELECT lo_create(2002);
       2002
 (1 row)
 
+SELECT loread(lo_open(1001, x'20000'::int), 32);       -- allowed, for now
+ loread 
+--------
+ \x
+(1 row)
+
+SELECT lowrite(lo_open(1001, x'40000'::int), 'abcd');  -- fail, wrong mode
+ERROR:  large object descriptor 0 was not opened for writing
 SELECT loread(lo_open(1001, x'40000'::int), 32);
  loread 
 --------
@@ -1315,6 +1323,8 @@ SELECT lowrite(lo_open(1002, x'20000'::int), 'abcd');     -- to be denied
 ERROR:  permission denied for large object 1002
 SELECT lo_truncate(lo_open(1002, x'20000'::int), 10);  -- to be denied
 ERROR:  permission denied for large object 1002
+SELECT lo_put(1002, 1, 'abcd');                                -- to be denied
+ERROR:  permission denied for large object 1002
 SELECT lo_unlink(1002);                                        -- to be denied
 ERROR:  must be owner of large object 1002
 SELECT lo_export(1001, '/dev/null');                   -- to be denied
index 9368f96035d29ac62af0fd5e9ad5db4a41febb54..ab67508e60ea86b03939808cded770292049046a 100644 (file)
@@ -770,6 +770,9 @@ SET SESSION AUTHORIZATION regressuser2;
 SELECT lo_create(2001);
 SELECT lo_create(2002);
 
+SELECT loread(lo_open(1001, x'20000'::int), 32);       -- allowed, for now
+SELECT lowrite(lo_open(1001, x'40000'::int), 'abcd');  -- fail, wrong mode
+
 SELECT loread(lo_open(1001, x'40000'::int), 32);
 SELECT loread(lo_open(1002, x'40000'::int), 32);       -- to be denied
 SELECT loread(lo_open(1003, x'40000'::int), 32);
@@ -809,6 +812,7 @@ SET SESSION AUTHORIZATION regressuser4;
 SELECT loread(lo_open(1002, x'40000'::int), 32);       -- to be denied
 SELECT lowrite(lo_open(1002, x'20000'::int), 'abcd');  -- to be denied
 SELECT lo_truncate(lo_open(1002, x'20000'::int), 10);  -- to be denied
+SELECT lo_put(1002, 1, 'abcd');                                -- to be denied
 SELECT lo_unlink(1002);                                        -- to be denied
 SELECT lo_export(1001, '/dev/null');                   -- to be denied