Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp677908lqp; Wed, 12 Jun 2024 12:48:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU7jfibfDKDtdFRIvfQ1WkDKbqb1djuGDzKgYFneabt4kPU7r2mZiqxeBLjx9f61ZnpEPeZ1Onl7wnZPBKXMcX606lIEMYWFTAoYA5zVA== X-Google-Smtp-Source: AGHT+IH4wxSEAjRDaBSAsOy3VsT+vtpYPW0lFi+V0uX0e94WwW4PndfhHzgmLAPxQyzaK8imgNWX X-Received: by 2002:a5d:694c:0:b0:35f:3051:1935 with SMTP id ffacd0b85a97d-35fe8937e29mr2831920f8f.59.1718221689383; Wed, 12 Jun 2024 12:48:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718221689; cv=pass; d=google.com; s=arc-20160816; b=V5WvaMZqQU7eO8GNZF2XLEVDdTZeUpVVC9R+JEVHNxR2AmzAm9Bh+T1pdYivLsa1au dbFES/7Nw2q4zgwNk53+V895hdEAhXvKyIVlpfwwHwoK9eDPPW8aloMyBtFw4RgTvmaz nlKi+J5fz3fCk3W+jfREyaaijXkPSBfOAw4BmmeZFzih74AzlE+sVScgLhAUEBTg99PG 1yhxBcEL8+hxBKfAeoyUocjPLTPEzOl31PnpodEKqzRnZ+dVj9Fa05BEw5O4uJ196Fgb ScRx9TVMNP3+GhWWIKdbyc1cc3Mg2/G7/TCYskAWxqOd/4Bea0uy22K9WaD5WeY0u3Ih cfuA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9eJaLCrlG/ntjrLc40dKxAjgJIwKnTZRdeTQde+GDy4=; fh=Cd4yW8B+37fJ1Ihmf4+OdLqDWf+lrzM9sjrG0zV3lww=; b=D4M/DDMNjXaYDI5J/VftJDL3vWRFqqwgSwSXOFILA5cNeWzW7XDZZUyFwdpT5ZfBUO kOiGjQv2b39PXClZtS7FETwmEe/lSbdQmsjG/IvGZQ6lsNMAQmlApWw8u8jxvad4HshR lnCAwGgWT7HKyR6KfJAt69EVycdYj/ukpTXVdNtZBC+YqJulfHL4hVLxs/RKJsveR12i GFABWIMWSudoFCkRNjNcjy95LDHQN+k1rFpVq3qczkFQUbx9c2TyM62MfP3AkOQKAof1 snCTUqmSj7BZ/RgZusjaTsO3HekaHn7ogBqb+gGNjEzfxgRofPAKWF5hSX00BIqkc5Tq LE1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t3n2VsgT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-212173-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c8074a7a8si692198466b.964.2024.06.12.12.48.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 12:48:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212173-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t3n2VsgT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-212173-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D7B581F23EC5 for ; Wed, 12 Jun 2024 19:48:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE56A7E110; Wed, 12 Jun 2024 19:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t3n2VsgT" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F06A72F50; Wed, 12 Jun 2024 19:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718221661; cv=none; b=dWTKmM65ZY5mq/NZs0iraOWfo2EMGykYOYLHcfx8ttdquouHoiXF3Knp2afC8LjDhdDrG4pay2ndULw/ftSH1OdoAPJdtprE2CHFH6JfjwcmMiQLzhgSMUfYBnKZJY8y/ibQjMv4HDz/0T8z6+7qGF+Tu/vTh38pLBLArRYjhbA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718221661; c=relaxed/simple; bh=8FQ9c7Ch3FC/45m1f2sv/N9cm5NEyghZRzqrKFkzdcc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XduqL8uip+lQyqhMEQLlkTuTTViGjIV80UnHgcYnHOyBFIaNVhm1U6UwKdwenqN4Je0qq7PBzs+4N8/It3COslxy8gmpyLm7179h44gG+h2XzAGibHFcHnrnITN/68v2LezdSl2AgCacLMq4j7k2DFOvkVDpQwDI5p8PUhXKW8E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t3n2VsgT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E0E3C32786; Wed, 12 Jun 2024 19:47:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718221660; bh=8FQ9c7Ch3FC/45m1f2sv/N9cm5NEyghZRzqrKFkzdcc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=t3n2VsgTo08P0X+ucMW5nAE/Jvi9bmuYntTSGWbfOVXyyUq+OavQcZ4zmCAVQnZpv +i6acaHOQFmJDaIa632xABI/nodaQrNGRsnz75tgXcuWQJJAfJ2tIpZV/bu/xhlA8p CG4jNiNFNskT1asWdp4RKIYVhwfkIcjGQxFxA1U8bG7+cwLhd/2cSAXDl8w/VGK9Cw YTRdjK5Vzg5lAtN4p1q4kPEobXuvszyijmAYOr7nMJFj+qijmGCB+sAFS9hN59DeN9 g55JEtguQDdCLfgG9tqwF1AxhD2eeNBL/41lPRER0tTmJIdgbRfqyvtgy38zWi0knR 5xAiZJGcQ69aA== Date: Wed, 12 Jun 2024 12:47:39 -0700 From: Kees Cook To: Geert Uytterhoeven Cc: Mark Rutland , David Gow , Vitor Massaru Iha , Ivan Orlov , Brendan Higgins , Rae Moar , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-hardening@vger.kernel.org, linux-m68k@lists.linux-m68k.org Subject: Re: [PATCH v2 2/2] usercopy: Convert test_user_copy to KUnit test Message-ID: <202406121245.D3536D45D@keescook> References: <20240610213055.it.075-kees@kernel.org> <20240610213330.1310156-2-kees@kernel.org> <202406120927.3C64ACD6@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Jun 12, 2024 at 09:21:52PM +0200, Geert Uytterhoeven wrote: > Hi Kees, > > On Wed, Jun 12, 2024 at 6:51 PM Kees Cook wrote: > > On Wed, Jun 12, 2024 at 05:13:39PM +0800, David Gow wrote: > > > On Tue, 11 Jun 2024 at 05:33, Kees Cook wrote: > > > > Convert the runtime tests of hardened usercopy to standard KUnit tests. > > > > > > > > Co-developed-by: Vitor Massaru Iha > > > > Signed-off-by: Vitor Massaru Iha > > > > Link: https://lore.kernel.org/r/20200721174654.72132-1-vitor@massaru.org > > > > Tested-by: Ivan Orlov > > > > Signed-off-by: Kees Cook > > > > --- > > > > > > This looks good, particularly with the x86 fix applied. > > > > > > It's still hanging on m68k -- I think at the 'illegal reversed > > > copy_to_user passed' test -- but I'll admit to not having tried to > > > debug it further. > > > > > > One other (set of) notes below about using KUNIT_EXPECT_MEMEQ_MSG(), > > > otherwise (assuming the m68k stuff isn't actually a regression, which > > > I haven't tested but I imagine is unlikely), > > > > I'm trying to debug a hang on m68k in the usercopy behavioral testing > > routines. It's testing for the pathological case of having inverted > > arguments to copy_to_user(): > > > > user_addr = kunit_vm_mmap(test, NULL, 0, priv->size, > > PROT_READ | PROT_WRITE | PROT_EXEC, > > MAP_ANONYMOUS | MAP_PRIVATE, 0); > > ... > > bad_usermem = (char *)user_addr; > > ... > > KUNIT_EXPECT_NE_MSG(test, copy_to_user((char __user *)kmem, bad_usermem, > > PAGE_SIZE), 0, > > "illegal reversed copy_to_user passed"); > > > > On other architectures, this immediate fails because the access_ok() > > check rejects it. On m68k with CONFIG_ALTERNATE_USER_ADDRESS_SPACE, > > access_ok() short-circuits to "true". I've tried reading > > arch/m68k/include/asm/uaccess.h but I'm not sure what's happening under > > CONFIG_CPU_HAS_ADDRESS_SPACES. > > On m68k CPUs that support CPU_HAS_ADDRESS_SPACES (i.e. all traditional > 680x0 that can run real Linux), the CPU has separate address spaces > for kernel and user addresses. Accessing userspace addresses is done > using the special "moves" instruction, so we can just use the MMU to > catch invalid accesses. Okay, that's what I suspected. I think I'll need to just not test this particular case for archs with separate address spaces, since it would be meaningless. > > > For now I've excluded that test for m68k, but I'm not sure what's > > expected to happen here on m68k for this set of bad arguments. Can you > > advise? > > Perhaps the kernel address is actually a valid user address, or > vice versa? Right -- I think that's what's happened. > > Does the test work on systems that use 4G/4G for kernel/userspace > instead of the usual 1G/3G split? > > /me runs the old test_user_copy.ko on ARAnyM > Seems to take a while? Or it hangs, too? Sounds like the same behavior. > Related reading material > https://lore.kernel.org/all/CAMuHMdUzHwm5_TL7TNAOF+uqheJnKgsqF+_vzqGRzB_3eufKug@mail.gmail.com/ > https://lore.kernel.org/all/CAMuHMdVQ93ihgcxUbjptTaHdPjxXLyVAsAr-m3tWBJV0krS2vw@mail.gmail.com/ Thanks! -Kees -- Kees Cook