Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd0cb4e1

Browse files
committed
U Re-add flock TODO.detail.
1 parent4289cca commitd0cb4e1

File tree

1 file changed

+351
-0
lines changed

1 file changed

+351
-0
lines changed

‎doc/TODO.detail/flock

Lines changed: 351 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,351 @@
1+
From tgl@sss.pgh.pa.us Sun Aug 30 11:25:23 1998
2+
Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [206.210.65.6])
3+
by candle.pha.pa.us (8.8.5/8.8.5) with ESMTP id LAA12607
4+
for <maillist@candle.pha.pa.us>; Sun, 30 Aug 1998 11:25:20 -0400 (EDT)
5+
Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1])
6+
by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id LAA15788;
7+
Sun, 30 Aug 1998 11:23:38 -0400 (EDT)
8+
To: Bruce Momjian <maillist@candle.pha.pa.us>
9+
cc: dz@cs.unitn.it (Massimo Dal Zotto), hackers@postgreSQL.org
10+
Subject: Re: [HACKERS] flock patch breaks things here
11+
In-reply-to: Your message of Sun, 30 Aug 1998 08:19:52 -0400 (EDT)
12+
<199808301219.IAA08821@candle.pha.pa.us>
13+
Date: Sun, 30 Aug 1998 11:23:38 -0400
14+
Message-ID: <15786.904490618@sss.pgh.pa.us>
15+
From: Tom Lane <tgl@sss.pgh.pa.us>
16+
Status: RO
17+
18+
Bruce Momjian <maillist@candle.pha.pa.us> writes:
19+
> Can't we just have configure check for flock(). Another idea is to
20+
> create a 'pid' file in the pgsql/data/base directory, and do a kill -0
21+
> to see if it is stil running before removing the lock.
22+
23+
The latter approach is what I was going to suggest. Writing a pid file
24+
would be a fine idea anyway --- for one thing, it makes it a lot easier
25+
to write a "kill the postmaster" script. Given that the postmaster
26+
should write a pid file, a new postmaster should look for an existing
27+
pid file, and try to do a kill(pid, 0) on the number contained therein.
28+
If this doesn't return an error, then you figure there is already a
29+
postmaster running, complain, and exit. Otherwise you figure you is it,
30+
(re)write the pid file and away you go. Then pqcomm.c can just
31+
unconditionally delete any old file that's in the way of making the
32+
pipe.
33+
34+
The pidfile checking and creation probably ought to go in postmaster.c,
35+
not down inside pqcomm.c. I never liked the fact that a critical
36+
interlock function was being done by a low-level library that one might
37+
not even want to invoke (if all your clients are using TCP, opening up
38+
the Unix-domain socket is a waste of time, no?).
39+
40+
BTW, there is another problem with relying on flock on the socket file
41+
for this purpose: it opens up a hole for a denial-of-service attack.
42+
Anyone who can write the file can flock it. (We already had a problem
43+
with DOS via creating a dummy file at /tmp/.s.PGSQL.5432, but it would
44+
be harder to spot the culprit with an flock-based interference.)
45+
46+
regards, tom lane
47+
48+
From owner-pgsql-hackers@hub.org Sun Aug 30 12:27:41 1998
49+
Received: from hub.org (hub.org [209.47.148.200])
50+
by candle.pha.pa.us (8.8.5/8.8.5) with ESMTP id MAA12976
51+
for <maillist@candle.pha.pa.us>; Sun, 30 Aug 1998 12:27:37 -0400 (EDT)
52+
Received: from localhost (majordom@localhost) by hub.org (8.8.8/8.7.5) with SMTP id MAA09234; Sun, 30 Aug 1998 12:24:51 -0400 (EDT)
53+
Received: by hub.org (TLB v0.10a (1.23 tibbs 1997/01/09 00:29:32)); Sun, 30 Aug 1998 12:23:26 +0000 (EDT)
54+
Received: (from majordom@localhost) by hub.org (8.8.8/8.7.5) id MAA09167 for pgsql-hackers-outgoing; Sun, 30 Aug 1998 12:23:25 -0400 (EDT)
55+
Received: from mambo.cs.unitn.it (mambo.cs.unitn.it [193.205.199.204]) by hub.org (8.8.8/8.7.5) with SMTP id MAA09150 for <hackers@postgreSQL.org>; Sun, 30 Aug 1998 12:23:08 -0400 (EDT)
56+
Received: from boogie.cs.unitn.it (dz@boogie [193.205.199.79]) by mambo.cs.unitn.it (8.6.12/8.6.12) with ESMTP id SAA29572; Sun, 30 Aug 1998 18:21:42 +0200
57+
Received: (from dz@localhost) by boogie.cs.unitn.it (8.8.5/8.6.9) id SAA05993; Sun, 30 Aug 1998 18:21:41 +0200
58+
From: Massimo Dal Zotto <dz@cs.unitn.it>
59+
Message-Id: <199808301621.SAA05993@boogie.cs.unitn.it>
60+
Subject: Re: [HACKERS] flock patch breaks things here
61+
To: hackers@postgreSQL.org (PostgreSQL Hackers)
62+
Date: Sun, 30 Aug 1998 18:21:41 +0200 (MET DST)
63+
Cc: tgl@sss.pgh.pa.us (Tom Lane)
64+
In-Reply-To: <15786.904490618@sss.pgh.pa.us> from "Tom Lane" at Aug 30, 98 11:23:38 am
65+
X-Mailer: ELM [version 2.4 PL24 ME4]
66+
MIME-Version: 1.0
67+
Content-Type: text/plain; charset=iso-8859-1
68+
Content-Transfer-Encoding: 8bit
69+
Sender: owner-pgsql-hackers@hub.org
70+
Precedence: bulk
71+
Status: ROr
72+
73+
>
74+
> Bruce Momjian <maillist@candle.pha.pa.us> writes:
75+
> > Can't we just have configure check for flock(). Another idea is to
76+
> > create a 'pid' file in the pgsql/data/base directory, and do a kill -0
77+
> > to see if it is stil running before removing the lock.
78+
>
79+
> The latter approach is what I was going to suggest. Writing a pid file
80+
> would be a fine idea anyway --- for one thing, it makes it a lot easier
81+
> to write a "kill the postmaster" script. Given that the postmaster
82+
> should write a pid file, a new postmaster should look for an existing
83+
> pid file, and try to do a kill(pid, 0) on the number contained therein.
84+
> If this doesn't return an error, then you figure there is already a
85+
> postmaster running, complain, and exit. Otherwise you figure you is it,
86+
> (re)write the pid file and away you go. Then pqcomm.c can just
87+
> unconditionally delete any old file that's in the way of making the
88+
> pipe.
89+
>
90+
> The pidfile checking and creation probably ought to go in postmaster.c,
91+
> not down inside pqcomm.c. I never liked the fact that a critical
92+
> interlock function was being done by a low-level library that one might
93+
> not even want to invoke (if all your clients are using TCP, opening up
94+
> the Unix-domain socket is a waste of time, no?).
95+
>
96+
> BTW, there is another problem with relying on flock on the socket file
97+
> for this purpose: it opens up a hole for a denial-of-service attack.
98+
> Anyone who can write the file can flock it. (We already had a problem
99+
> with DOS via creating a dummy file at /tmp/.s.PGSQL.5432, but it would
100+
> be harder to spot the culprit with an flock-based interference.)
101+
102+
This came to my mind, but I didn't think this would have happened so
103+
quickly. In my opinion the socket and the pidfile should be created in a
104+
directory owned by postgres, for example /tmp/.Pgsql-unix, like does X.
105+
106+
--
107+
Massimo Dal Zotto
108+
109+
+----------------------------------------------------------------------+
110+
| Massimo Dal Zotto email: dz@cs.unitn.it |
111+
| Via Marconi, 141 phone: ++39-461-534251 |
112+
| 38057 Pergine Valsugana (TN) www: http://www.cs.unitn.it/~dz/ |
113+
| Italy pgp: finger dz@tango.cs.unitn.it |
114+
+----------------------------------------------------------------------+
115+
116+
117+
From owner-pgsql-hackers@hub.org Sun Aug 30 13:01:10 1998
118+
Received: from renoir.op.net (root@renoir.op.net [209.152.193.4])
119+
by candle.pha.pa.us (8.8.5/8.8.5) with ESMTP id NAA13785
120+
for <maillist@candle.pha.pa.us>; Sun, 30 Aug 1998 13:01:09 -0400 (EDT)
121+
Received: from hub.org (hub.org [209.47.148.200]) by renoir.op.net (o1/$ Revision: 1.18 $) with ESMTP id MAA29386 for <maillist@candle.pha.pa.us>; Sun, 30 Aug 1998 12:58:24 -0400 (EDT)
122+
Received: from localhost (majordom@localhost) by hub.org (8.8.8/8.7.5) with SMTP id MAA11406; Sun, 30 Aug 1998 12:54:48 -0400 (EDT)
123+
Received: by hub.org (TLB v0.10a (1.23 tibbs 1997/01/09 00:29:32)); Sun, 30 Aug 1998 12:52:22 +0000 (EDT)
124+
Received: (from majordom@localhost) by hub.org (8.8.8/8.7.5) id MAA11310 for pgsql-hackers-outgoing; Sun, 30 Aug 1998 12:52:20 -0400 (EDT)
125+
Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [206.210.65.6]) by hub.org (8.8.8/8.7.5) with ESMTP id MAA11296 for <hackers@postgreSQL.org>; Sun, 30 Aug 1998 12:52:13 -0400 (EDT)
126+
Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1])
127+
by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id MAA16094;
128+
Sun, 30 Aug 1998 12:50:55 -0400 (EDT)
129+
To: Massimo Dal Zotto <dz@cs.unitn.it>
130+
cc: hackers@postgreSQL.org (PostgreSQL Hackers)
131+
Subject: Re: [HACKERS] flock patch breaks things here
132+
In-reply-to: Your message of Sun, 30 Aug 1998 18:21:41 +0200 (MET DST)
133+
<199808301621.SAA05993@boogie.cs.unitn.it>
134+
Date: Sun, 30 Aug 1998 12:50:55 -0400
135+
Message-ID: <16092.904495855@sss.pgh.pa.us>
136+
From: Tom Lane <tgl@sss.pgh.pa.us>
137+
Sender: owner-pgsql-hackers@hub.org
138+
Precedence: bulk
139+
Status: RO
140+
141+
Massimo Dal Zotto <dz@cs.unitn.it> writes:
142+
> In my opinion the socket and the pidfile should be created in a
143+
> directory owned by postgres, for example /tmp/.Pgsql-unix, like does X.
144+
145+
The pidfile belongs at the top level of the database directory (eg,
146+
/usr/local/pgsql/data/postmaster.pid), because what it actually
147+
represents is that there is a postmaster running *for that database
148+
group*.
149+
150+
If you want to support multiple database sets on one machine (which I
151+
do), then the interlock has to be per database directory. Putting the
152+
pidfile into a common directory would mean we'd have to invent some
153+
kind of pidfile naming convention to keep multiple postmasters from
154+
tromping on each other. This is unnecessarily complex.
155+
156+
I agree with you that putting the socket file into a less easily munged
157+
directory than /tmp would be a good idea for security. But that's a
158+
separate issue. On machines that understand stickybits for directories,
159+
the security hole is not really very big.
160+
161+
At this point, the fact that /tmp/.s.PGSQL.port# is the socket path is
162+
effectively a version-independent aspect of the FE/BE protocol, and so
163+
we can't change it without breaking old applications. I'm not sure that
164+
that's worth the security improvement.
165+
166+
What I'd like to see someday is a postmaster command line switch to tell
167+
it to use *only* TCP connections and not create a Unix socket at all.
168+
That hasn't been possible so far, because we were relying on the socket
169+
file to provide a safety interlock against starting multiple
170+
postmasters. But an interlock using a pidfile would be much better.
171+
(Look around; *every* other Unix daemon I know of that wants to ensure
172+
that there's only one of it uses a pidfile interlock. Not file locking.
173+
There's a reason why that's the well-trodden path.)
174+
175+
regards, tom lane
176+
177+
178+
From owner-pgsql-hackers@hub.org Sun Aug 30 15:31:13 1998
179+
Received: from hub.org (hub.org [209.47.148.200])
180+
by candle.pha.pa.us (8.8.5/8.8.5) with ESMTP id PAA15275
181+
for <maillist@candle.pha.pa.us>; Sun, 30 Aug 1998 15:31:11 -0400 (EDT)
182+
Received: from localhost (majordom@localhost) by hub.org (8.8.8/8.7.5) with SMTP id PAA22194; Sun, 30 Aug 1998 15:27:20 -0400 (EDT)
183+
Received: by hub.org (TLB v0.10a (1.23 tibbs 1997/01/09 00:29:32)); Sun, 30 Aug 1998 15:23:58 +0000 (EDT)
184+
Received: (from majordom@localhost) by hub.org (8.8.8/8.7.5) id PAA21800 for pgsql-hackers-outgoing; Sun, 30 Aug 1998 15:23:57 -0400 (EDT)
185+
Received: from thelab.hub.org (nat0118.mpoweredpc.net [142.177.188.118]) by hub.org (8.8.8/8.7.5) with ESMTP id PAA21696 for <hackers@postgreSQL.org>; Sun, 30 Aug 1998 15:22:51 -0400 (EDT)
186+
Received: from localhost (scrappy@localhost)
187+
by thelab.hub.org (8.9.1/8.8.8) with SMTP id QAA18542;
188+
Sun, 30 Aug 1998 16:21:29 -0300 (ADT)
189+
(envelope-from scrappy@hub.org)
190+
X-Authentication-Warning: thelab.hub.org: scrappy owned process doing -bs
191+
Date: Sun, 30 Aug 1998 16:21:28 -0300 (ADT)
192+
From: The Hermit Hacker <scrappy@hub.org>
193+
To: Tom Lane <tgl@sss.pgh.pa.us>
194+
cc: Massimo Dal Zotto <dz@cs.unitn.it>,
195+
PostgreSQL Hackers <hackers@postgreSQL.org>
196+
Subject: Re: [HACKERS] flock patch breaks things here
197+
In-Reply-To: <16092.904495855@sss.pgh.pa.us>
198+
Message-ID: <Pine.BSF.4.02.9808301618350.343-100000@thelab.hub.org>
199+
MIME-Version: 1.0
200+
Content-Type: TEXT/PLAIN; charset=US-ASCII
201+
Sender: owner-pgsql-hackers@hub.org
202+
Precedence: bulk
203+
Status: RO
204+
205+
On Sun, 30 Aug 1998, Tom Lane wrote:
206+
207+
> Massimo Dal Zotto <dz@cs.unitn.it> writes:
208+
> > In my opinion the socket and the pidfile should be created in a
209+
> > directory owned by postgres, for example /tmp/.Pgsql-unix, like does X.
210+
>
211+
> The pidfile belongs at the top level of the database directory (eg,
212+
> /usr/local/pgsql/data/postmaster.pid), because what it actually
213+
> represents is that there is a postmaster running *for that database
214+
> group*.
215+
216+
I have to agree with this one...but then it also negates the
217+
argument about the flock() DoS...*grin*
218+
219+
BTW...I like the kill(pid,0) solution myself, primarily because it
220+
is, i think, the most portable solution.
221+
222+
I would not consider a patch to remove the flock() solution and
223+
replace it with the kill(pid,0) solution a new feature, just an
224+
improvement of an existing one...either way, moving the pid file (or
225+
socket, for that matter) from /tmp should be listed as a security related
226+
requirement for v6.4 :)
227+
228+
Marc G. Fournier
229+
Systems Administrator @ hub.org
230+
primary: scrappy@hub.org secondary: scrappy@{freebsd|postgresql}.org
231+
232+
233+
234+
From owner-pgsql-hackers@hub.org Sun Aug 30 22:41:10 1998
235+
Received: from hub.org (hub.org [209.47.148.200])
236+
by candle.pha.pa.us (8.8.5/8.8.5) with ESMTP id WAA01526
237+
for <maillist@candle.pha.pa.us>; Sun, 30 Aug 1998 22:41:08 -0400 (EDT)
238+
Received: from localhost (majordom@localhost) by hub.org (8.8.8/8.7.5) with SMTP id WAA29298; Sun, 30 Aug 1998 22:38:18 -0400 (EDT)
239+
Received: by hub.org (TLB v0.10a (1.23 tibbs 1997/01/09 00:29:32)); Sun, 30 Aug 1998 22:35:05 +0000 (EDT)
240+
Received: (from majordom@localhost) by hub.org (8.8.8/8.7.5) id WAA29203 for pgsql-hackers-outgoing; Sun, 30 Aug 1998 22:35:03 -0400 (EDT)
241+
Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [206.210.65.6]) by hub.org (8.8.8/8.7.5) with ESMTP id WAA29017 for <hackers@postgreSQL.org>; Sun, 30 Aug 1998 22:34:55 -0400 (EDT)
242+
Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1])
243+
by sss.sss.pgh.pa.us (8.9.1/8.9.1) with ESMTP id WAA20075;
244+
Sun, 30 Aug 1998 22:34:41 -0400 (EDT)
245+
To: The Hermit Hacker <scrappy@hub.org>
246+
cc: PostgreSQL Hackers <hackers@postgreSQL.org>
247+
Subject: Re: [HACKERS] flock patch breaks things here
248+
In-reply-to: Your message of Sun, 30 Aug 1998 16:21:28 -0300 (ADT)
249+
<Pine.BSF.4.02.9808301618350.343-100000@thelab.hub.org>
250+
Date: Sun, 30 Aug 1998 22:34:40 -0400
251+
Message-ID: <20073.904530880@sss.pgh.pa.us>
252+
From: Tom Lane <tgl@sss.pgh.pa.us>
253+
Sender: owner-pgsql-hackers@hub.org
254+
Precedence: bulk
255+
Status: ROr
256+
257+
The Hermit Hacker <scrappy@hub.org> writes:
258+
> either way, moving the pid file (or
259+
> socket, for that matter) from /tmp should be listed as a security related
260+
> requirement for v6.4 :)
261+
262+
Huh? There is no pid file being generated in /tmp (or anywhere else)
263+
at the moment. If we do add one, it should not go into /tmp for the
264+
reasons I gave before.
265+
266+
Where the Unix-domain socket file lives is an entirely separate issue.
267+
268+
If we move the socket out of /tmp then we have just kicked away all the
269+
work we did to preserve backwards compatibility of the FE/BE protocol
270+
with existing clients. Being able to talk to a 1.0 client isn't much
271+
good if you aren't listening where he's going to try to contact you.
272+
So I think I have to vote in favor of leaving the socket where it is.
273+
274+
regards, tom lane
275+
276+
277+
From owner-pgsql-hackers@hub.org Mon Aug 31 11:31:19 1998
278+
Received: from renoir.op.net (root@renoir.op.net [209.152.193.4])
279+
by candle.pha.pa.us (8.8.5/8.8.5) with ESMTP id LAA21195
280+
for <maillist@candle.pha.pa.us>; Mon, 31 Aug 1998 11:31:13 -0400 (EDT)
281+
Received: from hub.org (hub.org [209.47.148.200]) by renoir.op.net (o1/$ Revision: 1.18 $) with ESMTP id LAA06827 for <maillist@candle.pha.pa.us>; Mon, 31 Aug 1998 11:17:41 -0400 (EDT)
282+
Received: from localhost (majordom@localhost) by hub.org (8.8.8/8.7.5) with SMTP id LAA24792; Mon, 31 Aug 1998 11:12:18 -0400 (EDT)
283+
Received: by hub.org (TLB v0.10a (1.23 tibbs 1997/01/09 00:29:32)); Mon, 31 Aug 1998 11:10:31 +0000 (EDT)
284+
Received: (from majordom@localhost) by hub.org (8.8.8/8.7.5) id LAA24742 for pgsql-hackers-outgoing; Mon, 31 Aug 1998 11:10:29 -0400 (EDT)
285+
Received: from trillium.nmsu.edu (trillium.NMSU.Edu [128.123.5.15]) by hub.org (8.8.8/8.7.5) with ESMTP id LAA24725 for <hackers@postgreSQL.org>; Mon, 31 Aug 1998 11:10:22 -0400 (EDT)
286+
Received: (from brook@localhost)
287+
by trillium.nmsu.edu (8.8.8/8.8.8) id JAA03282;
288+
Mon, 31 Aug 1998 09:09:01 -0600 (MDT)
289+
Date: Mon, 31 Aug 1998 09:09:01 -0600 (MDT)
290+
Message-Id: <199808311509.JAA03282@trillium.nmsu.edu>
291+
From: Brook Milligan <brook@trillium.NMSU.Edu>
292+
To: tgl@sss.pgh.pa.us
293+
CC: dg@informix.com, hackers@postgreSQL.org
294+
In-reply-to: <23042.904573041@sss.pgh.pa.us> (message from Tom Lane on Mon, 31
295+
Aug 1998 10:17:21 -0400)
296+
Subject: Re: [HACKERS] flock patch breaks things here
297+
References: <23042.904573041@sss.pgh.pa.us>
298+
Sender: owner-pgsql-hackers@hub.org
299+
Precedence: bulk
300+
Status: ROr
301+
302+
I just came up with an idea that might help alleviate the /tmp security
303+
exposure without creating a backwards-compatibility problem. It works
304+
like this:
305+
306+
1. During installation, create a subdirectory of /tmp to hold Postgres'
307+
socket files and associated pid lockfiles. This subdirectory should be
308+
owned by the Postgres superuser and have permissions 755
309+
(world-readable, writable only by Postgres superuser). Maybe call it
310+
/tmp/.pgsql --- the name should start with a dot to keep it out of the
311+
way. (Bruce points out that some systems clear /tmp during reboot, so
312+
it might be that a postmaster will have to be prepared to recreate this
313+
directory at startup --- anyone know if subdirectories of /tmp are
314+
zapped too? My system doesn't do that...)
315+
316+
...
317+
318+
I notice that on my system, the X11 socket files in /tmp/.X11-unix are
319+
actually symlinks to socket files in /usr/spool/sockets/X11. I dunno if
320+
it's worth our trouble to get into putting our sockets under /usr/spool
321+
or /var/spool or whatever --- seems like another configuration choice to
322+
mess up. It'd be nice if the socket directory lived somewhere where the
323+
parent dirs weren't world-writable, but this would mean one more thing
324+
that you have to have root permissions for in order to install pgsql.
325+
326+
It seems like we need a directory for locks (= pid files) and one for
327+
sockets (perhaps the same one). I strongly suggest that the location
328+
for these be configurable. By default, it might make sense to put
329+
them in ~pgsql/locks and ~pgsql/sockets. It is easy (i.e., I'll be
330+
glad to do it) to modify configure.in to take options like
331+
332+
--lock-dir=/var/spool/lock
333+
--socket-dir=/var/spool/sockets
334+
335+
that set cc defines and have the code respond accordingly. This way,
336+
those who don't care (or don't have root access) can use the defaults,
337+
whereas those with root access who like to keep locks and sockets in a
338+
common place can do so easily. Either way, multiple postmasters (all
339+
compiled with the same options of course) can check the appropriate
340+
locks in the well-known places. Finally, drop the link into /tmp for
341+
the old socket and document that it will be disappearing at some
342+
point, and all is fine.
343+
344+
If someone wants to give me some guidance on what preprocessor
345+
variables should be set in response to the above options (or something
346+
like them), I'll do the configure stuff.
347+
348+
Cheers,
349+
Brook
350+
351+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp