Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3540113pxb; Mon, 4 Apr 2022 20:30:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBS3inORoPl1nmYW9gny08rUT/x2iw1Myo117OX5WRSmggiwNRrR1AT2vSVBdrs0fWvLCo X-Received: by 2002:a17:90a:4882:b0:1c5:f4e2:989a with SMTP id b2-20020a17090a488200b001c5f4e2989amr1676981pjh.160.1649129425443; Mon, 04 Apr 2022 20:30:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649129425; cv=none; d=google.com; s=arc-20160816; b=FrYnX+oe5Vp0KCYNPMnpclus8MrRxAjNy6MF5lZIPqOeEl6VoxcazQ3CiR+fafixs2 RoyEin2yBZgelNZ6GhCYsr4afEQEx4LRu/VSETIpIDrACCm2+Qd7oQQPJkSyqC07+vLl zkucdV3IJDVpijXzWNEhZyy3Bv8gKrCGswdsR+DVy0yQqseaIQY6Z6LF/rTUew9KMvM9 fY8C3nEuI1mSWn6BxDchIOGvHf6qgUY7cgY/0H9zNLTCw2chzdRYVO0N7RIfAQLjsXNY 4A+bCvKQQlLk0dLJOVtNdsLAJYNoP1RLCAkRvni2r4UGGMuHKhxoU1Nm+tyS1czLEIJD Vffg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=o0vAHBhFcSoUS5jiIXPuGb0npNOBFBMsApNeWdL8Xg0=; b=p168DOtAuj9kZ+4owC3FYCtOdWbaXjJ5yk2sA074woAd7XZr1ADy0VnKWfg/jGPxzH zyomc8xOT+ZT8LBVPZ1IiVeOMRO/k0c1RASP45czzo4/KrHi7GTd6kES2gu9KTPipvjK 0StZPZXdX31m8nsMSLUkTHXR32rT4fbohPSUt5ZfpqO+qeepTDXrvBbBkZyZ7g2iGDcs kPoSnfYY3+3RsYj4O86J6OMyxhlyCrtJ4HDe5spNW98QOb4rPLYZx5zUHvIwWgt2AOSL TQ9tmDrSgCOts6QSRPvu+LgdX1lCGSynuTpllE8h9C4elG6pgTciO+wSh8CHGnDO1o0g 6ckg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eI01janH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id me18-20020a17090b17d200b001cacb4477f9si1037141pjb.149.2022.04.04.20.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 20:30:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eI01janH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 36B48AFAC1; Mon, 4 Apr 2022 18:29:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236483AbiDAT1P (ORCPT + 99 others); Fri, 1 Apr 2022 15:27:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231358AbiDAT1O (ORCPT ); Fri, 1 Apr 2022 15:27:14 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F082143469 for ; Fri, 1 Apr 2022 12:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648841124; x=1680377124; h=message-id:date:mime-version:to:cc:references:from: subject:in-reply-to:content-transfer-encoding; bh=1qdcczlKX4Qjv3s3lopzGh1+3WgMrjU6pxzvv7DskMU=; b=eI01janHOsQDF+Og23x5JZVO6xC5SmAEfhEox0A0SeU+Jvi1inFJMl/W JNLFWVy1BewXlbHr/Ae9sx6SXAn5YJP7T1CYT259w0YY+I1BAwCBZA3HW Fz2oXvY0wv6+x4bLLDBY3oLfyGTukr6UNLfH1bPTiJvXHjQzgFQLr6bXv 7JduJQMsRCy7O7SZFNSk26f8Ioukw5xDF4Df6gSox5mot/YAAOXFqEngD 84oazZslNmBg5U5E1JjXCb6Gu+0T94dsc1osbpuGXmNWHNNyb0nPsxWMV 3LGVFAUmVHRNSt76w4xgsv1Tw3p6faRmGsC9wFsJYPKt1jzrgJnOKCi/D Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10304"; a="240151866" X-IronPort-AV: E=Sophos;i="5.90,228,1643702400"; d="scan'208";a="240151866" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2022 12:25:24 -0700 X-IronPort-AV: E=Sophos;i="5.90,228,1643702400"; d="scan'208";a="567739894" Received: from dajones-mobl.amr.corp.intel.com (HELO [10.212.134.9]) ([10.212.134.9]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2022 12:25:22 -0700 Message-ID: Date: Fri, 1 Apr 2022 12:25:22 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: Bharata B Rao , Andy Lutomirski , Linux Kernel Mailing List Cc: linux-mm@kvack.org, the arch/x86 maintainers , "Kirill A. Shutemov" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Catalin Marinas , Will Deacon , shuah@kernel.org, Oleg Nesterov , ananth.narayan@amd.com References: <20220310111545.10852-1-bharata@amd.com> <6a5076ad-405e-4e5e-af55-fe2a6b01467d@www.fastmail.com> From: Dave Hansen Subject: Re: [RFC PATCH v0 0/6] x86/AMD: Userspace address tagging In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/23/22 00:48, Bharata B Rao wrote: > Ok got that. However can you point to me a few instances in the current > kernel code where such assumption of high bit being user/kernel address > differentiator exists so that I get some idea of what it takes to > audit all such cases? Look around for comparisons against TASK_SIZE_MAX. arch/x86/lib/putuser.S or something like arch_check_bp_in_kernelspace() come to mind. > Also wouldn't the problem of high bit be solved by using only the > 6 out of 7 available bits in UAI and leaving the 63rd bit alone? > The hardware will still ignore the top bit, but this should take > care of the requirement of high bit being 0/1 for user/kernel in the > x86_64 kernel. Wouldn't that work? I don't think so. The kernel knows that a dereference of a pointer that looks like a kernel address that get kernel data. Userspace must be kept away from things that look like kernel addresses. Let's say some app does: void *ptr = (void *)0xffffffffc038d130; read(fd, ptr, 1); and inside the kernel, that boils down to: put_user('x', 0xffffffffc038d130); Today the kernels knows that 0xffffffffc038d130 is >=TASK_SIZE_MAX, so this is obviously naughty userspace trying to write to the kernel. But, it's not obviously wrong if the high bits are ignored. Like you said, we could, as a convention, check for the highest bit being set and use *that* to indicate a kernel address. But, the sneaky old userspace would just do: put_user('x', 0x7fffffffc038d130); It would pass the "high bit" check since that bit is clear, but it still accesses kernel memory because UAI ignores the bit userspace just cleared. I think the only way to get around this is to go find every single place in the kernel that does a userspace address check and ensure that it fully untags the pointer first. ... > However given that without a hardware feature like ARM64 MTE, this would > primarily be used in non-production environments. Hence I wonder if MSR > write cost could be tolerated? It would be great of the mysterious folks who asked both Intel and AMD for this feature could weigh in on this thread. But, I've been assuming that these features will be used to accelerate address sanitizers which used heavily today in non-production environments but are (generally) too slow for production. I'd be very surprised if folks wanted this snazzy new hardware feature from every CPU vendor on the planet just to speed up their non-production environments. I'd be less surprised if they wanted to expand the use of pointer tagging into more production environments.