Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dt9oL-0006Ip-06 for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Sep 2017 09:54:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dt9oK-0005S2-HS for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Sep 2017 09:54:52 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dt9oJ-0005Rs-Sd for pgsql-bugs@postgresql.org; Sat, 16 Sep 2017 09:54:52 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dt9oG-0005jn-D7 for pgsql-bugs@postgresql.org; Sat, 16 Sep 2017 09:54:50 +0000 Received: by mail-wm0-x232.google.com with SMTP id 13so13007742wmq.2 for ; Sat, 16 Sep 2017 02:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=Mj+2CCFWj7aSrXmpPzheLfkEj78ebdq8o+BHyQ+dZ4Y=; b=LlOsv5jpESBhm310Dn/lHZryynpIATWWQgH1ur6ANdtSmxKP8A9/oZW9/7pMbRZsW6 zkXthtaLXbcf5m6uzOole+rRPNRF1WUtXoZ8fVC27qa2KjwAatjvvoY96KcYHFFB4d6e h+l++2CvRLsym0Iv2ZcjJBA2QkhVGWJtR1cQTG46ei215qFddhPDnGy+xteoA2aFPxcM HeQ/ucI7FRoeWV2zVLcnNIp03vMUCJO1hPcIMHabZzymqhLq9/LzfZc3ViJIMvg2azAL KWCf0lBkSe/fDvFCjobcn0wvT6gQAyXdHnorY9DOc1nlHSOIVuUM20Nt0M7iwe8kkGhy FBuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Mj+2CCFWj7aSrXmpPzheLfkEj78ebdq8o+BHyQ+dZ4Y=; b=rYM6ASj54Vi/uViQBWkFrNFBTRfpVrHJCeVL2JUw+/dQpulhOIwy60offB2boR8GL9 6YkQhbXfz2tVxpbutnUt+GdLsa0O6Lx7b4e4D/7p4CzhmEo9tWC/iWmnL6WVF92R9RAZ dGj5m+95s5Gk5VSrEo+xaABPY1Snp5hs6RD4V89Rg2xZLYz3AZAkmcyKdWmI19IXbpGL mAXaszw9TAV9pPw2u2GtCetvlnXA/YALQKzIkCS9DiwVpzNhMUXsqnFrm69xRYFcgzt8 YHyIXNjJwDfexpYLBgnO4E/D6ZBZWLg0/+nudY779OOu2fHoIP5xNLC3PLESqM31Kqx4 3nMw== X-Gm-Message-State: AHPjjUg2HQbN7ROPE0+KqzhYqPwGHNenqCI6XjdXHVwFmLnhGQtBPFzf jY09Azwd6qBBIcGUVqLkxsMgUKvehD7T+B9BJMcX8VrdEFB8Z95Ugf9N3r7No6Pjkxp9AGynnDI wq6YT6cclONPSHJ/z5q9eH3/oc3RyT75dJFJdC7oK8zJ0yskuf+eboUnIf9TXN80UwtrFZe0= X-Google-Smtp-Source: AOwi7QAbBUXPHxwr/swMp6ZYf6nF/fjWvq9B7H9kpjhFdenV6GoGwV9NZWxRITzhzaYLr+t9PqF8DQ== X-Received: by 10.28.93.145 with SMTP id r139mr4998215wmb.115.1505555685442; Sat, 16 Sep 2017 02:54:45 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id 6sm2476457wru.33.2017.09.16.02.54.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Sep 2017 02:54:44 -0700 (PDT) Subject: =?UTF-8?Q?Re:__=e3=80=91?= To: "postgresql_2016@163.com" , pgsql-bugs@postgresql.org References: <1505549162782-0.post@n3.nabble.com> From: Tomas Vondra Message-ID: Date: Sat, 16 Sep 2017 11:54:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1505549162782-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 09/16/2017 10:06 AM, postgresql_2016@163.com wrote: > 1、Through our security test, we find the *copy from* command can read any > files from the server if it has the read permission,for example, /etc/passwd > file. Although, the pg_read_file or pg_read_binary_file function restricts > the file read path, which only can read files from the PGDATA directory. > > For example, the next example can read the server file. > > [postgres@X86C136 ~]$ psql postgres -p 5432 > psql (9.2.22) > Type "help" for help. > > postgres=# create table test(va varchar); > CREATE TABLE > postgres=# copy test from '/etc/passwd'; > COPY 37 > postgres=# select * from test; > va > ----------------------------------------------------------------------------------------------------- > root:x:0:0:root:/root:/bin/bash > bin:x:1:1:bin:/bin:/sbin/nologin > daemon:x:2:2:daemon:/sbin:/sbin/nologin > adm:x:3:4:adm:/var/adm:/sbin/nologin > lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin > sync:x:5:0:sync:/sbin:/bin/sync > shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown > halt:x:7:0:halt:/sbin:/sbin/halt > mail:x:8:12:mail:/var/spool/mail:/sbin/nologin > operator:x:11:0:operator:/root:/sbin/nologin > games:x:12:100:games:/usr/games:/sbin/nologin > ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin > nobody:x:99:99:Nobody:/:/sbin/nologin > systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin > systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin > dbus:x:81:81:System message bus:/:/sbin/nologin > polkitd:x:998:996:User for polkitd:/:/sbin/nologin > tss:x:59:59:Account used by the trousers package to sandbox the tcsd > daemon:/dev/null:/sbin/nologin > postfix:x:89:89::/var/spool/postfix:/sbin/nologin > sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin > chrony:x:997:995::/var/lib/chrony:/sbin/nologin > postgres:x:1000:1000::/home/postgres:/bin/bash > hsqldb:x:96:96::/var/lib/hsqldb:/sbin/nologin > davinci:x:1001:1001::/home/davinci:/bin/bash > tcpdump:x:72:72::/:/sbin/nologin > cassandra:x:1002:1002::/home/cassandra:/bin/bash > usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin > rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin > qemu:x:107:107:qemu user:/:/sbin/nologin > apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin > pcp:x:996:994:Performance Co-Pilot:/var/lib/pcp:/sbin/nologin > saslauth:x:995:76:Saslauthd user:/run/saslauthd:/sbin/nologin > sssd:x:994:993:User for sssd:/:/sbin/nologin > unbound:x:993:992:Unbound DNS resolver:/etc/unbound:/sbin/nologin > rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin > nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin > radvd:x:75:75:radvd user:/:/sbin/nologin > (37 rows) > > postgres=# select version(); > version > ---------------------------------------------------------------------------------------------------------------- > PostgreSQL 9.2.22 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.8.5 > 20150623 (Red Hat 4.8.5-11), 64-bit > (1 row) > > 2、Also, another command "copy to" can write any files in the server if it > has the write privileges. > > For example, when copy the table test to the postgresql.conf file, it > will modifiy the postgresql.conf file. > > [postgres@X86C136 data]$ psql -d postgres -p 5432 > psql (9.2.22) > Type "help" for help. > > postgres=# copy test to '/home/postgres/data/postgresql.conf'; > COPY 37 > postgres=# > > 3、So, I think we should restrict the copy directory like pg_read_file or > pg_read_binary_file function. > I'm pretty sure this is why COPY TO/FROM a file is restricted to superusers, and regular users will get an error. I'm not sure what you mean by "our security test" but if you're running it under superuser account, you're probably doing it wrong. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs