pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14615: ReplicationOriginShmemInit Memory access cross-border
4+ messages / 3 participants
[nested] [flat]
* BUG #14615: ReplicationOriginShmemInit Memory access cross-border
@ 2017-04-10 06:26 bret.shao@outlook.com
0 siblings, 1 reply; 4+ messages in thread
From: bret.shao@outlook.com @ 2017-04-10 06:26 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14615
Logged by: bret shao
Email address: bret.shao@outlook.com
PostgreSQL version: 9.6.2
Operating system: linux
Description:
MemSet(replication_states, 0, ReplicationOriginShmemSize()); in function
ReplicationOriginShmemInit cause cross-border,because that start address of
the share memory allocated is replication_states_ctl, but call MemSet to
initialize this memory start from replication_states which is variable
states's address in struct ReplicationStateCtl.so call MemSet to set 0 with
the total size of this share memory will cross border of this share memory.
Although, this cross-border will not caused the system failure due to share
memory allocation strategy after my analysis. but i still believe we
shouldn't do like this.
Fix suggestion:
change to
MemSet(replication_states_ctl, 0, ReplicationOriginShmemSize()); then move
to the beginning of if statement.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #14615: ReplicationOriginShmemInit Memory access cross-border
@ 2017-04-10 06:38 Michael Paquier <michael.paquier@gmail.com>
parent: bret.shao@outlook.com
0 siblings, 1 reply; 4+ messages in thread
From: Michael Paquier @ 2017-04-10 06:38 UTC (permalink / raw)
To: bret.shao@outlook.com; +Cc: pgsql-bugs; Andres Freund <andres@anarazel.de>
On Mon, Apr 10, 2017 at 3:26 PM, <bret.shao@outlook.com> wrote:
> MemSet(replication_states, 0, ReplicationOriginShmemSize()); in function
> ReplicationOriginShmemInit cause cross-border,because that start address of
> the share memory allocated is replication_states_ctl, but call MemSet to
> initialize this memory start from replication_states which is variable
> states's address in struct ReplicationStateCtl.so call MemSet to set 0 with
> the total size of this share memory will cross border of this share memory.
>
> Although, this cross-border will not caused the system failure due to share
> memory allocation strategy after my analysis. but i still believe we
> shouldn't do like this.
>
> Fix suggestion:
> change to
> MemSet(replication_states_ctl, 0, ReplicationOriginShmemSize()); then move
> to the beginning of if statement.
Yes, there is a mistake here, but I don't agree with your solution. It
seems to me that using mul_size(max_replication_slots,
sizeof(ReplicationState)) is the way to go as you would reinitialize
what has been set in tranche_id. Per se the attached.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
replorigin-shmem-fix.patch (application/octet-stream, 617B) download
diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
index 5eaf863e02..0aa468789c 100644
--- a/src/backend/replication/logical/origin.c
+++ b/src/backend/replication/logical/origin.c
@@ -473,7 +473,8 @@ ReplicationOriginShmemInit(void)
replication_states_ctl->tranche_id = LWTRANCHE_REPLICATION_ORIGIN;
- MemSet(replication_states, 0, ReplicationOriginShmemSize());
+ MemSet(replication_states, 0,
+ mul_size(max_replication_slots, sizeof(ReplicationState)));
for (i = 0; i < max_replication_slots; i++)
LWLockInitialize(&replication_states[i].lock,
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #14615: ReplicationOriginShmemInit Memory access cross-border
@ 2017-04-11 15:20 Andres Freund <andres@anarazel.de>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Andres Freund @ 2017-04-11 15:20 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-bugs
On 2017-04-10 15:38:56 +0900, Michael Paquier wrote:
> diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
> index 5eaf863e02..0aa468789c 100644
> --- a/src/backend/replication/logical/origin.c
> +++ b/src/backend/replication/logical/origin.c
> @@ -473,7 +473,8 @@ ReplicationOriginShmemInit(void)
>
> replication_states_ctl->tranche_id = LWTRANCHE_REPLICATION_ORIGIN;
>
> - MemSet(replication_states, 0, ReplicationOriginShmemSize());
> + MemSet(replication_states, 0,
> + mul_size(max_replication_slots, sizeof(ReplicationState)));
What's the benefit of using mul_size here? That's usually only
beneficial in the original size computation - during use/initialization
an actual error should be impossible.
To me the right fix seems to be to just do:
- replication_states_ctl->tranche_id = LWTRANCHE_REPLICATION_ORIGIN;
-
- MemSet(replication_states, 0, ReplicationOriginShmemSize());
+ MemSet(replication_states_ctl, 0, ReplicationOriginShmemSize());
+
+ replication_states_ctl->tranche_id = LWTRANCHE_REPLICATION_ORIGIN;
No?
Greetings,
Andres Freund
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #14615: ReplicationOriginShmemInit Memory access cross-border
@ 2017-04-11 23:49 Michael Paquier <michael.paquier@gmail.com>
parent: Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 4+ messages in thread
From: Michael Paquier @ 2017-04-11 23:49 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-bugs
On Wed, Apr 12, 2017 at 12:20 AM, Andres Freund <andres@anarazel.de> wrote:
> On 2017-04-10 15:38:56 +0900, Michael Paquier wrote:
>> diff --git a/src/backend/replication/logical/origin.c b/src/backend/replication/logical/origin.c
>> index 5eaf863e02..0aa468789c 100644
>> --- a/src/backend/replication/logical/origin.c
>> +++ b/src/backend/replication/logical/origin.c
>> @@ -473,7 +473,8 @@ ReplicationOriginShmemInit(void)
>>
>> replication_states_ctl->tranche_id = LWTRANCHE_REPLICATION_ORIGIN;
>>
>> - MemSet(replication_states, 0, ReplicationOriginShmemSize());
>> + MemSet(replication_states, 0,
>> + mul_size(max_replication_slots, sizeof(ReplicationState)));
>
> What's the benefit of using mul_size here? That's usually only
> beneficial in the original size computation - during use/initialization
> an actual error should be impossible.
Clarity in initializing only the replication states.
> To me the right fix seems to be to just do:
> - replication_states_ctl->tranche_id = LWTRANCHE_REPLICATION_ORIGIN;
> -
> - MemSet(replication_states, 0, ReplicationOriginShmemSize());
> + MemSet(replication_states_ctl, 0, ReplicationOriginShmemSize());
> +
> + replication_states_ctl->tranche_id = LWTRANCHE_REPLICATION_ORIGIN;
>
> No?
That's what Bret is proposing. I am fine either way.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2017-04-11 23:49 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-04-10 06:26 BUG #14615: ReplicationOriginShmemInit Memory access cross-border bret.shao@outlook.com
2017-04-10 06:38 ` Michael Paquier <michael.paquier@gmail.com>
2017-04-11 15:20 ` Andres Freund <andres@anarazel.de>
2017-04-11 23:49 ` Michael Paquier <michael.paquier@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox