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 X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E8F9C433E0 for ; Fri, 19 Mar 2021 21:13:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B948461980 for ; Fri, 19 Mar 2021 21:13:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230092AbhCSVM3 (ORCPT ); Fri, 19 Mar 2021 17:12:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229990AbhCSVMC (ORCPT ); Fri, 19 Mar 2021 17:12:02 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48AC8C061761 for ; Fri, 19 Mar 2021 14:12:02 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id f2-20020a17090a4a82b02900c67bf8dc69so7319174pjh.1 for ; Fri, 19 Mar 2021 14:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=bLNry3ZXHQ9tHu+On0bkjiCkpapr1pSIrFsTvvsflEc=; b=1n0mkAQFvc10rNMQoLM9YVKLE+ZBv2SCxreZVqm0WfGygljeO+ZRmjcTdUMMLhNjB4 Gi9g41nDX8BOK97qf6iUs0zF3ZCAQXoRtNyPkL1qM36LklJ1WM0Lo7JCyIPHXj5eF0u1 JojeCjZc7pbP/XHtf0DO9W+UdwEqN9n8x/jNAd5xP2cFriIInfigeo1h3/1T8FkHIFw+ X6YXB3TaCZbo3iV0IwmBxTbBYKTtwOJasCsj08Ivlz5gDE7HAkj6mxpnwCETT7sJsW9Z ygkepDZ9z1WkRAMbZVQBMNnARQyEockssNtkAwOk1gAJIyRF849x5PNPl3DMM3foMGkT WTdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=bLNry3ZXHQ9tHu+On0bkjiCkpapr1pSIrFsTvvsflEc=; b=hY42IN2jAIS2Ab0jpIM8W5KV4Qkwm2exnTqWjwXfZBr4l0chGWhIUHLzzZ+fgUX4AN cHs/G7RXBOFtUEx5zrCujWuKvToT3xwNy2OBY/VEBdjyYbR52M1nrQEMTwW+zSSjkAd6 CN4vym/HUv77nQm5sGiF16PGkXQCqNbVp2DlCRwQOdIEkUDH8OHLxN0xaM248edRsTuO gINfGmot4tDw8lsk0zBALMvrhz8IHIlvbv4YAgr4bI3Doghc9WE1OSa6eB94U96PUgMU f13aeEXjndJzdCuyqtaUayIQeep06cr/9AYFybcufc2IPGYmEcUA2WYMRZ3pTL9uvMiN RHBg== X-Gm-Message-State: AOAM532jgtDyTfRjnYzkFE4PHXJ5ftJFqUxM+g4y32DDiM2RWPmtYFIr VbWSjfPAnAhXR3FAA5pfKeUlPw== X-Google-Smtp-Source: ABdhPJxX0o7uVOSoY7PrQ1YTqR+hEYKRyX9j2fhPjFZHpCBlCJQOqbd4pTvH/e1v2Ab7pYPtnWSwyw== X-Received: by 2002:a17:90a:8505:: with SMTP id l5mr437793pjn.100.1616188321497; Fri, 19 Mar 2021 14:12:01 -0700 (PDT) Received: from relinquished.localdomain ([2620:10d:c090:400::5:9ec6]) by smtp.gmail.com with ESMTPSA id c128sm6280833pfc.76.2021.03.19.14.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 14:11:59 -0700 (PDT) Date: Fri, 19 Mar 2021 14:11:56 -0700 From: Omar Sandoval To: Linus Torvalds Cc: Josef Bacik , linux-fsdevel , linux-btrfs , Al Viro , Christoph Hellwig , Dave Chinner , Jann Horn , Amir Goldstein , Aleksa Sarai , Linux API , Kernel Team Subject: Re: [PATCH v8 00/10] fs: interface for directly reading/writing compressed data Message-ID: References: <8f741746-fd7f-c81a-3cdf-fb81aeea34b5@toxicpanda.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-api@vger.kernel.org On Fri, Mar 19, 2021 at 01:55:18PM -0700, Linus Torvalds wrote: > On Fri, Mar 19, 2021 at 1:27 PM Omar Sandoval wrote: > > > > For RWF_ENCODED, iov[0] is always used as the entirety of the struct. I > > made the helper more generic to support other use cases, but if that's > > the main objection I can easily make it specifically use iov[0]. > > Honestly, with new interfaces, I'd prefer to always start off as > limited as possible. > > And read/write is not very limited (but O_ALLOW_ENCODED and > RWF_ENCODED at least helps with the "fool suid program to do it"). But > at least we could make sure that the structure then has to be as > strict as humanly possible. > > So it's not so much a "main objection" as more about trying to make > the rules stricter in the hope that that at least makes only one very > particular way of doing things valid. I'd hate for user space to start > 'streaming" struct data. After spending a few minutes trying to simplify copy_struct_from_iter(), it's honestly easier to just use the iterate_all_kinds() craziness than open coding it to only operate on iov[0]. But that's an implementation detail, and we can trivially make the interface stricter: diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 395ca89e5d9b..41b6b0325d18 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -969,9 +969,9 @@ EXPORT_SYMBOL(copy_page_from_iter); * On success, the iterator is advanced @usize bytes. On error, the iterator is * not advanced. */ -int copy_struct_from_iter(void *dst, size_t ksize, struct iov_iter *i, - size_t usize) +int copy_struct_from_iter(void *dst, size_t ksize, struct iov_iter *i) { + size_t usize = iov_iter_single_seg_count(i); if (usize <= ksize) { if (!copy_from_iter_full(dst, usize, i)) return -EFAULT; I.e., the size of the userspace structure is always the remaining size of the current segment. Maybe we can even throw in a check that we're either at the beginning of the current segment or the very beginning of the whole iter, what do you think? (Again, this is what RWF_ENCODED already does, it was just easier to write copy_struct_from_iter() more generically). > > > Also I see references to the man-page, but honestly, that's not how > > > the kernel UAPI should be defined ("just read the man-page"), plus I > > > refuse to live in the 70's, and consider troff to be an atrocious > > > format. > > > > No disagreement here, troff is horrible to read. > > > > > So make the UAPI explanation for this horror be in a legible format > > > that is actually part of the kernel so that I can read what the intent > > > is, instead of having to decode hieroglypics. > > > > I didn't want to document the UAPI in two places that would need to be > > kept in sync > > Honestly, I would suggest that nobody ever write troff format stuff. > I don't think it supports UTF-8 properly, for example, which means > that you can't even give credit to people properly etc. > > RST isn't perfect, but at least it's human-legible, and it's obviously > what we're encouraging for kernel use. You can use rst2man to convert > to bad formats (and yes, you might lose something in the translation, > eg proper names etc). It looks like there's precedent for man pages being generated from the kernel documentation [1], so I'll try that. 1: https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=53666f6c30451cde022f65d35a8d448f5a7132ba > Almost anything else(*) is better than troff. But at least I can read > the formatted version. > > Linus > > (*) With the possible exception of "info" files. Now *there* is a > truly pointless format maximally designed to make it inconvenient for > users.