remove set_fs calls from the coredump code v4
Subsystems (5)
Hi all,
this series gets rid of playing with the address limit in the exec and coredump code. Most of this was fairly trivial, the biggest changes are those to the spufs coredump code.
Changes since v3:
- fix x86 compilation with x32 in the new version of the signal code
- split the exec patches into a new series
Changes since v2:
- don't cleanup the compat siginfo calling conventions, use the patch variant from Eric with slight coding style fixes instead.
Changes since v1:
- properly spell NUL
- properly handle the compat siginfo case in ELF coredumps
PATCH 1/5 powerpc/spufs: simplify spufs core dumping
Replace the coredump ->read method with a ->dump method that must call dump_emit itself. That way we avoid a buffer allocation an messing with set_fs() to call into code that is intended to deal with user buffers. For the ->get case we can now use a small on-stack buffer and avoid memory allocations as well.
--- arch/powerpc/platforms/cell/spufs/coredump.c | 87 ++---- arch/powerpc/platforms/cell/spufs/file.c | 273 ++++++++++--------- arch/powerpc/platforms/cell/spufs/spufs.h | 3 +- 3 files changed, 170 insertions(+), 193 deletions(-)
arch/powerpc/platforms/cell/spufs/coredump.c +28 -59
@@ -21,22 +21,6 @@#include "spufs.h" -static ssize_t do_coredump_read (int num,struct spu_context *ctx,void *buffer, -size_t size,loff_t *off) -{ -u64 data; -int ret; - -if (spufs_coredump_read[num].read) -return spufs_coredump_read[num].read (ctx, buffer, size, off); - - data = spufs_coredump_read[num].get (ctx); - ret =snprintf (buffer, size,"0x%.16llx" , data); -if (ret >= size) -return size; -return ++ret;/* count trailing NULL */ -} -static int spufs_ctx_note_size (struct spu_context *ctx,int dfd) {int i, sz, total =0 ;
@@ -118,58 +102,43 @@ int spufs_coredump_extra_notes_size(void)static int spufs_arch_write_note (struct spu_context *ctx,int i,struct coredump_params *cprm,int dfd) { -loff_t pos =0 ; -int sz, rc, total =0 ; -const int bufsz =PAGE_SIZE ; -char *name; -char fullname[80 ], *buf; +size_t sz = spufs_coredump_read[i].size; +char fullname[80 ];struct elf_note en; -size_t skip; - - buf = (void *)get_zeroed_page (GFP_KERNEL ); -if (!buf) -return -ENOMEM ; +size_t ret; - name = spufs_coredump_read[i].name; - sz = spufs_coredump_read[i].size; - -sprintf (fullname,"SPU/%d/%s" , dfd, name); +sprintf (fullname,"SPU/%d/%s" , dfd, spufs_coredump_read[i].name); en.n_namesz =strlen (fullname) +1 ; en.n_descsz = sz; en.n_type =NT_SPU ;if (!dump_emit (cprm, &en,sizeof (en))) - goto Eio; - +return -EIO ;if (!dump_emit (cprm, fullname, en.n_namesz)) - goto Eio; - +return -EIO ;if (!dump_align (cprm,4 )) - goto Eio; - -do { - rc =do_coredump_read (i, ctx, buf, bufsz, &pos); -if (rc >0 ) { -if (!dump_emit (cprm, buf, rc)) - goto Eio; - total += rc; - } - }while (rc == bufsz && total < sz); - -if (rc <0 ) - goto out; - - skip =roundup (cprm->pos - total + sz,4 ) - cprm->pos; -if (!dump_skip (cprm, skip)) - goto Eio; - - rc =0 ; -out: -free_page ((unsigned long )buf); -return rc; -Eio: -free_page ((unsigned long )buf); -return -EIO ; +return -EIO ; + +if (spufs_coredump_read[i].dump) { + ret = spufs_coredump_read[i].dump (ctx, cprm); +if (ret <0 ) +return ret; + }else { +char buf[32 ]; + + ret =snprintf (buf,sizeof (buf),"0x%.16llx" , + spufs_coredump_read[i].get (ctx)); +if (ret >=sizeof (buf)) +return sizeof (buf); + +/* count trailing the NULL: */ +if (!dump_emit (cprm, buf, ret +1 )) +return -EIO ; + } + +if (!dump_skip (cprm,roundup (cprm->pos - ret + sz,4 ) - cprm->pos)) +return -EIO ; +return 0 ; }int spufs_coredump_extra_notes_write (struct coredump_params *cprm)
arch/powerpc/platforms/cell/spufs/file.c +141 -132
472 lines not on this page · raw message
arch/powerpc/platforms/cell/spufs/spufs.h +1 -2
@@ -337,8 +337,7 @@ void spufs_dma_callback(struct spu *spu, int type);extern struct spu_coredump_calls spufs_coredump_calls;struct spufs_coredump_reader {char *name; -ssize_t (*read)(struct spu_context *ctx, -char __user *buffer,size_t size,loff_t *pos); +ssize_t (*dump)(struct spu_context *ctx,struct coredump_params *cprm);u64 (*get)(struct spu_context *ctx);size_t size; };
Signature · 1 line
2.26.1
Al Viro
maintainerRe: [PATCH 1/5] powerpc/spufs: simplify spufs core dumping
arch/powerpc/platforms/cell/spufs/file.c static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf, · line 1994
Quoted 13 lines · Christoph Hellwig
arch/powerpc/platforms/cell/spufs/file.c +6
-1@@ -1988,7 +1984,12 @@ static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,if (ret)return ret;spin_lock (&ctx->csa.register_lock); - ret =__spufs_mbox_info_read (ctx, buf, len, pos); +/* EOF if there's no entry in the mbox */ +if (ctx->csa.prob.mb_stat_R &0x0000ff ) { + ret =simple_read_from_buffer (buf, len, pos, + &ctx->csa.prob.pu_mb_R, +sizeof (ctx->csa.prob.pu_mb_R)); + }spin_unlock (&ctx->csa.register_lock);spu_release_saved (ctx);
Again, this really needs fixing. Preferably - as a separate commit preceding this series, so that it could be backported. simple_read_from_buffer() is a blocking operation. Yes, I understand that mainline has the same bug; it really does need to be fixed and having to backport this series is not a good idea, for obvious reasons.
Re: [PATCH 1/5] powerpc/spufs: simplify spufs core dumping
Hi Al & Christoph,
Quoted 3 lines
Again, this really needs fixing. Preferably - as a separate commit preceding this series, so that it could be
backported.simple_read_from_buffer()is a blocking operation.
I'll put together a patch that fixes this.
Christoph: I'll do it in a way that matches your changes to the _read functions, so hopefully those hunks would just drop from your change, leaving only the _dump additions. Would that work?
Cheers,
Jeremy
Re: [PATCH 1/5] powerpc/spufs: simplify spufs core dumping
Quoted 11 lines · Jeremy Kerr
Hi Al & Christoph,
Quoted 3 lines
Again, this really needs fixing. Preferably - as a separate commit preceding this series, so that it could be
backported.simple_read_from_buffer()is a blocking operation.I'll put together a patch that fixes this.
Christoph: I'll do it in a way that matches your changes to the
_readfunctions, so hopefully those hunks would just drop from your change, leaving only the_dumpadditions. Would that work?
Sure.
RFC PATCH 1/1 powerpc/spufs: fix copy_to_user while atomic
In reply to Christoph HellwigCurrently, we may perform a copy_to_user (through simple_read_from_buffer()) while holding a context's register_lock, while accessing the context save area.
This change uses a temporary buffers for the context save area data, which we then pass to simple_read_from_buffer.
---
Christoph - this fixes the copy_to_user while atomic, hopefully with only minimal distruption to your series.
--- arch/powerpc/platforms/cell/spufs/file.c | 110 +++++++++++++++-------- 1 file changed, 74 insertions(+), 36 deletions(-)
arch/powerpc/platforms/cell/spufs/file.c +74 -36
@@ -1978,8 +1978,9 @@ static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,static ssize_t spufs_mbox_info_read (struct file *file,char __user *buf,size_t len,loff_t *pos) { -int ret;struct spu_context *ctx = file->private_data; +u32 stat, data; +int ret;if (!access_ok (buf, len))return -EFAULT ;
@@ -1988,11 +1989,16 @@ static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,if (ret)return ret;spin_lock (&ctx->csa.register_lock); - ret =__spufs_mbox_info_read (ctx, buf, len, pos); + stat = ctx->csa.prob.mb_stat_R; + data = ctx->csa.prob.pu_mb_R;spin_unlock (&ctx->csa.register_lock);spu_release_saved (ctx); -return ret; +/* EOF if there's no entry in the mbox */ +if (!(stat &0x0000ff )) +return 0 ; + +return simple_read_from_buffer (buf, len, pos, &data,sizeof (data)); }static const struct file_operations spufs_mbox_info_fops = {
@@ -2019,6 +2025,7 @@ static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf, size_t len, loff_t *pos) { struct spu_context *ctx = file->private_data; +u32 stat, data;int ret;if (!access_ok (buf, len))
@@ -2028,11 +2035,16 @@ static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,if (ret)return ret;spin_lock (&ctx->csa.register_lock); - ret =__spufs_ibox_info_read (ctx, buf, len, pos); + stat = ctx->csa.prob.mb_stat_R; + data = ctx->csa.priv2.puint_mb_R;spin_unlock (&ctx->csa.register_lock);spu_release_saved (ctx); -return ret; +/* EOF if there's no entry in the ibox */ +if (!(stat &0xff0000 )) +return 0 ; + +return simple_read_from_buffer (buf, len, pos, &data,sizeof (data)); }static const struct file_operations spufs_ibox_info_fops = {
@@ -2041,6 +2053,11 @@ static const struct file_operations spufs_ibox_info_fops = { .llseek = generic_file_llseek, }; +static size_t spufs_wbox_info_cnt (struct spu_context *ctx) +{ +return (4 - ((ctx->csa.prob.mb_stat_R &0x00ff00 ) >>8 )) *sizeof (u32); +} +static ssize_t __spufs_wbox_info_read (struct spu_context *ctx,char __user *buf,size_t len,loff_t *pos) {
@@ -2049,7 +2066,7 @@ static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,u32 wbox_stat; wbox_stat = ctx->csa.prob.mb_stat_R; - cnt =4 - ((wbox_stat &0x00ff00 ) >>8 ); + cnt =spufs_wbox_info_cnt (ctx);for (i =0 ; i < cnt; i++) { data[i] = ctx->csa.spu_mailbox_data[i]; }
@@ -2062,7 +2079,8 @@ static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf, size_t len, loff_t *pos) { struct spu_context *ctx = file->private_data; -int ret; +u32 data[ARRAY_SIZE (ctx->csa.spu_mailbox_data)]; +int ret, count;if (!access_ok (buf, len))return -EFAULT ;
@@ -2071,11 +2089,13 @@ static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,if (ret)return ret;spin_lock (&ctx->csa.register_lock); - ret =__spufs_wbox_info_read (ctx, buf, len, pos); + count =spufs_wbox_info_cnt (ctx); +memcpy (&data, &ctx->csa.spu_mailbox_data,sizeof (data));spin_unlock (&ctx->csa.register_lock);spu_release_saved (ctx); -return ret; +return simple_read_from_buffer (buf, len, pos, &data, + count *sizeof (u32)); }static const struct file_operations spufs_wbox_info_fops = {
@@ -2084,20 +2104,19 @@ static const struct file_operations spufs_wbox_info_fops = { .llseek = generic_file_llseek, }; -static ssize_t __spufs_dma_info_read (struct spu_context *ctx, -char __user *buf,size_t len,loff_t *pos) +static void ___spufs_dma_info_read (struct spu_context *ctx, +struct spu_dma_info *info) { -struct spu_dma_info info;struct mfc_cq_sr *qp, *spuqp;int i; - info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW; - info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0 ]; - info.dma_info_status = ctx->csa.spu_chnldata_RW[24 ]; - info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25 ]; - info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27 ]; + info->dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW; + info->dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0 ]; + info->dma_info_status = ctx->csa.spu_chnldata_RW[24 ]; + info->dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25 ]; + info->dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27 ];for (i =0 ; i <16 ; i++) { - qp = &info.dma_info_command_data[i]; + qp = &info->dma_info_command_data[i]; spuqp = &ctx->csa.priv2.spuq[i]; qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
@@ -2105,6 +2124,14 @@ static ssize_t __spufs_dma_info_read(struct spu_context *ctx, qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW; qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW; } +} + +static ssize_t __spufs_dma_info_read (struct spu_context *ctx, +char __user *buf,size_t len,loff_t *pos) +{ +struct spu_dma_info info; + +___spufs_dma_info_read (ctx, &info);return simple_read_from_buffer (buf, len, pos, &info,sizeof info);
@@ -2114,6 +2141,7 @@ static ssize_t spufs_dma_info_read(struct file *file, char __user *buf, size_t len, loff_t *pos) { struct spu_context *ctx = file->private_data; +struct spu_dma_info info;int ret;if (!access_ok (buf, len))
@@ -2123,11 +2151,12 @@ static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,if (ret)return ret;spin_lock (&ctx->csa.register_lock); - ret =__spufs_dma_info_read (ctx, buf, len, pos); +___spufs_dma_info_read (ctx, &info);spin_unlock (&ctx->csa.register_lock);spu_release_saved (ctx); -return ret; +return simple_read_from_buffer (buf, len, pos, &info, +sizeof (info)); }static const struct file_operations spufs_dma_info_fops = {
@@ -2136,13 +2165,31 @@ static const struct file_operations spufs_dma_info_fops = { .llseek = no_llseek, }; +static void ___spufs_proxydma_info_read (struct spu_context *ctx, +struct spu_proxydma_info *info) +{ +int i; + + info->proxydma_info_type = ctx->csa.prob.dma_querytype_RW; + info->proxydma_info_mask = ctx->csa.prob.dma_querymask_RW; + info->proxydma_info_status = ctx->csa.prob.dma_tagstatus_R; + +for (i =0 ; i <8 ; i++) { +struct mfc_cq_sr *qp = &info->proxydma_info_command_data[i]; +struct mfc_cq_sr *puqp = &ctx->csa.priv2.puq[i]; + + qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW; + qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW; + qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW; + qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW; + } +} +static ssize_t __spufs_proxydma_info_read (struct spu_context *ctx,char __user *buf,size_t len,loff_t *pos) {struct spu_proxydma_info info; -struct mfc_cq_sr *qp, *puqp;int ret =sizeof info; -int i;if (len < ret)return -EINVAL ;
@@ -2150,18 +2197,7 @@ static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,if (!access_ok (buf, len))return -EFAULT ; - info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW; - info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW; - info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R; -for (i =0 ; i <8 ; i++) { - qp = &info.proxydma_info_command_data[i]; - puqp = &ctx->csa.priv2.puq[i]; - - qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW; - qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW; - qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW; - qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW; - } +___spufs_proxydma_info_read (ctx, &info);return simple_read_from_buffer (buf, len, pos, &info,sizeof info);
@@ -2171,17 +2207,19 @@ static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf, size_t len, loff_t *pos) { struct spu_context *ctx = file->private_data; +struct spu_proxydma_info info;int ret; ret =spu_acquire_saved (ctx);if (ret)return ret;spin_lock (&ctx->csa.register_lock); - ret =__spufs_proxydma_info_read (ctx, buf, len, pos); +___spufs_proxydma_info_read (ctx, &info);spin_unlock (&ctx->csa.register_lock);spu_release_saved (ctx); -return ret; +return simple_read_from_buffer (buf, len, pos, &info, +sizeof (info)); } static const struct file_operations spufs_proxydma_info_fops = {
Signature · 1 line
2.17.1
Re: [RFC PATCH] powerpc/spufs: fix copy_to_user while atomic
Quoted 4 lines · Jeremy Kerr
Currently, we may perform a
copy_to_user(throughsimple_read_from_buffer()) while holding a context'sregister_lock, while accessing the context save area.
Quoted 8 lines
This change uses a temporary buffers for the context save area data, which we then pass to
simple_read_from_buffer.Signed-off-by Jeremy Kerr <[email protected]>---
Christoph - this fixes the
copy_to_userwhile atomic, hopefully with only minimal distruption to your series.
I recognize plenty of sniplets from that :) Your patch looks good to me:
Re: [RFC PATCH] powerpc/spufs: fix copy_to_user while atomic
In reply to Jeremy KerrQuoted 10 lines · Jeremy Kerr
Currently, we may perform a
copy_to_user(throughsimple_read_from_buffer()) while holding a context'sregister_lock, while accessing the context save area.This change uses a temporary buffers for the context save area data, which we then pass to
simple_read_from_buffer.Signed-off-by Jeremy Kerr <[email protected]>---
Thanks for fixing this!
I wonder how far it should be backported, given that this has been broken for 14 years now.
Re: [RFC PATCH] powerpc/spufs: fix copy_to_user while atomic
In reply to Jeremy KerrFYI, these little hunks reduce the difference to my version, maybe you can fold them in?
arch/powerpc/platforms/cell/spufs/file.c +3 -4
@@ -2107,7 +2107,6 @@ static const struct file_operations spufs_wbox_info_fops = {static void ___spufs_dma_info_read (struct spu_context *ctx,struct spu_dma_info *info) { -struct mfc_cq_sr *qp, *spuqp;int i; info->dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
@@ -2116,8 +2115,8 @@ static void ___spufs_dma_info_read(struct spu_context *ctx, info->dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25 ]; info->dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27 ];for (i =0 ; i <16 ; i++) { - qp = &info->dma_info_command_data[i]; - spuqp = &ctx->csa.priv2.spuq[i]; +struct mfc_cq_sr *qp = &info->dma_info_command_data[i]; +struct mfc_cq_sr *qp, *spuqp = &ctx->csa.priv2.spuq[i]; qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW; qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
@@ -2166,7 +2165,7 @@ static const struct file_operations spufs_dma_info_fops = { };static void ___spufs_proxydma_info_read (struct spu_context *ctx, -struct spu_proxydma_info *info) +struct spu_proxydma_info *info) {int i;
Re: [RFC PATCH] powerpc/spufs: fix copy_to_user while atomic
Hi Christoph,
Quoted 2 lines
FYI, these little hunks reduce the difference to my version, maybe you can fold them in?
Sure, no problem.
How do you want to coordinate these? I can submit mine through mpe, but that may make it tricky to synchronise with your changes. Or, you can include this change in your series if you prefer.
Cheers,
Jeremy
Re: [RFC PATCH] powerpc/spufs: fix copy_to_user while atomic
Quoted 10 lines · Jeremy Kerr
Hi Christoph,
Quoted 2 lines
FYI, these little hunks reduce the difference to my version, maybe you can fold them in?
Sure, no problem.
How do you want to coordinate these? I can submit mine through mpe, but that may make it tricky to synchronise with your changes. Or, you can include this change in your series if you prefer.
Maybe you can feed your patch directly to Linus through Michael ASAP, and I'll wait for that before resubmitting this series?
Re: [RFC PATCH] powerpc/spufs: fix copy_to_user while atomic
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Jeremy Kerr
Hi Christoph,
Quoted 2 lines
FYI, these little hunks reduce the difference to my version, maybe you can fold them in?
Quoted 8 lines
Quoted 5 lines
Sure, no problem.
How do you want to coordinate these? I can submit mine through mpe, but that may make it tricky to synchronise with your changes. Or, you can include this change in your series if you prefer.
Maybe you can feed your patch directly to Linus through Michael ASAP, and I'll wait for that before resubmitting this series?
Btw, turns out my fold patch didn't actually compile without the rebased patch on top, sorry. Here is the proper one:
arch/powerpc/platforms/cell/spufs/file.c +3 -4
@@ -2107,7 +2107,6 @@ static const struct file_operations spufs_wbox_info_fops = {static void ___spufs_dma_info_read (struct spu_context *ctx,struct spu_dma_info *info) { -struct mfc_cq_sr *qp, *spuqp;int i; info->dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
@@ -2116,8 +2115,8 @@ static void ___spufs_dma_info_read(struct spu_context *ctx, info->dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25 ]; info->dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27 ];for (i =0 ; i <16 ; i++) { - qp = &info->dma_info_command_data[i]; - spuqp = &ctx->csa.priv2.spuq[i]; +struct mfc_cq_sr *qp = &info->dma_info_command_data[i]; +struct mfc_cq_sr *spuqp = &ctx->csa.priv2.spuq[i]; qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW; qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
@@ -2166,7 +2165,7 @@ static const struct file_operations spufs_dma_info_fops = { };static void ___spufs_proxydma_info_read (struct spu_context *ctx, -struct spu_proxydma_info *info) +struct spu_proxydma_info *info) {int i;
Re: [RFC PATCH] powerpc/spufs: fix copy_to_user while atomic
In reply to Jeremy KerrAnd another one that should go on top of this one to address Al's other compaint:
---
From 1b7ced3de0b3a4addec61f61ac5278c3ff141657 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <[email protected]>
Date: Wed, 22 Apr 2020 09:05:30 +0200
Subject: powerpc/spufs: stop using access_ok
Just use the proper non __-prefixed get/put_user variants where that is not done yet.
--- arch/powerpc/platforms/cell/spufs/file.c | 42 +++++------------------- 1 file changed, 8 insertions(+), 34 deletions(-)
arch/powerpc/platforms/cell/spufs/file.c +8 -34
@@ -590,17 +590,12 @@ static ssize_t spufs_mbox_read(struct file *file, char __user *buf, size_t len, loff_t *pos) { struct spu_context *ctx = file->private_data; -u32 mbox_data,__user *udata; +u32 mbox_data,__user *udata = (void __user *)buf;ssize_t count;if (len <4 )return -EINVAL ; -if (!access_ok (buf, len)) -return -EFAULT ; - - udata = (void __user *)buf; - count =spu_acquire (ctx);if (count)return count;
@@ -616,7 +611,7 @@ static ssize_t spufs_mbox_read(struct file *file, char __user *buf,* but still need to return the data we have * read successfully so far. */ - ret =__put_user (mbox_data, udata); + ret =put_user (mbox_data, udata);if (ret) {if (!count) count = -EFAULT ;
@@ -698,17 +693,12 @@ static ssize_t spufs_ibox_read(struct file *file, char __user *buf, size_t len, loff_t *pos) { struct spu_context *ctx = file->private_data; -u32 ibox_data,__user *udata; +u32 ibox_data,__user *udata = (void __user *)buf;ssize_t count;if (len <4 )return -EINVAL ; -if (!access_ok (buf, len)) -return -EFAULT ; - - udata = (void __user *)buf; - count =spu_acquire (ctx);if (count) goto out;
@@ -727,7 +717,7 @@ static ssize_t spufs_ibox_read(struct file *file, char __user *buf, }/* if we can't write at all, return -EFAULT */ - count =__put_user (ibox_data, udata); + count =put_user (ibox_data, udata);if (count) goto out_unlock;
@@ -741,7 +731,7 @@ static ssize_t spufs_ibox_read(struct file *file, char __user *buf,* but still need to return the data we have * read successfully so far. */ - ret =__put_user (ibox_data, udata); + ret =put_user (ibox_data, udata);if (ret)break ; }
@@ -836,17 +826,13 @@ static ssize_t spufs_wbox_write(struct file *file, const char __user *buf, size_t len, loff_t *pos) { struct spu_context *ctx = file->private_data; -u32 wbox_data,__user *udata; +u32 wbox_data,__user *udata = (void __user *)buf;ssize_t count;if (len <4 )return -EINVAL ; - udata = (void __user *)buf; -if (!access_ok (buf, len)) -return -EFAULT ; - -if (__get_user (wbox_data, udata)) +if (get_user (wbox_data, udata))return -EFAULT ; count =spu_acquire (ctx);
@@ -873,7 +859,7 @@ static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,/* write as much as possible */ for (count =4 , udata++; (count +4 ) <= len; count +=4 , udata++) {int ret; - ret =__get_user (wbox_data, udata); + ret =get_user (wbox_data, udata);if (ret)break ;
@@ -1982,9 +1968,6 @@ static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,u32 stat, data;int ret; -if (!access_ok (buf, len)) -return -EFAULT ; - ret =spu_acquire_saved (ctx);if (ret)return ret;
@@ -2028,9 +2011,6 @@ static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,u32 stat, data;int ret; -if (!access_ok (buf, len)) -return -EFAULT ; - ret =spu_acquire_saved (ctx);if (ret)return ret;
@@ -2082,9 +2062,6 @@ static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,u32 data[ARRAY_SIZE (ctx->csa.spu_mailbox_data)];int ret, count; -if (!access_ok (buf, len)) -return -EFAULT ; - ret =spu_acquire_saved (ctx);if (ret)return ret;
@@ -2143,9 +2120,6 @@ static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,struct spu_dma_info info;int ret; -if (!access_ok (buf, len)) -return -EFAULT ; - ret =spu_acquire_saved (ctx);if (ret)return ret;
Signature · 1 line
2.26.2
Re: [RFC PATCH] powerpc/spufs: fix copy_to_user while atomic
Hi Christoph,
Quoted 2 lines
And another one that should go on top of this one to address Al's other compaint:
Yeah, I was pondering that one. The access_ok() is kinda redundant, but it does avoid forcing a SPU context save on those errors.
However, it's not like we really need to optimise for the case of invalid addresses from userspace. So, I'll include this change in the submission to Michael's tree. Arnd - let me know if you have any objections.
Cheers,
Jeremy
Re: [RFC PATCH] powerpc/spufs: fix copy_to_user while atomic
Quoted 6 lines · Jeremy Kerr
Hi Christoph,
Quoted 2 lines
And another one that should go on top of this one to address Al's other compaint:
Quoted 7 lines
Yeah, I was pondering that one. The
access_ok()is kinda redundant, but it does avoid forcing a SPU context save on those errors.However, it's not like we really need to optimise for the case of invalid addresses from userspace. So, I'll include this change in the submission to Michael's tree. Arnd - let me know if you have any objections.
Sounds good. A lot of the access_ok() checks in the kernel are redundant or wrong, I think it makes a lot of sense to remove these.
Arnd
PATCH 2/5 signal: factor copy_siginfo_to_external32 from copy_siginfo_to_user32
In reply to Christoph HellwigFrom: "Eric W. Biederman" <[email protected]>
To remove the use of set_fs in the coredump code there needs to be a way to convert a kernel siginfo to a userspace compat siginfo.
Call that function copy_siginfo_to_compat and factor it out of copy_siginfo_to_user32.
The existence of x32 complicates this code. On x32 SIGCHLD uses 64bit times for utime and stime. As only SIGCHLD is affected and SIGCHLD never causes a coredump I have avoided handling that case.
--- include/linux/compat.h | 2 + kernel/signal.c | 113 ++++++++++++++++++++++------------------- 2 files changed, 62 insertions(+), 53 deletions(-)
include/linux/compat.h +2 -0
@@ -402,6 +402,8 @@ long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask, unsigned long bitmap_size);long compat_put_bitmap (compat_ulong_t __user *umask,unsigned long *mask,unsigned long bitmap_size); +void copy_siginfo_to_external32 (struct compat_siginfo *to, +const struct kernel_siginfo *from);int copy_siginfo_from_user32 (kernel_siginfo_t *to,const struct compat_siginfo __user *from);int copy_siginfo_to_user32 (struct compat_siginfo __user *to,const kernel_siginfo_t *from); int get_compat_sigevent(struct sigevent *event,
kernel/signal.c +60 -53
154 lines not on this page · raw message
Signature · 1 line
2.26.1
PATCH 3/5 binfmt_elf: remove the set_fs in fill_siginfo_note
In reply to Christoph HellwigFrom: "Eric W. Biederman" <[email protected]>
The code in binfmt_elf.c is differnt from the rest of the code that processes siginfo, as it sends siginfo from a kernel buffer to a file rather than from kernel memory to userspace buffers. To remove it's use of set_fs the code needs some different siginfo helpers.
Add the helper copy_siginfo_to_external to copy from the kernel's internal siginfo layout to a buffer in the siginfo layout that userspace expects.
Modify fill_siginfo_note to use copy_siginfo_to_external instead of set_fs and copy_siginfo_to_user.
Update compat_binfmt_elf.c to use the previously added copy_siginfo_to_external32 to handle the compat case.
--- fs/binfmt_elf.c | 5 +---- fs/compat_binfmt_elf.c | 2 +- include/linux/signal.h | 8 ++++++++ 3 files changed, 10 insertions(+), 5 deletions(-)
fs/binfmt_elf.c +1 -4
@@ -1556,10 +1556,7 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)static void fill_siginfo_note (struct memelfnote *note,user_siginfo_t *csigdata,const kernel_siginfo_t *siginfo) { -mm_segment_t old_fs =get_fs (); -set_fs (KERNEL_DS ); -copy_siginfo_to_user ((user_siginfo_t __user *) csigdata, siginfo); -set_fs (old_fs); +copy_siginfo_to_external (csigdata, siginfo);fill_note (note,"CORE" ,NT_SIGINFO ,sizeof (*csigdata), csigdata); }
fs/compat_binfmt_elf.c +1 -1
@@ -39,7 +39,7 @@*/ #define user_long_t compat_long_t#define user_siginfo_t compat_siginfo_t -#define copy_siginfo_to_user copy_siginfo_to_user32 +#define copy_siginfo_to_external copy_siginfo_to_external32/* * The machine-dependent core note format types are defined in elfcore-compat.h,
include/linux/signal.h +8 -0
@@ -24,6 +24,14 @@ static inline void clear_siginfo(kernel_siginfo_t *info)#define SI_EXPANSION_SIZE (sizeof(struct siginfo) - sizeof(struct kernel_siginfo)) +static inline void copy_siginfo_to_external (siginfo_t *to, +const kernel_siginfo_t *from) +{ +memcpy (to, from,sizeof (*from)); +memset (((char *)to) +sizeof (struct kernel_siginfo ),0 , +SI_EXPANSION_SIZE ); +} +int copy_siginfo_to_user (siginfo_t __user *to,const kernel_siginfo_t *from);int copy_siginfo_from_user (kernel_siginfo_t *to,const siginfo_t __user *from);
Signature · 1 line
2.26.1
PATCH 4/5 binfmt_elf: remove the set_fs(KERNEL_DS) in elf_core_dump
In reply to Christoph HellwigThere is no logic in elf_core_dump itself or in the various arch helpers called from it which use uaccess routines on kernel pointers except for the file writes thate are nicely encapsulated by using __kernel_write in dump_emit.
--- fs/binfmt_elf.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-)
fs/binfmt_elf.c +13 -27
@@ -1355,7 +1355,6 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma, vma->vm_pgoff == 0 && (vma->vm_flags & VM_READ)) {u32 __user *header = (u32 __user *) vma->vm_start;u32 word; -mm_segment_t fs =get_fs ();/* * Doing it this way gets the constant folded by GCC. */
@@ -1368,14 +1367,8 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma, magic.elfmag[EI_MAG1 ] =ELFMAG1 ; magic.elfmag[EI_MAG2 ] =ELFMAG2 ; magic.elfmag[EI_MAG3 ] =ELFMAG3 ; -/* -* Switch to the user "segment" for get_user(), -* then put back what elf_core_dump() had in place. -*/ -set_fs (USER_DS );if (unlikely (get_user (word, header))) word =0 ; -set_fs (fs);if (word == magic.cmp)return PAGE_SIZE ; }
@@ -2183,7 +2176,6 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,static int elf_core_dump (struct coredump_params *cprm) {int has_dumped =0 ; -mm_segment_t fs;int segs, i;size_t vma_data_size =0 ;struct vm_area_struct *vma, *gate_vma;
@@ -2236,9 +2228,6 @@ static int elf_core_dump(struct coredump_params *cprm) has_dumped =1 ; - fs =get_fs (); -set_fs (KERNEL_DS ); - offset +=sizeof (elf);/* Elf header */ offset += segs *sizeof (struct elf_phdr );/* Program headers */
@@ -2250,7 +2239,7 @@ static int elf_core_dump(struct coredump_params *cprm) phdr4note =kmalloc (sizeof (*phdr4note),GFP_KERNEL );if (!phdr4note) - goto end_coredump; + goto cleanup;fill_elf_note_phdr (phdr4note, sz, offset); offset += sz;
@@ -2265,7 +2254,7 @@ static int elf_core_dump(struct coredump_params *cprm) vma_filesz =kvmalloc (array_size (sizeof (*vma_filesz), (segs -1 )),GFP_KERNEL );if (!vma_filesz) - goto end_coredump; + goto cleanup;for (i =0 , vma =first_vma (current, gate_vma); vma !=NULL ; vma =next_vma (vma, gate_vma)) {
@@ -2283,17 +2272,17 @@ static int elf_core_dump(struct coredump_params *cprm)if (e_phnum ==PN_XNUM ) { shdr4extnum =kmalloc (sizeof (*shdr4extnum),GFP_KERNEL );if (!shdr4extnum) - goto end_coredump; + goto cleanup;fill_extnum_info (&elf, shdr4extnum, e_shoff, segs); } offset = dataoff;if (!dump_emit (cprm, &elf,sizeof (elf))) - goto end_coredump; + goto cleanup;if (!dump_emit (cprm, phdr4note,sizeof (*phdr4note))) - goto end_coredump; + goto cleanup;/* Write program headers for segments dump */ for (i = 0, vma = first_vma(current, gate_vma); vma != NULL;
@@ -2315,22 +2304,22 @@ static int elf_core_dump(struct coredump_params *cprm) phdr.p_align =ELF_EXEC_PAGESIZE ;if (!dump_emit (cprm, &phdr,sizeof (phdr))) - goto end_coredump; + goto cleanup; }if (!elf_core_write_extra_phdrs (cprm, offset)) - goto end_coredump; + goto cleanup;/* write out the notes section */ if (!write_note_info (&info, cprm)) - goto end_coredump; + goto cleanup;if (elf_coredump_extra_notes_write (cprm)) - goto end_coredump; + goto cleanup;/* Align to page */ if (!dump_skip (cprm, dataoff - cprm->pos)) - goto end_coredump; + goto cleanup;for (i =0 , vma =first_vma (current, gate_vma); vma !=NULL ; vma =next_vma (vma, gate_vma)) {
@@ -2352,22 +2341,19 @@ static int elf_core_dump(struct coredump_params *cprm) }else stop = !dump_skip (cprm,PAGE_SIZE );if (stop) - goto end_coredump; + goto cleanup; } }dump_truncate (cprm);if (!elf_core_write_extra_data (cprm)) - goto end_coredump; + goto cleanup;if (e_phnum ==PN_XNUM ) {if (!dump_emit (cprm, shdr4extnum,sizeof (*shdr4extnum))) - goto end_coredump; + goto cleanup; } -end_coredump: -set_fs (fs); - cleanup:free_note_info (&info);kfree (shdr4extnum);
Signature · 1 line
2.26.1
PATCH 5/5 binfmt_elf_fdpic: remove the set_fs(KERNEL_DS) in elf_fdpic_core_dump
In reply to Christoph HellwigThere is no logic in elf_fdpic_core_dump itself or in the various arch helpers called from it which use uaccess routines on kernel pointers except for the file writes thate are nicely encapsulated by using __kernel_write in dump_emit.
--- fs/binfmt_elf_fdpic.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-)
fs/binfmt_elf_fdpic.c +12 -19
@@ -1549,7 +1549,6 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) {#define NUM_NOTES 6int has_dumped =0 ; -mm_segment_t fs;int segs;int i;struct vm_area_struct *vma;
@@ -1678,9 +1677,6 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) "LINUX", ELF_CORE_XFPREG_TYPE, sizeof(*xfpu), xfpu);#endif - fs =get_fs (); -set_fs (KERNEL_DS ); - offset +=sizeof (*elf);/* Elf header */ offset += segs *sizeof (struct elf_phdr );/* Program headers */
@@ -1695,7 +1691,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) phdr4note =kmalloc (sizeof (*phdr4note),GFP_KERNEL );if (!phdr4note) - goto end_coredump; + goto cleanup;fill_elf_note_phdr (phdr4note, sz, offset); offset += sz;
@@ -1711,17 +1707,17 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)if (e_phnum ==PN_XNUM ) { shdr4extnum =kmalloc (sizeof (*shdr4extnum),GFP_KERNEL );if (!shdr4extnum) - goto end_coredump; + goto cleanup;fill_extnum_info (elf, shdr4extnum, e_shoff, segs); } offset = dataoff;if (!dump_emit (cprm, elf,sizeof (*elf))) - goto end_coredump; + goto cleanup;if (!dump_emit (cprm, phdr4note,sizeof (*phdr4note))) - goto end_coredump; + goto cleanup;/* write program headers for segments dump */ for (vma = current->mm->mmap; vma; vma = vma->vm_next) {
@@ -1745,16 +1741,16 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) phdr.p_align =ELF_EXEC_PAGESIZE ;if (!dump_emit (cprm, &phdr,sizeof (phdr))) - goto end_coredump; + goto cleanup; }if (!elf_core_write_extra_phdrs (cprm, offset)) - goto end_coredump; + goto cleanup;/* write out the notes section */ for (i =0 ; i < numnote; i++)if (!writenote (notes + i, cprm)) - goto end_coredump; + goto cleanup;/* write out the thread status notes section */ list_for_each (t, &thread_list) {
@@ -1763,21 +1759,21 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)for (i =0 ; i < tmp->num_notes; i++)if (!writenote (&tmp->notes[i], cprm)) - goto end_coredump; + goto cleanup; }if (!dump_skip (cprm, dataoff - cprm->pos)) - goto end_coredump; + goto cleanup;if (!elf_fdpic_dump_segments (cprm)) - goto end_coredump; + goto cleanup;if (!elf_core_write_extra_data (cprm)) - goto end_coredump; + goto cleanup;if (e_phnum ==PN_XNUM ) {if (!dump_emit (cprm, shdr4extnum,sizeof (*shdr4extnum))) - goto end_coredump; + goto cleanup; }if (cprm->file->f_pos != offset) {
@@ -1787,9 +1783,6 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) cprm->file->f_pos, offset); } -end_coredump: -set_fs (fs); - cleanup:while (!list_empty (&thread_list)) {struct list_head *tmp = thread_list.next;
Signature · 1 line
2.26.1