Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8847098ybl; Fri, 17 Jan 2020 02:07:08 -0800 (PST) X-Google-Smtp-Source: APXvYqxniTClIFieTPMighkh/d5huNpTRaGSNqdEv7hKKQk68hS16ZDt0a9JG56+fEy7fgxfqc9u X-Received: by 2002:a05:6808:c:: with SMTP id u12mr2786104oic.107.1579255628076; Fri, 17 Jan 2020 02:07:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579255628; cv=none; d=google.com; s=arc-20160816; b=UHgK/HJo2WzHcAvGMguznmyDz8rH3ktSgIQygtI31kDsjMglRPp28zjhd8euyzoDve oVzFFwENEinIiN5psRkdFgYSEpCF1uH6AfR7JjbIlJXmitJZv22XgWvqmjruZSRrh2Om Hf3K4DiDcfui1oaUbgWSTmEidabsE0Vzx7D5Jv/6IOlIQxNlKX8yEN66TWKKI+8qiMdE 5uxO6zvT94a3XKgVDU1q8JlCmz66Qit6X2tSfoVA6pm+51G1hW0qtfeabHwOx/56shw1 g+5lNOKlDo6dj2BNJPMH3nih7h7lbIRGrmlip2BZkRH+dCH5MORWZ03cPQvl5ITxRAUs qLLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=w/2c5M/UzJFnbWr1rvLc1suSEZvfABkxh5yg/ucrfTY=; b=KRlQ/wDLNIteFZoAgWpMJ6W1MwV8XkfooRekPI2DILYvEd/V0yyEowk3crmqMd3IIq C222uQ8scDlhIHg5EnY/53BygX67cyj9SDsGjQ9gkRaNmvmj09ILnmRbn6nCypa5CTvJ /lJG4jyB5p5v3PmEIDEC3GYPmNYStjsp4lnNjI/+u59Uq7Zmx1HE0M6Q3i5sGopuC0VU SOB46saK1j+uvvOf4VK/W+MupYhNKvqROG0szgCtAT2HpiBU+zSMAkxO0uVKzeE9EYsE 2BCw3Kedu0Zl+qwJYfe5YSWM4/jJVC+4G0C1DbYAFvclAUDlSx6rXZZRyYleGt5DaLqx Tjpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Mw7wWn7P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d23si13257786oij.270.2020.01.17.02.06.55; Fri, 17 Jan 2020 02:07:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Mw7wWn7P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726761AbgAQKFa (ORCPT + 99 others); Fri, 17 Jan 2020 05:05:30 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:43760 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbgAQKF3 (ORCPT ); Fri, 17 Jan 2020 05:05:29 -0500 Received: by mail-qk1-f195.google.com with SMTP id t129so22104824qke.10 for ; Fri, 17 Jan 2020 02:05:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=w/2c5M/UzJFnbWr1rvLc1suSEZvfABkxh5yg/ucrfTY=; b=Mw7wWn7P4s/MDlKKDeO2hCa7cduHamni/cV2VqAPosAt6si42jbxLnx+IUNOF7B/Xx if4jxxq3BIl5hm8W0DWkksygQWmW3YxDC6CK8ibhrPC2tvqh7HoEKYcJgYAH/Ummi20h I9H8RoUJoqUR44gfg1N3dIdTZix4xCDKE/ZjyVYpHXsSBHEr0I552pxJMKvvItl8Yht8 avKxub0Bu33Sx6p6daRqXSJ5DCOb/u+WPYBvJotCUdVId7Yfj0nw8N5IIYnkMAOEC9DN 3qXBAQQ/PE+8wLsmLUcvDbH1Mm+8dS7ScL2hkkB4b7S4ofHHpoQafskioxmHEqnka/Vf KcDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=w/2c5M/UzJFnbWr1rvLc1suSEZvfABkxh5yg/ucrfTY=; b=VhFLZes3Kal+3p/aBFGzMOEL+FRwGsDnXTom8LVmEQh/HjPeKGrGKcxQEKHzD1OUx7 LYYlWDCMYqixCN8qAxvRwvQZGbNjnqu93xnvMQ4vXo8+pN5hLHhrm/XXXSBPHWAvPU2i 73h79AU0eDvaiASWmwhi8XemYVp43VPcmb4NiEkgwWaaQiO7X8DDG+q1XjIcn9ESuWiY X/fu8RK3L7AjTusV9J9/LNxh1ItOmBMNxUFGc1W8Lpja92W2vUivJ1W8EjX7d/ptjCJd WEkuYDzisnvICANrEro0jv0vhTsd3t75UOddByI1wqaZMpuAvkHMof68R1XuumiTc04Q eZ0w== X-Gm-Message-State: APjAAAVMfSShlE+j7KRmaXzZuyggnujep993zxibWrisWqWj7aJw5Ifa nZ3CEDnnwIgVi7RYo8ZDqRVTyAyDOjrvNqbRrOnprg== X-Received: by 2002:a37:5841:: with SMTP id m62mr36462569qkb.256.1579255527934; Fri, 17 Jan 2020 02:05:27 -0800 (PST) MIME-Version: 1.0 References: <20200115182816.33892-1-trishalfonso@google.com> <4f382794416c023b6711ed2ca645abe4fb17d6da.camel@sipsolutions.net> <2092169e6dd1f8d15f1db4b3787cc9fe596097b7.camel@sipsolutions.net> In-Reply-To: From: Dmitry Vyukov Date: Fri, 17 Jan 2020 11:05:15 +0100 Message-ID: Subject: Re: [RFC PATCH] UML: add support for KASAN under x86_64 To: Johannes Berg Cc: Patricia Alfonso , Richard Weinberger , Jeff Dike , Brendan Higgins , LKML , kasan-dev , linux-um@lists.infradead.org, David Gow , Andrey Ryabinin , anton.ivanov@cambridgegreys.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 17, 2020 at 11:03 AM Dmitry Vyukov wrote: > > On Fri, Jan 17, 2020 at 10:59 AM Dmitry Vyukov wrote: > > > > On Thu, Jan 16, 2020 at 10:39 PM Patricia Alfonso > > wrote: > > > > > > On Thu, Jan 16, 2020 at 1:23 AM Dmitry Vyukov wrote: > > > > > > > > On Thu, Jan 16, 2020 at 10:20 AM Johannes Berg > > > > wrote: > > > > > > > > > > On Thu, 2020-01-16 at 10:18 +0100, Dmitry Vyukov wrote: > > > > > > > > > > > > Looking at this problem and at the number of KASAN_SANITIZE := n in > > > > > > Makefiles (some of which are pretty sad, e.g. ignoring string.c, > > > > > > kstrtox.c, vsprintf.c -- that's where the bugs are!), I think we > > > > > > initialize KASAN too late. I think we need to do roughly what we do in > > > > > > user-space asan (because it is user-space asan!). Constructors run > > > > > > before main and it's really good, we need to initialize KASAN from > > > > > > these constructors. Or if that's not enough in all cases, also add own > > > > > > constructor/.preinit array entry to initialize as early as possible. > > > > > > > > > > > I am not too happy with the number of KASAN_SANITIZE := n's either. > > > This sounds like a good idea. Let me look into it; I am not familiar > > > with constructors or .preint array. > > > > > > > > We even control the linker in this case, so we can put something into > > > > > the .preinit array *first*. > > > > > > > > Even better! If we can reliably put something before constructors, we > > > > don't even need lazy init in constructors. > > > > > > > > > > All we need to do is to call mmap syscall, there is really no > > > > > > dependencies on anything kernel-related. > > > > > > > > > > OK. I wasn't really familiar with those details. > > > > > > > > > > > This should resolve the problem with constructors (after they > > > > > > initialize KASAN, they can proceed to do anything they need) and it > > > > > > should get rid of most KASAN_SANITIZE (in particular, all of > > > > > > lib/Makefile and kernel/Makefile) and should fix stack instrumentation > > > > > > (in case it does not work now). The only tiny bit we should not > > > > > > instrument is the path from constructor up to mmap call. > > > > > > This sounds like a great solution. I am getting this KASAN report: > > > "BUG: KASAN: stack-out-of-bounds in syscall_stub_data+0x2a5/0x2c7", > > > which is probably because of this stack instrumentation problem you > > > point out. > > > > [reposting to the list] > > > > If that part of the code I mentioned is instrumented, manifestation > > would be different -- stack instrumentation will try to access shadow, > > shadow is not mapped yet, so it would crash on the shadow access. > > > > What you are seeing looks like, well, a kernel bug where it does a bad > > stack access. Maybe it's KASAN actually _working_? :) > > Though, stack instrumentation may have issues with longjmp-like things. > I would suggest first turning off stack instrumentation and getting > that work. Solving problems one-by-one is always easier. > If you need help debugging this, please post more info: patch, what > you are doing, full kernel output (preferably from start, if it's not > too lengthy). I see syscall_stub_data does some weird things with stack (stack copy?). Maybe we just need to ignore accesses there: individual accesses, or whole function/file.