Skip to content

Commit 57756e7

Browse files
Change all shmget calls to user-only memory
Drop the read and write permissions for group and other users in the system. Change-Id: I8fc753f09126651af3fb82df3049050f0b14e876 (cherry-picked from Qt 5 commit 856f209fb63ae336bfb389a12d2a75fa886dc1c5) Reviewed-by: Richard J. Moore <[email protected]> (cherry picked from commit 20b26bd)
1 parent 3b14dc9 commit 57756e7

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

src/corelib/kernel/qsharedmemory_unix.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ bool QSharedMemoryPrivate::create(int size)
199199
}
200200

201201
// create
202-
if (-1 == shmget(unix_key, size, 0666 | IPC_CREAT | IPC_EXCL)) {
202+
if (-1 == shmget(unix_key, size, 0600 | IPC_CREAT | IPC_EXCL)) {
203203
QString function = QLatin1String("QSharedMemory::create");
204204
switch (errno) {
205205
case EINVAL:
@@ -220,7 +220,7 @@ bool QSharedMemoryPrivate::create(int size)
220220
bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode mode)
221221
{
222222
// grab the shared memory segment id
223-
int id = shmget(unix_key, 0, (mode == QSharedMemory::ReadOnly ? 0444 : 0660));
223+
int id = shmget(unix_key, 0, (mode == QSharedMemory::ReadOnly ? 0400 : 0600));
224224
if (-1 == id) {
225225
setErrorString(QLatin1String("QSharedMemory::attach (shmget)"));
226226
return false;
@@ -265,7 +265,7 @@ bool QSharedMemoryPrivate::detach()
265265
size = 0;
266266

267267
// Get the number of current attachments
268-
int id = shmget(unix_key, 0, 0444);
268+
int id = shmget(unix_key, 0, 0400);
269269
cleanHandle();
270270

271271
struct shmid_ds shmid_ds;

src/corelib/kernel/qsystemsemaphore_unix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ key_t QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode mode)
143143
}
144144

145145
// Get semaphore
146-
semaphore = semget(unix_key, 1, 0666 | IPC_CREAT | IPC_EXCL);
146+
semaphore = semget(unix_key, 1, 0600 | IPC_CREAT | IPC_EXCL);
147147
if (-1 == semaphore) {
148148
if (errno == EEXIST)
149-
semaphore = semget(unix_key, 1, 0666 | IPC_CREAT);
149+
semaphore = semget(unix_key, 1, 0600 | IPC_CREAT);
150150
if (-1 == semaphore) {
151151
setErrorString(QLatin1String("QSystemSemaphore::handle"));
152152
cleanHandle();

src/gui/image/qnativeimage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ QNativeImage::QNativeImage(int width, int height, QImage::Format format,bool /*
173173

174174
bool ok;
175175
xshminfo.shmid = shmget(IPC_PRIVATE, xshmimg->bytes_per_line * xshmimg->height,
176-
IPC_CREAT | 0777);
176+
IPC_CREAT | 0700);
177177
ok = xshminfo.shmid != -1;
178178
if (ok) {
179179
xshmimg->data = (char*)shmat(xshminfo.shmid, 0, 0);

src/gui/image/qpixmap_x11.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static bool qt_create_mitshm_buffer(const QPaintDevice* dev, int w, int h)
193193
bool ok;
194194
xshminfo.shmid = shmget(IPC_PRIVATE,
195195
xshmimg->bytes_per_line * xshmimg->height,
196-
IPC_CREAT | 0777);
196+
IPC_CREAT | 0700);
197197
ok = xshminfo.shmid != -1;
198198
if (ok) {
199199
xshmimg->data = (char*)shmat(xshminfo.shmid, 0, 0);

tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ int tst_QSharedMemory::remove(const QString &key)
189189
return -3;
190190
}
191191

192-
int id = shmget(unix_key, 0, 0660);
192+
int id = shmget(unix_key, 0, 0600);
193193
if (-1 == id) {
194194
qDebug() << "shmget failed";
195195
return -4;

tools/qvfb/qvfbshmem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ QShMemViewProtocol::QShMemViewProtocol(int displayid, const QSize &s,
174174
uint data_offset_value = sizeof(QVFbHeader);
175175

176176
int dataSize = bpl * h + data_offset_value;
177-
shmId = shmget(key, dataSize, IPC_CREAT | 0666);
177+
shmId = shmget(key, dataSize, IPC_CREAT | 0600);
178178
if (shmId != -1)
179179
data = (unsigned char *)shmat(shmId, 0, 0);
180180
else {
181181
struct shmid_ds shm;
182182
shmctl(shmId, IPC_RMID, &shm);
183-
shmId = shmget(key, dataSize, IPC_CREAT | 0666);
183+
shmId = shmget(key, dataSize, IPC_CREAT | 0600);
184184
if (shmId == -1) {
185185
perror("QShMemViewProtocol::QShMemViewProtocol");
186186
qFatal("Cannot get shared memory 0x%08x", key);

0 commit comments

Comments
 (0)