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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F47BC43334 for ; Thu, 7 Jul 2022 12:00:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235052AbiGGMAS (ORCPT ); Thu, 7 Jul 2022 08:00:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235642AbiGGMAC (ORCPT ); Thu, 7 Jul 2022 08:00:02 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B0135925D for ; Thu, 7 Jul 2022 04:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657195084; x=1688731084; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Y897ccQh9DniNRVq6CwkRyY6onhzd1oeECrmj1dS8v0=; b=PBpUDtxpZPreo5XK0FPNp58UqL0ySFG0aRLQiV/SStWqxmrtXvQ+XjPC cSw1UUT20t8elxZo2RJAnTJVznULekP158mRNv09FHI7pyNhEU/bSRFmZ aQveGGD3cvPIfqb1RWaZVMQw8/gVGrWQYCGXoUsxC3ndsGx+fLf+PGDFh WC2GLeDnyPv1NrsMhAE4+4OfGN7WvStxDWz5vVh9Wg0KYeMmw0e3JxEk4 NgkXHerSXZtCdyi/BuCihfyo48l1A3FlkAm2Cu8MzqRHAzfUAah9J5W7f a/Pr/48alSEc8em/kGw1l5gVfRlSNfUa2hLvMn/m3T+tSrPruxAganyOZ Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10400"; a="284029853" X-IronPort-AV: E=Sophos;i="5.92,252,1650956400"; d="scan'208";a="284029853" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jul 2022 04:58:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,252,1650956400"; d="scan'208";a="620762106" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 07 Jul 2022 04:58:00 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id C5DCD400; Thu, 7 Jul 2022 14:58:07 +0300 (EEST) Date: Thu, 7 Jul 2022 14:58:07 +0300 From: "Kirill A. Shutemov" To: Alexander Potapenko Cc: Dave Hansen , Andy Lutomirski , Peter Zijlstra , the arch/x86 maintainers , Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Linux Memory Management List , LKML Subject: Re: [PATCHv4 3/8] mm: Pass down mm_struct to untagged_addr() Message-ID: <20220707115807.pzrj7bngm2ndcjwk@black.fi.intel.com> References: <20220622162230.83474-1-kirill.shutemov@linux.intel.com> <20220622162230.83474-4-kirill.shutemov@linux.intel.com> <20220706231349.4ghhewbfpzjln56u@black.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 07, 2022 at 10:56:53AM +0200, Alexander Potapenko wrote: > On Thu, Jul 7, 2022 at 1:14 AM Kirill A. Shutemov > wrote: > > > > On Tue, Jul 05, 2022 at 05:42:21PM +0200, Alexander Potapenko wrote: > > > Kirill, > > > > > > > > > > diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c > > > > index feeb935a2299..abc096a68f05 100644 > > > > --- a/lib/strnlen_user.c > > > > +++ b/lib/strnlen_user.c > > > > @@ -97,7 +97,7 @@ long strnlen_user(const char __user *str, long count) > > > > return 0; > > > > > > > > max_addr = TASK_SIZE_MAX; > > > > - src_addr = (unsigned long)untagged_addr(str); > > > > + src_addr = (unsigned long)untagged_addr(current->mm, str); > > > > > > In a downstream kernel with LAM disabled I'm seeing current->mm being > > > NULL at this point, because strnlen_user() is being called by > > > kdevtmpfs. > > > IIUC current->mm is only guaranteed to be non-NULL in the userspace > > > process context, whereas untagged_addr() may get called in random > > > places. > > > > > > Am I missing something? > > > > Hm. Could you show a traceback? > > > > As strnlen_user() intended to be used on an user string I expected it to > > be called from a process context. I guess I'm wrong, but I don't yet > > understand why. > > Oh, I see now. The old implementation of devtmpfsd() > (https://elixir.bootlin.com/linux/v5.4/source/drivers/base/devtmpfs.c#L397) > uses ksys_mount(), which assumes that the strings must be copied from > the userspace, whereas they are actually constants in kernel .rodata > > Wonder if the validity of mm->current for userspace accesses is > actually enforced anyhow in newer kernels. I think it is. See 967747bbc084 and how it changes strnlen_user(). With max_addr equal to TASK_SIZE_MAX, strnlen_user() will always fail on a kernel string. -- Kirill A. Shutemov