From: David Abdurachmanov <david.abdurachmanov@gmail.com>
To: palmer@sifive.com, aou@eecs.berkeley.edu, keescook@chromium.org,
luto@amacapital.net, wad@chromium.org, green.hu@gmail.com,
deanbo422@gmail.com, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org
Cc: David Abdurachmanov <david.abdurachmanov@gmail.com>
Subject: [PATCH 2/2] riscv: fix syscall_{get,set}_arguments
Date: Thu, 6 Dec 2018 16:01:56 +0100 [thread overview]
Message-ID: <20181206150156.28210-3-david.abdurachmanov@gmail.com> (raw)
In-Reply-To: <20181206150156.28210-1-david.abdurachmanov@gmail.com>
Testing with libseccomp master branch revealed that testcases with
filters on syscall arguments were failing due to wrong values. Seccomp
uses syscall_get_argumentsi() to copy syscall arguments, and there is a
bug in pointer arithmetics in memcpy() call.
Two alternative implementation were tested: the one in this patch and
another one based on while-break loop. Both delivered the same results.
This implementation is also used in arm, arm64 and nds32 arches.
Signed-off-by: David Abdurachmanov <david.abdurachmanov@gmail.com>
---
arch/riscv/include/asm/syscall.h | 42 ++++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 10 deletions(-)
diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h
index bba3da6ef157..26ceb434a433 100644
--- a/arch/riscv/include/asm/syscall.h
+++ b/arch/riscv/include/asm/syscall.h
@@ -70,19 +70,32 @@ static inline void syscall_set_return_value(struct task_struct *task,
regs->a0 = (long) error ?: val;
}
+#define SYSCALL_MAX_ARGS 6
+
static inline void syscall_get_arguments(struct task_struct *task,
struct pt_regs *regs,
unsigned int i, unsigned int n,
unsigned long *args)
{
- BUG_ON(i + n > 6);
+ if (n == 0)
+ return;
+
+ if (i + n > SYSCALL_MAX_ARGS) {
+ unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
+ unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
+ pr_warning("%s called with max args %d, handling only %d\n",
+ __func__, i + n, SYSCALL_MAX_ARGS);
+ memset(args_bad, 0, n_bad * sizeof(args[0]));
+ }
+
if (i == 0) {
args[0] = regs->orig_a0;
args++;
i++;
n--;
}
- memcpy(args, ®s->a1 + i * sizeof(regs->a1), n * sizeof(args[0]));
+
+ memcpy(args, ®s->a0 + i, n * sizeof(args[0]));
}
static inline void syscall_set_arguments(struct task_struct *task,
@@ -90,14 +103,23 @@ static inline void syscall_set_arguments(struct task_struct *task,
unsigned int i, unsigned int n,
const unsigned long *args)
{
- BUG_ON(i + n > 6);
- if (i == 0) {
- regs->orig_a0 = args[0];
- args++;
- i++;
- n--;
- }
- memcpy(®s->a1 + i * sizeof(regs->a1), args, n * sizeof(regs->a0));
+ if (n == 0)
+ return;
+
+ if (i + n > SYSCALL_MAX_ARGS) {
+ pr_warning("%s called with max args %d, handling only %d\n",
+ __func__, i + n, SYSCALL_MAX_ARGS);
+ n = SYSCALL_MAX_ARGS - i;
+ }
+
+ if (i == 0) {
+ regs->orig_a0 = args[0];
+ args++;
+ i++;
+ n--;
+ }
+
+ memcpy(®s->a0 + i, args, n * sizeof(args[0]));
}
static inline int syscall_get_arch(void)
--
2.19.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2018-12-06 15:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-06 15:01 [PATCH 0/2] riscv: add support for SECCOMP and SECCOMP_FILTER David Abdurachmanov
2018-12-06 15:01 ` [PATCH 1/2] riscv: add support for SECCOMP incl. filters David Abdurachmanov
2018-12-06 16:47 ` Kees Cook
2018-12-06 17:10 ` David Abdurachmanov
2018-12-06 16:51 ` Kees Cook
2018-12-06 17:11 ` David Abdurachmanov
2018-12-06 18:25 ` David Abdurachmanov
2018-12-06 18:32 ` Kees Cook
2018-12-06 17:06 ` Kees Cook
2018-12-06 17:12 ` David Abdurachmanov
2018-12-06 15:01 ` David Abdurachmanov [this message]
2018-12-06 16:48 ` [PATCH 2/2] riscv: fix syscall_{get,set}_arguments Kees Cook
2018-12-06 17:13 ` David Abdurachmanov
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=20181206150156.28210-3-david.abdurachmanov@gmail.com \
--to=david.abdurachmanov@gmail.com \
--cc=aou@eecs.berkeley.edu \
--cc=deanbo422@gmail.com \
--cc=green.hu@gmail.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=luto@amacapital.net \
--cc=palmer@sifive.com \
--cc=wad@chromium.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 NNTP newsgroup(s).