Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3156698pxk; Mon, 7 Sep 2020 05:03:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwupMY/uFMxjSP9vyiOdGgAx0wtawapxD5GIJ1+TRq3fQeM7yHUII/BdNRx5R7corkoF0Ug X-Received: by 2002:a17:906:9718:: with SMTP id k24mr19327082ejx.365.1599480202456; Mon, 07 Sep 2020 05:03:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599480202; cv=none; d=google.com; s=arc-20160816; b=qDGytp69RCnI7LvgqBFl3zSFMR5Q+hpFKFwwSEfSAcsjr6PhV6mrCue3g5Y9mQRTGW ocbXX+OtZrQ0p2LwqulmzEFbLIRUurVTTI7Ugms6Gb7W/l6s6SUSnIN99nRuUl/JyYsZ XF/OIM3W8DJXDqZDXz3AbyddRyja50l4H15p/rA7PlyElWmzphSJndpMQLfpYi1dSFkC HOm6dl50GhZSw/ShLcD0HADbsarro02cDCENYMbwEJ47yi7f852OjGJirKz/NLsRJLaQ q6bfdhYsG8SNXo8h76gXtbKEq+VS6RWof0cU4mAf5fH7wkKTznE/QNhIY3zgxZvwTk6i VYNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=wuNizNJ6r33hGWcPZZ5Js9EvkLS7jqpgkks6hNUFhPA=; b=oQL4hc/CJhOHRHcyGOlHoQDCTh7LSzjsMHZoEbXpXddT1+YS+yuFlTIlHYLMGlEzyl N71nD7GTPtWZSEvOTZV9v4vhhJ/nGmo/vXHHBOuw01c+W1lICYoRwUgqnEujiMeKMOp5 zHo+dqT+N8H9kXr3h6JgSXyLIqyrYAiwuyDNnn77tpcivniwQPA94aPfAPLA7Um672Ez 11rtsxuDMS/bIm3Ju421m7n/4q1Yalc2naT9I+KiYYDWK0iyIqmWkVZzUpY4IhKPU4jS 9Q89d4OzRLa+1ZfdUr1LtWxabitxcTm1CKHByTc0G4n83BT/VorF4YMPAKCjpVa4ELet AeMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=hmebUBbh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u15si9331332ejx.239.2020.09.07.05.02.59; Mon, 07 Sep 2020 05:03:22 -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; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=hmebUBbh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729042AbgIGMB5 (ORCPT + 99 others); Mon, 7 Sep 2020 08:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728459AbgIGL6B (ORCPT ); Mon, 7 Sep 2020 07:58:01 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0C9EC061574 for ; Mon, 7 Sep 2020 04:58:00 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id lo4so17877349ejb.8 for ; Mon, 07 Sep 2020 04:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wuNizNJ6r33hGWcPZZ5Js9EvkLS7jqpgkks6hNUFhPA=; b=hmebUBbhYKYjFws6DyXQmTbngYhFOaYQZwILguT9XWAVUF34AkgUhucL2X83PWUz3B O1WILkR2ETVUXAQHnmzJ3T9TOE+BkUDSmBuGiSgS6Sp5sXm97ReIQwhxpvCiXKPYPxwl KmYDUbghifyxlWCuz0FXLZhOP8/WaaBorOGjV0OaPvsg96+OJ9dsVtYXdMjZspZn4Z+G WnnS+fADtLeE8tiSTQ84zNr/1dJ4qnng0gSHl9HGGeZ9NF0QDxScyDw1+vyr5LVHsdpY BHAzbAA6yL4HFjfbQwk6s5dWCoCOvVuf2PpqzV88RAQnteHZ8G9AZHlHpHrnxdKi5Hax Gnmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wuNizNJ6r33hGWcPZZ5Js9EvkLS7jqpgkks6hNUFhPA=; b=j+VeLVdvk3AnnYWbhECPtp9NZocBNcBpj83kwT2k4bPJDTP83a+mk6eRUw5+HYj9pH WBWq0Y+1mIds/E7RPgWqdmjqPFOhjduZPrUsKcCuUORvlhrBnZv8H1ncWwWvn0LZe4to wVDwxSopxAi7hUlUi+8crg4MUVQPOdQOV6W2m97o5WqPWfB/7OLkOp1wxWKcfC6W4+fO hQzpf969cZcCAbjL700lwHMdKIrPGAKSvoWrhIqz1jho5AL3zLlxBGWEowEdawA4QAX/ gK0h6Yi7wWe7aogjBFQiX4v2NJdzdQbAiAWyb9wOUq6h0O429tGnQZvKUM3yWfKQgsV4 jF8w== X-Gm-Message-State: AOAM532PYUVBu8OWzdTtYvth03wCORsOXD5HCBuN7dgqKE7GDLJcz2xT dTBvkZkcafKbbQKDzzZCcygWkIfRcRmfxpyDJJ/LzA== X-Received: by 2002:a17:906:174e:: with SMTP id d14mr3022559eje.225.1599479879319; Mon, 07 Sep 2020 04:57:59 -0700 (PDT) MIME-Version: 1.0 References: <20200904154547.3836-1-brgl@bgdev.pl> <20200904154547.3836-4-brgl@bgdev.pl> <20200904163517.GW1891694@smile.fi.intel.com> <20200907114551.GV1891694@smile.fi.intel.com> In-Reply-To: <20200907114551.GV1891694@smile.fi.intel.com> From: Bartosz Golaszewski Date: Mon, 7 Sep 2020 13:57:48 +0200 Message-ID: Subject: Re: [PATCH 03/23] lib: uaccess: provide getline_from_user() To: Andy Shevchenko Cc: Bartosz Golaszewski , Linus Walleij , Jonathan Corbet , Mika Westerberg , Kent Gibson , linux-gpio , linux-doc , LKML , ACPI Devel Maling List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 7, 2020 at 1:45 PM Andy Shevchenko wrote: > > 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? > May be more than that. I'll see what I can do. Bart