Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp362189ybl; Fri, 24 Jan 2020 01:38:58 -0800 (PST) X-Google-Smtp-Source: APXvYqxVy6WC2tLaZpwCUIppyJYl8wMCgryqFxpMNiCMQ+O+RWssCDGbMV4jmNc7gJp3TsY3jFAa X-Received: by 2002:a9d:1928:: with SMTP id j40mr2120241ota.68.1579858738168; Fri, 24 Jan 2020 01:38:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579858738; cv=none; d=google.com; s=arc-20160816; b=DVYPNS5gi5tcWU4iLrJPn/szWX3rSroN+/qpuoebZqWduvXdY+7bmkZeiYh1aDUznX 3yvTPUNfztGo7SFfEy+EYV8cj9OL68TAlPw2AbVv8dR4hM+chW2CGpenhBl8YllewdAu zXQwQOPniiYiV4brXYVnsHl/uSd+VJSzkvejSTGnl3qBwn+xmf68jYa+EeYY5mnJwHZ9 T3UXXOlQJ7n5wbTRo++sjb3QLbMYE5+hMxjwWpaiA4EbI7+0KHsSxRh3oAyhiMxCEhs4 9bkYSMJ0EK4hM9RxuDKhUZHdASeDwq+/GyCC8zOzoMXi1+EUcfbtf4n366wJGQCQitep 9s8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:dkim-signature; bh=QugXP++tX2QdF2BlYh+oWt5d/1+WjAi+1riPy4DfzEI=; b=QfEuzE5U4Kyq3Tpgh1YPwB11sd6aPIsHtVLD9qZUlVUop+4rjwjBxTDkD8SiUhH0X7 sKwpX1sE8DxOTvq2dvFv2cU51PlXUBfyz5XpnTvln+EquBw7DgK2jhr4psh441rKVqEu hKLUJGXsiBwEfuBu1BxF/ZkZClB9dnMFYZYnRo/FvLCcU7bFA31NTHXiFvo+VBgtozKf LYQIsS4lmw9ZMeIzei9yIQ5Gq2WzVuQGepp2DZ5Lxb5tPs7YsboSjsxpAqs4QLla4RUv y+TuiHv7F1AQYHD9FaeFj6Py+1Ll2ighR4KKvoeLy8Xv6W+KF+4uv+cuwX6MtyQI/tp1 Uffg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="XsaJ/DyU"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l204si2104040oif.261.2020.01.24.01.38.46; Fri, 24 Jan 2020 01:38:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="XsaJ/DyU"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731081AbgAXJhc (ORCPT + 99 others); Fri, 24 Jan 2020 04:37:32 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:37559 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731041AbgAXJhb (ORCPT ); Fri, 24 Jan 2020 04:37:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579858650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=QugXP++tX2QdF2BlYh+oWt5d/1+WjAi+1riPy4DfzEI=; b=XsaJ/DyUjXSvnPyZs3/fZtppGSEM7b3lT1cvKYUIru3cDpcrzpDnXAfiojLTe1YBJTRI07 z7ntmACyGv+TPErmjIatZyXyydTJlWOlkZPfIbNfirtljKqU8vr29eAcwuN7SoeD3tovWQ nt4HQjhGQoj8WByAKenbu8yMYJAZkg0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-157-5EmjIe8IMX62BrAeobcsDg-1; Fri, 24 Jan 2020 04:37:26 -0500 X-MC-Unique: 5EmjIe8IMX62BrAeobcsDg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F306DB23; Fri, 24 Jan 2020 09:37:25 +0000 (UTC) Received: from oldenburg2.str.redhat.com (dhcp-192-227.str.redhat.com [10.33.192.227]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 253A210016EB; Fri, 24 Jan 2020 09:37:23 +0000 (UTC) From: Florian Weimer To: Rich Felker Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Alexander Viro Subject: Re: Proposal to fix pwrite with O_APPEND via pwritev2 flag References: <20200124000243.GA12112@brightrain.aerifal.cx> Date: Fri, 24 Jan 2020 10:37:22 +0100 In-Reply-To: <20200124000243.GA12112@brightrain.aerifal.cx> (Rich Felker's message of "Thu, 23 Jan 2020 19:02:43 -0500") Message-ID: <87d0b942lp.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Rich Felker: > There's a longstanding unfixable (due to API stability) bug in the > pwrite syscall: > > http://man7.org/linux/man-pages/man2/pwrite.2.html#BUGS > > whereby it wrongly honors O_APPEND if set, ignoring the caller-passed > offset. Now that there's a pwritev2 syscall that takes a flags > argument, it's possible to fix this without breaking stability by > adding a new RWF_NOAPPEND flag, which callers that want the fixed > behavior can then pass. > > I have a completely untested patch to add such a flag, but would like > to get a feel for whether the concept is acceptable before putting > time into testing it. If so, I'll submit this as a proper patch with > detailed commit message etc. Draft is below. Has this come up before? I had already written a test case and it turns out that an O_APPEND descriptor does not protect the previously written data in the file: openat(AT_FDCWD, "/tmp/append-truncateuoRexJ", O_RDWR|O_CREAT|O_EXCL, 0600) = 3 write(3, "@", 1) = 1 close(3) = 0 openat(AT_FDCWD, "/tmp/append-truncateuoRexJ", O_WRONLY|O_APPEND) = 3 ftruncate(3, 0) = 0 So at least it looks like there is no security issue in adding a RWF_NOAPPEND flag. Thanks, Florian