Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1690537iog; Thu, 16 Jun 2022 11:35:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t9BYJGDAv5DqW4GvALY4cyMI/+oah6w6WvbKoSpqYkKnun3LfFxU/dLABGwy9jeehH5pb8 X-Received: by 2002:a17:906:5053:b0:70d:a0cc:b3fd with SMTP id e19-20020a170906505300b0070da0ccb3fdmr5566684ejk.162.1655404531171; Thu, 16 Jun 2022 11:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655404531; cv=none; d=google.com; s=arc-20160816; b=cXWvQX8DRrGXxJpT8GiqWdrnKp9IZHt9AR3HdxhJmrhUoa9xOEr/mlN8NNOf/wCmuk pwAFjRKAa6QeZu37rUoENFMJWqvSYzyYkvpT/jKKnJe6ou/e1VhkYYQnAodsHXSeTS6N C7dCdKWQcUqLdR9lkq4IbneyPRunkDzTCoTMFlv+8RZfIt5sqsV2va7QppcfVbaPpROK l8khcfMOIf6Uot2uUAVUKZfpgesdRI+9oYUuvl2WtiZtIkluaJxiOUebudzTBh63XA9N wC2M3OqhfGbSAKnEMEdRdIVhPFLAPAboUco0dUOmNzuksffIKXl5oYMtd75WJVGjhEkg xdIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:cc:to:subject:date:from :dkim-signature; bh=xm94cFRpLBeZoS4MkJUmpD9ccv8vD46ilbV91YuAu+4=; b=CRpDpquPqTPDMcN11my+NNFb+XItik+KOo3fMHjwI3RL2k+x9eRM2iEM3WCLInlgMg 9TCcmAmdQegIOcfLk0y7z1pOXlNxxxF1B5+Qq8ts663YNrjVAqq55KbR0BQ9r/PKST8a joxRhDHanzBGMrrIURXQOVGbEDiIo0Bt/mQTWjw9iOBTsfUjpJQfxl1w0NWEnGBkoKCm +lqXACXpUCRexzP8BZfKnqb2rlCJFWsAZUaY3FwEIlsOAC2oaoPtkjuKTxxakSRvpqv9 RSamYQYub7RbH/1qE9Tlo4YByWnnHJW/mVOVjgKAJA0Wkty8xvhqXQ9em9NUEcoGkeze 1mjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crudebyte.com header.s=lizzy header.b=gTOEsaiO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=crudebyte.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh12-20020a1709076e8c00b00718d1200d74si766439ejc.488.2022.06.16.11.35.05; Thu, 16 Jun 2022 11:35:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@crudebyte.com header.s=lizzy header.b=gTOEsaiO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=crudebyte.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377297AbiFPSJl (ORCPT + 99 others); Thu, 16 Jun 2022 14:09:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233838AbiFPSJk (ORCPT ); Thu, 16 Jun 2022 14:09:40 -0400 X-Greylist: delayed 2527 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 16 Jun 2022 11:09:37 PDT Received: from lizzy.crudebyte.com (lizzy.crudebyte.com [91.194.90.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 905574EDFE for ; Thu, 16 Jun 2022 11:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Message-Id:Cc:To:Subject:Date:From:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Content-ID: Content-Description; bh=xm94cFRpLBeZoS4MkJUmpD9ccv8vD46ilbV91YuAu+4=; b=gTOEs aiOGh59u3PyvQFNqRbDXK5rbrTl2/02z3Yf6YAwDFqMRHfBdGjmFBUeekgmLJpcOMtVj+qA44ha/V 7PY/1Dz0A9TFKsFgk7h7k79/VnE4JUHQ3nk9olcwnmy6b+AJwBT83U7v9mUC79w4h3SakvKiFbQ3y NfOKHHu55Clmzy9yEkoHJ/zRowQJLaeZcKRuJjQUxZfS15tI0w2bT6IqMtTpkuMg8H55//Gh8Mkdj rjdwgolVWqIsDBpTQeSdUfloljJkEdjMTuTEAnrVdPLOCBmEuIwzQ+a4jCIjzHjpzC6yrxSDUiCyC Zszg3Nxd9UpyhBTNY3dT1XFAn3dUA==; From: Christian Schoenebeck Date: Thu, 16 Jun 2022 19:09:42 +0200 Subject: [PATCH] net/9p: show warning on Tread/Twrite if wrong file mode To: Dominique Martinet Cc: v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Eric Van Hensbergen , Latchesar Ionkov , David Howells Message-Id: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The netfs changes (eb497943fa21) introduced cases where 'Tread' was sent to 9p server on a fid that was opened in write-only file mode. It took some time to find the cause of the symptoms observed (EBADF errors in user space apps). Add warnings to detect such issues easier in future. Signed-off-by: Christian Schoenebeck Link: https://lore.kernel.org/netdev/3645230.Tf70N6zClz@silver/ --- As requested by Dominique, here a clean version of my previous EBADF trap code to be merged. Dominique, if you already have an equivalent patch queued, then just go ahead. I don't mind. I'm currently testing your EBADF fix patch and the discussed, slightly adjusted versions. Looking good so far, but I'll report back later on. net/9p/client.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/9p/client.c b/net/9p/client.c index 8bba0d9cf975..05dead12702d 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -1555,6 +1555,8 @@ p9_client_read(struct p9_fid *fid, u64 offset, struct iov_iter *to, int *err) int total = 0; *err = 0; + WARN_ON((fid->mode & O_ACCMODE) == O_WRONLY); + while (iov_iter_count(to)) { int count; @@ -1648,6 +1650,8 @@ p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err) p9_debug(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %zd\n", fid->fid, offset, iov_iter_count(from)); + WARN_ON((fid->mode & O_ACCMODE) == O_RDONLY); + while (iov_iter_count(from)) { int count = iov_iter_count(from); int rsize = fid->iounit; -- 2.30.2