Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3150253pxk; Mon, 7 Sep 2020 04:51:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRzmagBe3ig6Bc+UUnx55Tz/CLAL3k0do6QEr/BTrTAyUhRPUYACMJ/9gGlzZGTTRKnc7Q X-Received: by 2002:a17:906:1c4f:: with SMTP id l15mr20309399ejg.419.1599479470683; Mon, 07 Sep 2020 04:51:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599479470; cv=none; d=google.com; s=arc-20160816; b=Dh3coEZePUMweF7fO9zxbeYCdbEPh2PWrFaPA+MkcZKYwb0Rt374hUidZtDOIl+cK7 9+JaFWUWoEK2KNgeWw4bwQnDwrHScsZ70OG9TCzWPXqsg2+7+p4amCx5loDiIZY+U3XX 0VZwQg401VWxI2gjbI5Qq64JMO9dDZ6KCeDS2laahhotdg0yTLSrbhVSgvetURepTTqp wgcR+7IFmUwTT8NVAui7hosAuwaYrsZbSoYOAOKhtTgzSY6DjQRuY5IAT1Qt2WgHWQrw orFa501BZjdYHv/MysQ66XgqUYMjZulgVoq9Le4CuWNDGNAUNgnI89vcjrHd0smISFEL sn4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=LlvDbaT+mnlWpNIwv458E8+yI8vp8lUqGvevS1JpCNg=; b=VayBgGDEGuH/L5h2djieipqSlWb+xbJZkDOj+47cEyRg1hLJk5brA5IWVROFI4/zvV UGQeD77dVBhvkZJMUY/4PNMYRcsSiifgyEFNEC/7uPdmOL2lPgRtDQHPyXA8i/m1zJ+d cPgxBR+B6fJKdeYJ5LJASJXzpxYYCVKW/FZB3O5cV/xX707Ld6bHCCPkb9LzbWowr2Ca /r6l7dd6zd5DnnUyNuQQii57yT99mrBlewYi7B4oLWa3fPGxR0K50PHzt9yWMIC+r7IG FmEyVgSRWX6Z4FfCZFlAvd8jeUsEVlwTCaAeXa1//qbeD9I+e4kFsdIOjO1iKdR6Yo9P xOaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si1872107edq.370.2020.09.07.04.50.48; Mon, 07 Sep 2020 04:51:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729156AbgIGLtH (ORCPT + 99 others); Mon, 7 Sep 2020 07:49:07 -0400 Received: from mga01.intel.com ([192.55.52.88]:18497 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729109AbgIGLq3 (ORCPT ); Mon, 7 Sep 2020 07:46:29 -0400 IronPort-SDR: u4KohBcvYcG9RbkmPJ3ozmpfiYzDMsjWNloDyxd9KR012bFb7MH/gw1Y3NYSAU8MddCr0BTx8J BVlYhcWaDl4A== X-IronPort-AV: E=McAfee;i="6000,8403,9736"; a="176046003" X-IronPort-AV: E=Sophos;i="5.76,401,1592895600"; d="scan'208";a="176046003" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2020 04:45:57 -0700 IronPort-SDR: 2c5/thtWfGsvF/VAAo2KUZsh1d3mpudhrE42tnry+4xfAzgIgzUSc25JQ7BeBaa6gPcu27O6tp kRAMhOH3CdHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,401,1592895600"; d="scan'208";a="333141071" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga008.jf.intel.com with ESMTP; 07 Sep 2020 04:45:54 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1kFFap-00EwG6-Fz; Mon, 07 Sep 2020 14:45:51 +0300 Date: Mon, 7 Sep 2020 14:45:51 +0300 From: Andy Shevchenko To: Bartosz Golaszewski Cc: Bartosz Golaszewski , Linus Walleij , Jonathan Corbet , Mika Westerberg , Kent Gibson , linux-gpio , linux-doc , LKML , ACPI Devel Maling List Subject: Re: [PATCH 03/23] lib: uaccess: provide getline_from_user() Message-ID: <20200907114551.GV1891694@smile.fi.intel.com> References: <20200904154547.3836-1-brgl@bgdev.pl> <20200904154547.3836-4-brgl@bgdev.pl> <20200904163517.GW1891694@smile.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 07, 2020 at 12:28:05PM +0200, Bartosz Golaszewski wrote: > On Mon, Sep 7, 2020 at 12:19 PM Andy Shevchenko > wrote: > > > > On Mon, Sep 7, 2020 at 1:05 PM Bartosz Golaszewski > > wrote: > > > On Fri, Sep 4, 2020 at 6:35 PM Andy Shevchenko > > > wrote: > > > > On Fri, Sep 04, 2020 at 05:45:27PM +0200, Bartosz Golaszewski wrote: > > > > > From: Bartosz Golaszewski > > > > > > Doesn't mm/util.c provides us something like this? > > > > strndup_user()? > > > > > > > > > > Yes, there's both strndup_user() as well as strncpy_from_user(). The > > > problem is that they rely on the strings being NULL-terminated. This > > > is not guaranteed for debugfs file_operations write callbacks. We need > > > some helper that takes the minimum of bytes provided by userspace and > > > the buffer size and figure out how many bytes to actually copy IMO. > > > > Wouldn't this [1] approach work? > > > > [1]: https://elixir.bootlin.com/linux/v5.9-rc3/source/arch/x86/kernel/cpu/mtrr/if.c#L93 > > > > Sure, but this is pretty much what I do in getline_from_user(). If > anything we should port mtrr_write() to using getline_from_user() once > it's available upstream, no? But you may provide getline_from_user() as inline in the same header where strncpy_from_user() is declared. It will be like 3 LOCs? -- With Best Regards, Andy Shevchenko