qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Song Gao <gaosong@loongson.cn>, qemu-devel@nongnu.org
Cc: laurent@vivier.eu, Xiaojuan Yang <yangxiaojuan@loongson.cn>
Subject: Re: [PATCH v18 02/13] linux-user: Add LoongArch signal support
Date: Mon, 20 Jun 2022 09:23:32 -0700	[thread overview]
Message-ID: <60e4b2f3-8e62-bd81-7ef3-298863afe16c@linaro.org> (raw)
In-Reply-To: <20220620093401.3727352-3-gaosong@loongson.cn>

On 6/20/22 02:33, Song Gao wrote:
> +static int restore_sigcontext(CPULoongArchState *env,
> +                               struct target_sigcontext *sc)
> +{
> +    int i;
> +    int ret = 0;
> +    struct extctx_layout extctx;
> +
> +    memset(&extctx, 0, sizeof(struct extctx_layout));
> +
> +    __get_user(extctx.flags, &sc->sc_flags);
> +
> +    ret = parse_extcontext(sc, &extctx);
> +    if (ret < 0) {
> +        goto bad;
> +    }
> +
> +    __get_user(env->pc, &sc->sc_pc);
> +    for (i = 1; i < 32; ++i) {
> +        __get_user(env->gpr[i], &sc->sc_regs[i]);
> +    }
> +
> +    if (extctx.fpu.addr) {
> +        copy_fpu_from_sigcontext(env, &extctx);
> +        restore_fp_status(env);
> +    }
> +bad:
> +    return ret;
> +}

This is missing lock_user/unlock_user somewhere.
You can't use the double-underscore __get/__put_user without having done that.

You can use the non-underscore get_user in parse_extcontext, and separately lock the 
target_fpu_context.  Failures must goto invalid.


> +void setup_rt_frame(int sig, struct target_sigaction *ka,
> +                    target_siginfo_t *info,
> +                    target_sigset_t *set, CPULoongArchState *env)
> +{
> +    struct target_rt_sigframe *frame;
> +    struct extctx_layout extctx;
> +    abi_ulong frame_addr;
> +    int i;
> +
> +    frame_addr = get_sigframe(ka, env, sizeof(*frame), &extctx);
> +    trace_user_setup_rt_frame(env, frame_addr);
> +    if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
> +        goto give_sigsegv;
> +    }

Similarly, this lock...

> +
> +    tswap_siginfo(&frame->rs_info, info);
> +
> +    __put_user(0, &frame->rs_uc.tuc_flags);
> +    __put_user(0, &frame->rs_uc.tuc_link);
> +    target_save_altstack(&frame->rs_uc.tuc_stack, env);
> +
> +    setup_sigcontext(env, &frame->rs_uc.tuc_mcontext, &extctx);

... fails to cover the extra memory allocated for extctx.

This is why I suggested statically allocating the extra
pieces of the signal frame *on write*.  You obviously
cannot rely on the signal frame being identical on
signal return -- the guest is allowed to create any valid
context to give to rt_sigreturn.


r~


  reply	other threads:[~2022-06-20 16:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20  9:33 [PATCH v18 00/13] Add LoongArch linux-user emulation support Song Gao
2022-06-20  9:33 ` [PATCH v18 01/13] linux-user: Add LoongArch generic header files Song Gao
2022-06-20  9:33 ` [PATCH v18 02/13] linux-user: Add LoongArch signal support Song Gao
2022-06-20 16:23   ` Richard Henderson [this message]
2022-06-21  3:56     ` gaosong
2022-06-21 14:12       ` Richard Henderson
2022-06-20  9:33 ` [PATCH v18 03/13] linux-user: Add LoongArch elf support Song Gao
2022-06-20  9:33 ` [PATCH v18 04/13] linux-user: Add LoongArch syscall support Song Gao
2022-06-20  9:33 ` [PATCH v18 05/13] linux-user: Add LoongArch cpu_loop support Song Gao
2022-06-20  9:33 ` [PATCH v18 06/13] scripts: add loongarch64 binfmt config Song Gao
2022-06-20  9:33 ` [PATCH v18 07/13] target/loongarch: remove badaddr from CPULoongArch Song Gao
2022-06-20  9:33 ` [PATCH v18 08/13] target/loongarch: Fix missing update CSR_BADV Song Gao
2022-06-20  9:33 ` [PATCH v18 09/13] target/loongarch: Fix helper_asrtle_d/asrtgt_d raise wrong exception Song Gao
2022-06-20  9:33 ` [PATCH v18 10/13] target/loongarch: remove unused include hw/loader.h Song Gao
2022-06-20  9:33 ` [PATCH v18 11/13] target/loongarch: Adjust functions and structure to support user-mode Song Gao
2022-06-20  9:34 ` [PATCH v18 12/13] default-configs: Add loongarch linux-user support Song Gao
2022-06-20  9:34 ` [PATCH v18 13/13] target/loongarch: Update README Song Gao

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=60e4b2f3-8e62-bd81-7ef3-298863afe16c@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=gaosong@loongson.cn \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=yangxiaojuan@loongson.cn \
    /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).