Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp893651ybg; Tue, 28 Jul 2020 23:56:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuJvfilz5IAB9uJMXyX/cs52frLZ2sIjyPOmYPiwcuPcojmFwsXWyRbs4BrsCr1UQOyokA X-Received: by 2002:a05:6402:1d97:: with SMTP id dk23mr30361167edb.1.1596005770737; Tue, 28 Jul 2020 23:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596005770; cv=none; d=google.com; s=arc-20160816; b=0B3fNDKblgdLA10wammtwb+tRFhZ18rWVUea9bLYgALOLfM4YNpIDnZvVndCibpWMV vO0s1XicDtokIpN4AWUM3NJPZSVIVOpLs69+InaInFCUDVd2W+z98pVPaJOfL71ADwGA 4G8/wXLpoUOqipdJytbEHNqSl21BE7t2PeUabjr+k/wPXpUyR1LfVdZQ6wsI7YplJ5t5 xrSmblADlo7uVWMASA37xdLK5RwbsuPr3mRwzuHfOA3Oj2u696EGkLHTi+V4ojHbUqkw 2Av8ouwBbH/f22K60mh3tr0x3MpAdHtOQNtik7TvlGtIbmRWuJAZNqidB+o9xPJEA7Jo sQUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=f885jt7QdnT93i9atfMci2ZnAhY7d2QZteFvtyNfEuo=; b=QXJOKaYRO6Inlaa91KLiJs/XexreyjwZAzOIpRIuuSVdNBDB0NkY4ZsrbBUfJzAEoL 8N0NgHpB74tr0c2zZR4+dg3wfmis0CkSumrICPCWK4tj76UX8R0M8mtNK7nW5caQCBlC khS/PJ01VElf4yKGORkLgjKJlY2AVa2/I29vCq0Wo5HIKFvwMuqSQD1xtKTNvoqcRpDO EnMFQVOMpfwcPtJgoMuB3G9+hdI+JfHy9OywsN4GTraoZVIa8S40IVhsnNeItaqeaifE +77rmFk5Y8cmZNbv62/kiXItEXz/Bnh5hwMObrEtCHWruya27tYYgONatqSLBMT3tSkj yEyQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce7si721332edb.85.2020.07.28.23.55.49; Tue, 28 Jul 2020 23:56: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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727078AbgG2Gz1 (ORCPT + 99 others); Wed, 29 Jul 2020 02:55:27 -0400 Received: from 4.mo179.mail-out.ovh.net ([46.105.36.149]:42408 "EHLO 4.mo179.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbgG2Gz0 (ORCPT ); Wed, 29 Jul 2020 02:55:26 -0400 Received: from player711.ha.ovh.net (unknown [10.108.42.75]) by mo179.mail-out.ovh.net (Postfix) with ESMTP id 694B4173B78 for ; Wed, 29 Jul 2020 08:38:32 +0200 (CEST) Received: from kaod.org (lns-bzn-46-82-253-208-248.adsl.proxad.net [82.253.208.248]) (Authenticated sender: groug@kaod.org) by player711.ha.ovh.net (Postfix) with ESMTPSA id AB08514A1AD8F; Wed, 29 Jul 2020 06:38:23 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-105G006896df29f-f4f3-493b-ab9a-d0c6f23d8bcf, A40F6FE0CFFE28C23AB4AFBB3D5D665E11D39731) smtp.auth=groug@kaod.org Date: Wed, 29 Jul 2020 08:38:22 +0200 From: Greg Kurz To: Dominique Martinet Cc: Alexey Kardashevskiy , v9fs-developer@lists.sourceforge.net, Latchesar Ionkov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Van Hensbergen , Jakub Kicinski , "David S. Miller" Subject: Re: [V9fs-developer] [PATCH kernel] 9p/trans_fd: Check file mode at opening Message-ID: <20200729083822.66e165ed@bahia.lan> In-Reply-To: <20200729061449.GA19682@nautica> References: <20200728124129.130856-1-aik@ozlabs.ru> <20200728194235.52660c08@bahia.lan> <20200729061449.GA19682@nautica> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 1830713248816142592 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduiedrieefgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepfffhvffukfgjfhfogggtgfesthejredtredtvdenucfhrhhomhepifhrvghgucfmuhhriicuoehgrhhouhhgsehkrghougdrohhrgheqnecuggftrfgrthhtvghrnhepveehieetvdettdfhiefhueetheekheejgfdtvddthfffuefgueduvefgveeijeegnecuffhomhgrihhnpehophgvnhhgrhhouhhprdhorhhgnecukfhppedtrddtrddtrddtpdekvddrvdehfedrvddtkedrvdegkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehplhgrhigvrhejuddurdhhrgdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomhepghhrohhugheskhgrohgurdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Jul 2020 08:14:49 +0200 Dominique Martinet wrote: > Greg Kurz wrote on Tue, Jul 28, 2020: > > > The "fd" transport layer uses 2 file descriptors passed externally > > > and calls kernel_write()/kernel_read() on these. If files were opened > > > without FMODE_WRITE/FMODE_READ, WARN_ON_ONCE() will fire. > > There already is a fix in linux-next as a39c46067c84 ("net/9p: validate > fds in p9_fd_open") > > > > This adds file mode checking in p9_fd_open; this returns -EBADF to > > > preserve the original behavior. > > > > So this would cause open() to fail with EBADF, which might look a bit Oops... this seems to rather end up in mount(). :) > > weird to userspace since it didn't pass an fd... Is this to have a > > different error than -EIO that is returned when either rfd or wfd > > doesn't point to an open file descriptor ? If yes, why do we care ? > > FWIW the solution taken just returns EIO as it would if an invalid fd > was given, but since it did pass an fd EBADF actually makes sense to me? > POSIX says: https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html [EBADF] Bad file descriptor. A file descriptor argument is out of range, refers to no open file, or a read (write) request is made to a file that is only open for writing (reading). It seems that EBADF would be appropriate for both the existing and the new error path. > However to the second question I'm not sure I care :) > > > > Found by syzkaller. > > I'm starting to understand where David comment came from the other day, > I guess it's still time to change my mind and submit to linus now I've > had time to test it... >