From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD902C433FE for ; Thu, 17 Nov 2022 22:06:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10B876B0071; Thu, 17 Nov 2022 17:06:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BCCE6B0072; Thu, 17 Nov 2022 17:06:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9F408E0001; Thu, 17 Nov 2022 17:06:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DA85F6B0071 for ; Thu, 17 Nov 2022 17:06:57 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8010BA82FF for ; Thu, 17 Nov 2022 22:06:57 +0000 (UTC) X-FDA: 80144320074.10.7CE55FF Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf04.hostedemail.com (Postfix) with ESMTP id 0D1C740006 for ; Thu, 17 Nov 2022 22:06:56 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id w23so2876074ply.12 for ; Thu, 17 Nov 2022 14:06:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=t2jCs60kn1VpKqRV5eqfHEnkYPCpSmcc9fFC/BsCBvY=; b=YXVt+q2t6CS8/Pz/E+AFY6qXuR2xREw03ymI68D8Wp5S9neLuD8HAsa3mLVc/06RkI 4jigOI6QzRXZrrgdRMmCaw+Q1TT0RkYx+jDpyyGT4NxExXCflMJX4THIHHJvvTZfBlIh ndTTVEkB627rm6vJSferAhCogOm+kukqVocB8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=t2jCs60kn1VpKqRV5eqfHEnkYPCpSmcc9fFC/BsCBvY=; b=Lqyj1IHGqp2uQFOgx3SMLOBG4jWkc+e6iO84QbRddZISBn8EF/PeqeOCFbqw3eXHLJ xkCx1Pr/npTzc6pYHpmTC9YMqd0xBDuR8+s0c/LmcMXEwEGkKbMUX2LRCllXfD0B89Ag x5H9204QHv0hR4TGFpoq6z0FXPWCW3clGklQG+tHy/7WW+l2cGvknRRmSxzNQpivGjFa mnPwu5E1hb1hA3UbPcHifZ+5SixR0q6B/ZVACoI5hNLPBfjGAlUk8qm5ez6Pq9lu9Tci syAI3hsbr4Ct2Miky9S5EddLM+agtbjjZD3hgAGaRz3VVfgX1FXfjlKTVdA/e43Pf5Jw +08Q== X-Gm-Message-State: ANoB5pnLyVkmGGz3wl6LP/tDbvvkh++y0V/lj+IPpPn+UOd9O1UZGSdf IytxKV4A/bY20+xJzCbvAlmmvu7Y6pvuCg== X-Google-Smtp-Source: AA0mqf6i68QB542uMSj8JGp5LTdvqzXHyOfwe+Ko1FvCgTDRRoNz6WIBYhEjEASqQscI22Pu3nbxuw== X-Received: by 2002:a17:902:aa93:b0:17c:892e:7c8e with SMTP id d19-20020a170902aa9300b0017c892e7c8emr4657705plr.92.1668722816081; Thu, 17 Nov 2022 14:06:56 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id y15-20020aa79aef000000b00565cbad9616sm1659213pfp.6.2022.11.17.14.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 14:06:55 -0800 (PST) Date: Thu, 17 Nov 2022 14:06:54 -0800 From: Kees Cook To: Matthew Wilcox , linux-mm@kvack.org Cc: Pedro Falcato , linux-kernel@vger.kernel.org, David Gow , sam@gentoo.org, Alexander Viro , Eric Biederman , linux-fsdevel@vger.kernel.org, Rich Felker , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com Subject: Attaching userspace VM to kernel thread (was Re: [PATCH] fs/binfmt_elf: Fix memsz > filesz handling) Message-ID: <202211171402.95121B3FD4@keescook> References: <20221106021657.1145519-1-pedro.falcato@gmail.com> <202211061948.46D3F78@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668722817; a=rsa-sha256; cv=none; b=swut1nS/8ykM0uIu/VB2Owjig51PvoxjBeQsBpF4+Q5cLDtBzUHdIauwVA6AWJIqN9bmgz t8stf2MJAflXUmvmGG1pZFMnvGMRU9PXWe/UujuIA08XATO3T9Wx/93n0byiRfODx4Xy4h dY1rjTbFmOG2wAaP2MHmm9mDCWhPmwE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=YXVt+q2t; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf04.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.182 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668722817; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=t2jCs60kn1VpKqRV5eqfHEnkYPCpSmcc9fFC/BsCBvY=; b=1mazttJVdCJY8RhmQgAtCajbCfxuAC7/OYGjD0rfZzGHlsCV3enGtxVnFJXLHnt7lKSiDb U3IRdRMQ6yM4QzDgX84O0fdzJoNNtU/o003UqediX/9tZXcDcmrcfwul4WJR/pyi8a85jK YFnMDeD+gk0J7qBGAa7sVhokB301GP4= X-Stat-Signature: bm97xxw8q6bzya3ashsx6concm65h5yc X-Rspamd-Queue-Id: 0D1C740006 X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=YXVt+q2t; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf04.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.182 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Rspamd-Server: rspam09 X-HE-Tag: 1668722816-144604 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi, This has diverged from the original topic a bit, so I've changed the Subject to hopefully gain visibility. :) For KUnit, it would be REALLY nice to have a way to attach a userspace VM to a kernel thread so we can do userspace memory mapping manipulation, etc. Neither David nor I have been able to figure out the right set of steps to make this happen. What are we missing? Details below... On Wed, Nov 16, 2022 at 12:34:40PM +0800, David Gow wrote: > On Mon, Nov 7, 2022 at 11:59 AM Kees Cook wrote: > > > > On Sun, Nov 06, 2022 at 02:16:57AM +0000, Pedro Falcato wrote: > > David, has there been any work on adding a way to instantiate > > userspace VMAs in a KUnit test? I tried to write this myself, but I > > couldn't figure out how to make the userspace memory mappings appear. > > Here's my fumbling attempt: > > https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=devel/kunit/usercopy > > > > I really wish KUnit had userspace mapping support -- I have a bunch of > > unit tests that need to get built up around checking for regressions > > here, etc. > > Hi Kees, > > Sorry the the delayed response! > > Alas, my attempts to get this to work haven't been much more > successful than yours. It's definitely something we'd like to support, > but I confess to not knowing enough about the mm code to know exactly > what would be involved. > > The workaround is to load tests as modules, and use something like > Vitor's original patch here: > https://lore.kernel.org/all/20200721174036.71072-1-vitor@massaru.org/ > > Basically, using the existing mm of the module loader. Adapting those > changes to your branch (and fixing a couple of back-to-front KUnit > assertions) does work for me when built as a module, in an x86_64 vm: > > root@slicestar:~# modprobe usercopy_kunit > [ 52.986290] # Subtest: usercopy > [ 52.986701] 1..1 > [ 53.246058] ok 1 - usercopy_test > [ 53.246628] ok 1 - usercopy > > But getting it to work with built-in tests hasn't been successful so > far. I wondered if we could just piggy-back on init_mm or similar, but > that doesn't seem to work either. > > So, in the short-term, this is only possible for modules. If that's > useful enough, we can get Vitor's support patch (or something similar) > in, and just mark any tests module-only (or have them skip if there's > no mm). Because kunit.py only runs built-in tests, though, it's > definitely less convenient. Thanks for any pointers! :) -Kees -- Kees Cook