From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Cc: "Dmitry V . Levin" <ldv@altlinux.org>,
Robert O'Callahan <robert@ocallahan.org>
Subject: [PATCH 6/6] sysvipc: Return EINVAL for invalid shmctl commands
Date: Mon, 28 Sep 2020 11:45:56 -0300 [thread overview]
Message-ID: <20200928144556.239160-6-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20200928144556.239160-1-adhemerval.zanella@linaro.org>
It avoids regressions on possible future commands that might require
additional libc support. The downside is new commands added by newer
kernels will need further glibc support.
Checked on x86_64-linux-gnu and i686-linux-gnu (Linux v4.15 and v5.4).
---
sysdeps/unix/sysv/linux/shmctl.c | 41 ++++++++++++++++++++++++--------
sysvipc/test-sysvshm.c | 5 ++++
2 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/shmctl.c b/sysdeps/unix/sysv/linux/shmctl.c
index 1d19a798b1..98eae91482 100644
--- a/sysdeps/unix/sysv/linux/shmctl.c
+++ b/sysdeps/unix/sysv/linux/shmctl.c
@@ -88,25 +88,46 @@ __shmctl64 (int shmid, int cmd, struct __shmid64_ds *buf)
{
#if __IPC_TIME64
struct kernel_shmid64_ds kshmid, *arg = NULL;
- if (buf != NULL)
+#else
+ shmctl_arg_t *arg;
+#endif
+
+ switch (cmd)
{
- /* This is a Linux extension where kernel expects either a
- 'struct shminfo' (IPC_INFO) or 'struct shm_info' (SHM_INFO). */
- if (cmd == IPC_INFO || cmd == SHM_INFO)
- arg = (struct kernel_shmid64_ds *) buf;
- else
+ case IPC_RMID:
+ arg = NULL;
+ break;
+
+ case IPC_SET:
+ case IPC_STAT:
+ case SHM_STAT:
+#if __IPC_TIME64
+ if (buf != NULL)
{
shmid64_to_kshmid64 (buf, &kshmid);
arg = &kshmid;
}
- }
# ifdef __ASSUME_SYSVIPC_BROKEN_MODE_T
- if (cmd == IPC_SET)
- arg->shm_perm.mode *= 0x10000U;
+ if (cmd == IPC_SET)
+ arg->msg_perm.mode *= 0x10000U;
# endif
#else
- shmctl_arg_t *arg = buf;
+ arg = buf;
#endif
+ break;
+
+ case IPC_INFO:
+ case SHM_INFO:
+ /* This is a Linux extension where kernel expects either a
+ 'struct shminfo' (IPC_INFO) or 'struct shm_info' (SHM_INFO). */
+ arg = (__typeof__ (arg)) buf;
+ break;
+
+ default:
+ __set_errno (EINVAL);
+ return -1;
+ }
+
int ret = shmctl_syscall (shmid, cmd, arg);
if (ret < 0)
diff --git a/sysvipc/test-sysvshm.c b/sysvipc/test-sysvshm.c
index f083fd280b..a1b8b4823e 100644
--- a/sysvipc/test-sysvshm.c
+++ b/sysvipc/test-sysvshm.c
@@ -25,6 +25,8 @@
#include <sys/ipc.h>
#include <sys/shm.h>
+#include <test-sysvipc.h>
+
#include <support/support.h>
#include <support/check.h>
#include <support/temp_file.h>
@@ -81,6 +83,9 @@ do_test (void)
FAIL_EXIT1 ("shmget failed (errno=%d)", errno);
}
+ TEST_COMPARE (shmctl (shmid, first_shm_invalid_cmd (), NULL), -1);
+ TEST_COMPARE (errno, EINVAL);
+
/* Get shared memory kernel information and do some sanity checks. */
struct shmid_ds shminfo;
if (shmctl (shmid, IPC_STAT, &shminfo) == -1)
--
2.25.1
next prev parent reply other threads:[~2020-09-28 14:46 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-28 14:45 [PATCH 1/6] sysvipc: Fix SEM_STAT_ANY kernel argument pass [BZ #26637] Adhemerval Zanella
2020-09-28 14:45 ` [PATCH 2/6] sysvipc: Return EINVAL for invalid semctl commands Adhemerval Zanella
2020-09-28 16:33 ` Florian Weimer
2020-09-28 21:07 ` Adhemerval Zanella
2020-09-28 14:45 ` [PATCH 3/6] sysvipc: Fix IPC_INFO and MSG_INFO handling [BZ #26639] Adhemerval Zanella
2020-09-28 14:55 ` Andreas Schwab
2020-09-29 7:57 ` Florian Weimer
2020-09-29 12:37 ` Adhemerval Zanella
2020-09-29 12:58 ` Adhemerval Zanella
2020-09-29 13:01 ` Florian Weimer
2020-09-29 13:04 ` Adhemerval Zanella
2020-09-28 14:45 ` [PATCH 4/6] sysvipc: Return EINVAL for invalid msgctl commands Adhemerval Zanella
2020-09-29 7:58 ` Florian Weimer
2020-09-29 13:26 ` Adhemerval Zanella
2020-09-29 17:05 ` Florian Weimer
2020-09-28 14:45 ` [PATCH 5/6] sysvipc: Fix IPC_INFO and SHM_INFO handling [BZ #26636] Adhemerval Zanella
2020-09-28 14:45 ` Adhemerval Zanella [this message]
2020-09-28 14:59 ` [PATCH 1/6] sysvipc: Fix SEM_STAT_ANY kernel argument pass [BZ #26637] Florian Weimer
2020-09-28 21:06 ` Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200928144556.239160-6-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=ldv@altlinux.org \
--cc=libc-alpha@sourceware.org \
--cc=robert@ocallahan.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).