Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3670131imw; Thu, 7 Jul 2022 05:53:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sR0PGYu5XHDfi342cBuNqDLNWB5hgLceypiRWlqDwquf/pydBBoTNkoKGNwb2mYX7pweO6 X-Received: by 2002:a05:6402:388b:b0:42b:5f20:c616 with SMTP id fd11-20020a056402388b00b0042b5f20c616mr60936347edb.50.1657198406423; Thu, 07 Jul 2022 05:53:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657198406; cv=none; d=google.com; s=arc-20160816; b=p49WRbfPA7ZH5MV1kW7QoXchqTSr02pCgEZEG4TPlG5Q6Jv4l6IJ+w3wsqYTodAY1C WIIlSIc+giDpsUcL7msJllQ/DGIa6CGVabN2WrHzhtEIrd41ruNX6wQI8Mfkz4BXflQP S850MlntqqBy8sqCntP+luotrZQvq+N9K7Yau5WAQsikd9jtpsHxVF1/UjE9y+/z500N 97URGCSNfldhsjBjy3yTjl3st/FPwG58KUhqURmGCG6bpwW33nYIk9dnveU9pHz543Km 3nCLoWAkJGBYgmTNTdW7hUG9lCTmLr6ZDJqpxaH4SUGo7ZNNG4+6isMnepQA6blhiK9K OfwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xuotuzqmuqvW/pM1XwazWuXR0jU+xokqDC6ljmKSi7Q=; b=Xjk3EFv370kO3Dzs/RicJjzwrGGs8d3ydfX9R3EVAEtKgK/dVSkX+ee5zX9sMAWZP9 LOIdDRi2FHIiAOPvgaakZrdurLZaJZVeRa4tmfpvLdPTQa2GqlQMD4BkXTDB7c/YN2YN hMno/UzGKBXak0uDJsbvmMWYq24h6OV1dPkpIXMf/mPbfuZRIjQBcZZy3TYCmgxN1CS2 atAvnBrrqbyPvZV/cdSyvkKiZMY/+cymaXJK0cqH6gfdzw37Vseb8aU6QlaeEwXCwtCc ppmBO11KV/3/A96NAbDRxQcYpLc/lw+GOKkKioNSPduoaryPFHxx8VqqUnzZVttzhsbf CZkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PBpUDtxp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r13-20020a170906364d00b00726b8363630si15555613ejb.923.2022.07.07.05.53.00; Thu, 07 Jul 2022 05:53:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PBpUDtxp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235644AbiGGMAR (ORCPT + 99 others); Thu, 7 Jul 2022 08:00:17 -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: X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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