Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754730AbbHNCD0 (ORCPT ); Thu, 13 Aug 2015 22:03:26 -0400 Received: from smtp44.i.mail.ru ([94.100.177.104]:54741 "EHLO smtp44.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754150AbbHNCDZ (ORCPT ); Thu, 13 Aug 2015 22:03:25 -0400 Subject: Re: [regression] x86/signal/64: Fix SS handling for signals delivered to 64-bit programs breaks dosemu To: Andy Lutomirski References: <55CA90B4.2010205@list.ru> <20150813200823.GS2059@uranus> <55CD0F29.4070604@gmail.com> <55CD13F3.1070904@list.ru> <55CD1968.7070002@list.ru> <55CD1F79.2010508@list.ru> <55CD2F9A.9040300@list.ru> <55CD3382.5070506@list.ru> <55CD3B3F.9040203@list.ru> <55CD4515.2030202@list.ru> Cc: Linus Torvalds , Raymond Jennings , Cyrill Gorcunov , Pavel Emelyanov , Linux kernel From: Stas Sergeev Message-ID: <55CD4C61.6020608@list.ru> Date: Fri, 14 Aug 2015 05:03:13 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Mras: Ok Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3795 Lines: 79 14.08.2015 04:37, Andy Lutomirski пишет: > On Thu, Aug 13, 2015 at 6:32 PM, Stas Sergeev wrote: >> 14.08.2015 04:21, Andy Lutomirski пишет: >> >>> On Thu, Aug 13, 2015 at 5:50 PM, Stas Sergeev wrote: >>>> 14.08.2015 03:27, Linus Torvalds пишет: >>>>> On Thu, Aug 13, 2015 at 5:17 PM, Stas Sergeev wrote: >>>>>> For example because you can as well do: >>>>>> prctl(ARCH_SET_SIGNAL_SS, 0) >>>>>> which will mean "restore ss in sighandler to its current value", >>>>> I really think a prctl() is the wrong thing to do. >>>>> >>>>> If you want a signal handler to save/restore segments, I think it >>>>> should be a SA_xyz flag to sigaction() (the way we have SA_RESTART >>>> Yes, I was proposing the new sigaction() flag in this thread >>>> already too. But at the end, prctl() looks better to me because >>>> it allows to pass the TLS value to use when restoring FS. >>>> The thing is that I am trying to find the similar treatment for >>>> both the SS and FS problems. If you don't think they need a >>>> similar treatment, then perhaps the Andy's patch is enough. >>>> >>>>> etc). And off by default because of the obvious compatibility issues. >>>> Of course. >>>> >>>> So, what we have right now (in the latest Andy's patch) is: >>>> 1. lar heuristics >>>> 2. new uc_flags flag >>>> >>>> What it solves: dosemu's regression. >>>> >>>> What prctl() can give: >>>> - fix to dosemu's regression >>>> - fix to the TLS problem in the future >>>> - no hack and heuristics >>>> >>>> With SA_xyz you can only solve the SS problem, so it is >>>> probably not any better than the uc_flags things coded >>>> up by Andy. >>> I'm leaning slightly toward LAR heuristic + SA_SAVE_SS. >> Stop right here, doesn't the SA_xyz allow to avoid the >> lar heuristic? Why would you still need the lar heuristic then? >> Just call it SA_RESTORE_SS instead of SA_SAVE_SS, and >> the lar heuristic is gone. > The LAR heuristic is about five lines of code, and it makes signal > delivery more reliable. Sure, we could gate the "regs->ss = > __USER_DS" line on a flag, but why? Speed? I'll let others decide on that. My vote is to no heuristic if possible, and keeping the FS problem in mind if possible (obviously, both are possible). >>> Unfortunately, I don't think we were clever enough to allow this to be >>> probed easily -- we silently ignore unrecognized sa_flags bits. >> Big deal, check the kversion. :) > Not so good. For example, if you made your DOSEMU patch to use the > saved SS check the version, then the backported revert would break > you. I would be scared to imagine the program that probes for everything, adding more and more probes with years, instead of just saying "you need kernel version at least x.y.z". If some functionality is reverted, another kversion check can be added. This all is not new: dosemu's protected mode implementation doesn't work on many kernels selectively. IIRC it didn't work on 3.14 because the 16bit LDTs were disallowed, and other versions had problems too. It is easier to ban such kernels by versions instead of adding a run-time probes, because you don't know beforehand what will break in the next kernel to add a probe in advance, and when you react to an existing breakage, it already doesn't matter. The possibly of reverting a new functionality is similar to getting a breakage in an existing functionality (or even have lower probability), so I see no reason to choose different treatments for these two. But of course every author has own habits. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/