Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7549654ybl; Thu, 16 Jan 2020 01:21:04 -0800 (PST) X-Google-Smtp-Source: APXvYqxhWD4TEEjoERu4Bhm6DGAq2eAWLsUR4HoR9QG5Kad6jR09VLZ5/rhdrpH+rxIyTMeMIo+z X-Received: by 2002:aca:e189:: with SMTP id y131mr3186154oig.111.1579166464455; Thu, 16 Jan 2020 01:21:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579166464; cv=none; d=google.com; s=arc-20160816; b=ukPs/zskpG1QsQbwInn7QsTWQHTyiW97OR8fd3V/DvT1TDeAKDCK0SP0ejlMGBQpXk YHYegX137m0g5xKrtxqR8k+Xk9hqXwlGJquvSzeEygi7+o6N95duJeFtLBbAyB6W8s7W zg3scfAQhmU2LsaUWT5emZLrdZca371UXyUzya5loGllxJK5Tjrq0LjNxRTtsPY56eVh m5fYisuOP0EMOWqwau0Jl9l8X4lSjZQyj1wvO7rlDCjiJ0kuPNLMvKvvwf15UpaCISep DOwh0KN26iXvbgSA4NqWV1cmhgysSeNS5Wm6aBdBMkkGUuXDXDHKXifxjehb0DWuNTTM /tww== 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=6aUm9IZBoyzrmlaZrE7sKzVINYzfYj5bNqwcb9Va7iI=; b=X7J2DRfDU964dbq7pTSh4sovJDUo2sa+APB3Ktt1By+qOkYxazcGa+tktkhBYOpbxr UX48wiSQ4gfOcBM0a91KAzUOUrIPiJjyW5IQ1+aUdYw5U/fYxCRzdVF538LAAZtiNZpR tdOadCRYsTHv3aYtLam+TbF3FvW2Fekp2xiZbn+kkehaPADv/6yyiwlfgoBYPkW3jk4S or0U15XmALvwb0NtSlQguSx7pmLtLfIFUGi7MXgf1nYX80on5tl3OLcyPa85jiYTYyUh QnaaFV39yL9wC3Qly2rv9XfjbeJoNbA1VayzojF9rz4jY8PIeZjYedHGZNfMl3jeWwZP TkLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SYYbnAVS; 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 k7si13122259otp.22.2020.01.16.01.20.51; Thu, 16 Jan 2020 01:21:04 -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=SYYbnAVS; 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 S1730040AbgAPJSi (ORCPT + 99 others); Thu, 16 Jan 2020 04:18:38 -0500 Received: from mail-qv1-f67.google.com ([209.85.219.67]:46001 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726684AbgAPJSi (ORCPT ); Thu, 16 Jan 2020 04:18:38 -0500 Received: by mail-qv1-f67.google.com with SMTP id l14so8734878qvu.12 for ; Thu, 16 Jan 2020 01:18:37 -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=6aUm9IZBoyzrmlaZrE7sKzVINYzfYj5bNqwcb9Va7iI=; b=SYYbnAVSUXIa9qjPlD9vE1jh2fCqbJAF0lK3PwmNSVGUE7fZ33KjX8Jp/FflTWJ3X3 WibzlMsnD5C7Lt1GTydrGs3zVxD8rnwiOHiHoAqyvYvBPqP+yN8skqAviLHJbytc34rv r1N+iQyRTkh4D60kFtO93fnagprGQQ5hdkH4p3eNquV3KT22+JlLvIVEGK+Qfg3Cqtud YwSEufB3R8cxmXBfTlzweLnBxfWw4pN4N+aUud8u7/3DBko8z2RIlzUQuZ5ZlFpc51wW YGQ0KyakrxLSLYaMN/REc/+8bH2bZEvxQJlQfK6XAmp7Y9HFCC7PWOPxaSvQeqFWXvcK jD/A== 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=6aUm9IZBoyzrmlaZrE7sKzVINYzfYj5bNqwcb9Va7iI=; b=uar4rZGfQIP5bicmGmceh+kd8dkScuuDbY8OQVBYKwLICWw4/ynELRcyAwCWiMgHCA ICbrabSHu0sziSLlFKGbO+ELdk7Afre1jCUHPSh5dkYaWt2oBOtCf4OUf/AFq9J2yHm8 0FM+F0GY3U642QO8K2acskBNi4xtjC2XdaqsYy4M0dzC00StxeMDOz61INBHc52QWcbI ak9Q61J1uDd6OgbkvFX2eDme6bCOkJVKqopSvrnNT90ZNE7EBg0JdCFkGhFPEATmruCJ JUvj6X/VuuQGf8Tn2KmN7BBhbB+bkObB99alFLGjN+RW248nPlOcN812YNVZ/wlcqYit B3lA== X-Gm-Message-State: APjAAAU4Xj04o1bqbp0ucYBa0XHiqoEgW++cS3RTN0Cx8Nvovkfb0C4s IKEIvdKlJyg8m83jAYJ2Gll0226nQXm+3ohesnBArX2WtLg= X-Received: by 2002:a05:6214:1103:: with SMTP id e3mr1646963qvs.159.1579166316797; Thu, 16 Jan 2020 01:18:36 -0800 (PST) MIME-Version: 1.0 References: <20200115182816.33892-1-trishalfonso@google.com> <4f382794416c023b6711ed2ca645abe4fb17d6da.camel@sipsolutions.net> In-Reply-To: From: Dmitry Vyukov Date: Thu, 16 Jan 2020 10:18:25 +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 Thu, Jan 16, 2020 at 9:03 AM Johannes Berg wrote: > > On Thu, 2020-01-16 at 08:57 +0100, Johannes Berg wrote: > > > > And if I remember from looking at KASAN, some of the constructors there > > depended on initializing after the KASAN data structures were set up (or > > at least allocated)? It may be that you solved that by allocating the > > shadow so very early though. > > Actually, no ... it's still after main(), and the constructors run > before. > > So I _think_ with the CONFIG_CONSTRUCTORS revert, this will no longer > work (but happy to be proven wrong!), if so then I guess we do have to > find a way to initialize the KASAN things from another (somehow > earlier?) constructor ... > > Or find a way to fix CONFIG_CONSTRUCTORS and not revert, but I looked at > it quite a bit and didn't. 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. All we need to do is to call mmap syscall, there is really no dependencies on anything kernel-related. 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.