From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16EC53D72 for ; Mon, 5 Feb 2024 02:32:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707100367; cv=none; b=L1t77/q/JxpQQAQHwDJXi0kJ3cTr21beodgWe0VlSAmQzHcnwXPPK+SpQpN1iM9gGzFHTJW/C46uYPCpXjw6whAD4Gm8CuXyOb/QLtmtRupme8TBE8lWv5e/4i12n/dwmkUR1milnvklCejHJ1lIhgZR/JdJhpjxEAs0RYKU/Lc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707100367; c=relaxed/simple; bh=O+/M8ttsm0JV57S+cboH+tGjzBaaXXwuRo99Mq9yc78=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=p4fp2ykMf4JLW1BUX7OXyeZ8Iivh1KHdX4xvgEa1hlcFJQMWb9pQF052ysJVwZrI6SdAUEIppEKwA/In4339VmF5+22wn7QEHQhLAQjZhP9zzV3URepLVgAJ3PuhGUls6oxISJ+RRgeNln57yK2uU04VdXfVdIHgzKR7EBLU8OU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mi/yY8fC; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mi/yY8fC" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-296a5863237so108385a91.0 for ; Sun, 04 Feb 2024 18:32:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707100365; x=1707705165; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=OSUt8NyFxS5NXl0C4AJwGIwIujyQEDwsTDqbpAC3+30=; b=mi/yY8fCmutvGa0Ck9VEdvqh0e6dhDm+OjWPAfuS+GIKcDCIQ558n0IFGSf9fs1oay qZ4KWd8yR4lSibOHxS1daX0KCLNleutMnryZyfHjAqp97In/GZjZcsJQ0RLG9obB7c1k 9xajK1PuGbXAmUlibcAVcNKktTSfvwVDkVY6Ql6lJsAuTxz1+SBfXpJKsUsQM8GMShx/ 6BfbD6tftSpA7XNEFa3b7/JcTLrMEIBgf2ZVNORRWa9/mSLJOvtXwlXjbVZsWtAOYb0h eDX/TPVR4KNXhNwbg5J9Wn1W9N8BabruzxGJF2/MZxfTk+lGUvzPoQ2ALsYCxobDrV8+ ScLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707100365; x=1707705165; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OSUt8NyFxS5NXl0C4AJwGIwIujyQEDwsTDqbpAC3+30=; b=Jjojcf/w7yDiTgY7wZHPh/3y1Rrpa/gy6vA6oT/d3ErTYMkswSjlevCeb7ovg36A73 fWCnNdtk0Si8qmcoBXTFCqwKRgfabF/iUn6OCTuYaPSYCVQWrEYgzw7Q9RPEHNJjvqap ZPuQ+53qmz7BGS/qVh01s9FQFHo/YaG7K/rbtDzucvz1StrAyp8MOmFaTm/oh/MO57/O yHiGafT5e8L6451EpM5wT/9QX+Ri769nR5T+YQl7VkWTDEPnTGMftbobSNHVUmAphfTj JDwMhTAa/EjMRTdsfnKexzlN67/bVB4z1KfKsGOAueR3U1cs+Fwwufs9I/3n/KhwjSrx ub3w== X-Gm-Message-State: AOJu0YyVTYnOf5PvsLRZRZkgRBLV5RbySdqVw70W4ku0aDHyyVLr/Y8J Tvc2dOHwr6n2w+/ybzKnBJ7oqhfezUNF9iIw7KuXww6l0v2dNZ/P X-Google-Smtp-Source: AGHT+IGDT89uyIm8FiAvzGGFEg3DUiygGXNgoyKIAgVrlxRHr1Wvv5rZ3ypGVHatgzJEBp0OaS2OCQ== X-Received: by 2002:a17:90b:1b45:b0:296:a68b:d2e1 with SMTP id nv5-20020a17090b1b4500b00296a68bd2e1mr583653pjb.15.1707100365283; Sun, 04 Feb 2024 18:32:45 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWFtHZVvFRkJFLBixhWUi+WNiFepD8MjkFQZ9Pr8sULxGZXL7g8DEsyYaau04DlL7MGtFSgUzy71aUpm+4nqMAssnzTXIOj9KWbIk3fxktjPYpDyNjx6NMblFcqLWqnro6HyaT/Ku6D3RKhaZpObggJGHactl0QMCfjukVQnKtuEepy Received: from xplor.waratah.dyndns.org (125-236-136-221-fibre.sparkbb.co.nz. [125.236.136.221]) by smtp.gmail.com with ESMTPSA id sb6-20020a17090b50c600b0028ffea988a2sm3934802pjb.37.2024.02.04.18.32.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 18:32:44 -0800 (PST) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id 67BA6360361; Mon, 5 Feb 2024 15:32:40 +1300 (NZDT) From: Michael Schmitz To: linux-m68k@vger.kernel.org Cc: geert@linux-m68k.org, uli@fpond.eu, fthain@linux-m68k.org, viro@zeniv.linux.org.uk, Michael Schmitz Subject: [PATCH RFC v2 4/8] m68k: Handle arrivals of multiple signals correctly Date: Mon, 5 Feb 2024 15:32:32 +1300 Message-Id: <20240205023236.9325-5-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240205023236.9325-1-schmitzmic@gmail.com> References: <20240205023236.9325-1-schmitzmic@gmail.com> Precedence: bulk X-Mailing-List: linux-m68k@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Al Viro When we have several pending signals, have entered with the kernel with large exception frame *and* have already built at least one sigframe, regs->stkadj is going to be non-zero and regs->format/sr/pc are going to be junk - the real values are in shifted exception stack frame we'd built when putting together the first sigframe. If that happens, subsequent sigframes are going to be garbage. Not hard to fix - just need to find the "adjusted" frame first and look for format/vector/sr/pc in it. MSch: Minor v4.4 backport merge conflict fixes. Signed-off-by: Al Viro Tested-by: Michael Schmitz Reviewed-by: Michael Schmitz Tested-by: Finn Thain Link: https://lore.kernel.org/r/YP2dBIAPTaVvHiZ6@zeniv-ca.linux.org.uk Signed-off-by: Geert Uytterhoeven Signed-off-by: Michael Schmitz --- arch/m68k/kernel/signal.c | 100 +++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c index af1c4f330aef..644c2ddc8aac 100644 --- a/arch/m68k/kernel/signal.c +++ b/arch/m68k/kernel/signal.c @@ -465,7 +465,7 @@ static inline void save_fpu_state(struct sigcontext *sc, struct pt_regs *regs) if (CPU_IS_060 ? sc->sc_fpstate[2] : sc->sc_fpstate[0]) { fpu_version = sc->sc_fpstate[0]; - if (CPU_IS_020_OR_030 && + if (CPU_IS_020_OR_030 && !regs->stkadj && regs->vector >= (VEC_FPBRUC * 4) && regs->vector <= (VEC_FPNAN * 4)) { /* Clear pending exception in 68882 idle frame */ @@ -528,7 +528,7 @@ static inline int rt_save_fpu_state(struct ucontext __user *uc, struct pt_regs * if (!(CPU_IS_060 || CPU_IS_COLDFIRE)) context_size = fpstate[1]; fpu_version = fpstate[0]; - if (CPU_IS_020_OR_030 && + if (CPU_IS_020_OR_030 && !regs->stkadj && regs->vector >= (VEC_FPBRUC * 4) && regs->vector <= (VEC_FPNAN * 4)) { /* Clear pending exception in 68882 idle frame */ @@ -788,18 +788,24 @@ badframe: return 0; } +static inline struct pt_regs *rte_regs(struct pt_regs *regs) +{ + return (void *)regs + regs->stkadj; +} + static void setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs, unsigned long mask) { + struct pt_regs *tregs = rte_regs(regs); sc->sc_mask = mask; sc->sc_usp = rdusp(); sc->sc_d0 = regs->d0; sc->sc_d1 = regs->d1; sc->sc_a0 = regs->a0; sc->sc_a1 = regs->a1; - sc->sc_sr = regs->sr; - sc->sc_pc = regs->pc; - sc->sc_formatvec = regs->format << 12 | regs->vector; + sc->sc_sr = tregs->sr; + sc->sc_pc = tregs->pc; + sc->sc_formatvec = tregs->format << 12 | tregs->vector; save_a5_state(sc, regs); save_fpu_state(sc, regs); } @@ -807,6 +813,7 @@ static void setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs, static inline int rt_setup_ucontext(struct ucontext __user *uc, struct pt_regs *regs) { struct switch_stack *sw = (struct switch_stack *)regs - 1; + struct pt_regs *tregs = rte_regs(regs); greg_t __user *gregs = uc->uc_mcontext.gregs; int err = 0; @@ -827,9 +834,9 @@ static inline int rt_setup_ucontext(struct ucontext __user *uc, struct pt_regs * err |= __put_user(sw->a5, &gregs[13]); err |= __put_user(sw->a6, &gregs[14]); err |= __put_user(rdusp(), &gregs[15]); - err |= __put_user(regs->pc, &gregs[16]); - err |= __put_user(regs->sr, &gregs[17]); - err |= __put_user((regs->format << 12) | regs->vector, &uc->uc_formatvec); + err |= __put_user(tregs->pc, &gregs[16]); + err |= __put_user(tregs->sr, &gregs[17]); + err |= __put_user((tregs->format << 12) | tregs->vector, &uc->uc_formatvec); err |= rt_save_fpu_state(uc, regs); return err; } @@ -846,15 +853,14 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) { struct sigframe __user *frame; - int fsize = frame_extra_sizes(regs->format); + struct pt_regs *tregs = rte_regs(regs); + int fsize = frame_extra_sizes(tregs->format); struct sigcontext context; int err = 0, sig = ksig->sig; if (fsize < 0) { -#ifdef DEBUG - printk ("setup_frame: Unknown frame format %#x\n", - regs->format); -#endif + pr_debug("setup_frame: Unknown frame format %#x\n", + tregs->format); return -EFAULT; } @@ -865,7 +871,7 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set, err |= __put_user(sig, &frame->sig); - err |= __put_user(regs->vector, &frame->code); + err |= __put_user(tregs->vector, &frame->code); err |= __put_user(&frame->sc, &frame->psc); if (_NSIG_WORDS > 1) @@ -890,36 +896,28 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set, push_cache ((unsigned long) &frame->retcode); - /* - * Set up registers for signal handler. All the state we are about - * to destroy is successfully copied to sigframe. - */ - wrusp ((unsigned long) frame); - regs->pc = (unsigned long) ksig->ka.sa.sa_handler; - adjustformat(regs); - /* * This is subtle; if we build more than one sigframe, all but the * first one will see frame format 0 and have fsize == 0, so we won't * screw stkadj. */ - if (fsize) + if (fsize) { regs->stkadj = fsize; - - /* Prepare to skip over the extra stuff in the exception frame. */ - if (regs->stkadj) { - struct pt_regs *tregs = - (struct pt_regs *)((ulong)regs + regs->stkadj); -#ifdef DEBUG - printk("Performing stackadjust=%04x\n", regs->stkadj); -#endif - /* This must be copied with decreasing addresses to - handle overlaps. */ + tregs = rte_regs(regs); + pr_debug("Performing stackadjust=%04lx\n", regs->stkadj); tregs->vector = 0; tregs->format = 0; - tregs->pc = regs->pc; tregs->sr = regs->sr; } + + /* + * Set up registers for signal handler. All the state we are about + * to destroy is successfully copied to sigframe. + */ + wrusp ((unsigned long) frame); + tregs->pc = (unsigned long) ksig->ka.sa.sa_handler; + adjustformat(regs); + return 0; } @@ -927,7 +925,8 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) { struct rt_sigframe __user *frame; - int fsize = frame_extra_sizes(regs->format); + struct pt_regs *tregs = rte_regs(regs); + int fsize = frame_extra_sizes(tregs->format); int err = 0, sig = ksig->sig; if (fsize < 0) { @@ -978,36 +977,27 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, push_cache ((unsigned long) &frame->retcode); - /* - * Set up registers for signal handler. All the state we are about - * to destroy is successfully copied to sigframe. - */ - wrusp ((unsigned long) frame); - regs->pc = (unsigned long) ksig->ka.sa.sa_handler; - adjustformat(regs); - /* * This is subtle; if we build more than one sigframe, all but the * first one will see frame format 0 and have fsize == 0, so we won't * screw stkadj. */ - if (fsize) + if (fsize) { regs->stkadj = fsize; - - /* Prepare to skip over the extra stuff in the exception frame. */ - if (regs->stkadj) { - struct pt_regs *tregs = - (struct pt_regs *)((ulong)regs + regs->stkadj); -#ifdef DEBUG - printk("Performing stackadjust=%04x\n", regs->stkadj); -#endif - /* This must be copied with decreasing addresses to - handle overlaps. */ + tregs = rte_regs(regs); + pr_debug("Performing stackadjust=%04lx\n", regs->stkadj); tregs->vector = 0; tregs->format = 0; - tregs->pc = regs->pc; tregs->sr = regs->sr; } + + /* + * Set up registers for signal handler. All the state we are about + * to destroy is successfully copied to sigframe. + */ + wrusp ((unsigned long) frame); + tregs->pc = (unsigned long) ksig->ka.sa.sa_handler; + adjustformat(regs); return 0; } -- 2.17.1