Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp268948ybg; Tue, 28 Jul 2020 05:43:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCos8h/6/r+6DQEKCiul35riSUeIy6uCg/a3avy+kyC26nvyofJpelaHWC8OQRCSEBaHkH X-Received: by 2002:a17:906:fc26:: with SMTP id ov38mr15134608ejb.99.1595940204025; Tue, 28 Jul 2020 05:43:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595940204; cv=none; d=google.com; s=arc-20160816; b=aQpiBHy1d/a33xbcnqFn0lbxMWh2lm/bVs/cV7OzTzJCMctQ4w7qYEWIWCKDITdnyA BFcFNz6b7b5/yKRFQPIcTPH8D6TN/92HdGAkUrJmVJCGRhmuyMcQlwEOTDCFt74pqFPx DwVRAF28aLn72GDUag9ab/6g7HsYGg8h/JmZa32+yVw5CjNiYIwqEyu1cDILSzI6sTZ9 63FkoZisgeYFg0d0+uPg0WpyyL3xC1pITJyJLz4zFzB9tdJ3g2SU9STu3km0LDxBIyp5 ZZnitEi77VvAcDVl/ZbIUwz8UzD+J4r5UBb40lRenXO2fE1twIKIEn+z9VvEdrlAPvDL FJvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=tUtoJvG/chtuXtvBDDaSMmx9rYyXFF5PpGoV5MhO8ok=; b=dOBJPpBwMaEqfqUkKlIuP5NAVky0BJW16m6iuAvvZNQ2V8qeW1UD3ZQ5+3O5gmlAbd cMsbqioPQzDqVFehqmcqtdTXMXMY2WAdrd78eR3ScKvDrxs3MpE1O5Rj1Bne3e10yJSC RctS9nmwt7H7oHda+I9bJTfzjcWkKBtedzgTn3vphlHJ2qS8X91abtjNLJEc0gALVYVz k4jpUKbLxjKE7aziLQpNX5fNuVUxYtt2ev5l7TNVmcxfSWJ7EwE2dNYTzAzw4iiTWEwy j+kxBP646mJK86PykDHyuYQHppGSpK1Ofw4FMDvEXSmTvlFDXwDnySmbI80qbYsFmLrQ KPQQ== 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 b24si2798667eje.471.2020.07.28.05.43.01; Tue, 28 Jul 2020 05:43:24 -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 S1729848AbgG1Mlk (ORCPT + 99 others); Tue, 28 Jul 2020 08:41:40 -0400 Received: from 107-174-27-60-host.colocrossing.com ([107.174.27.60]:35556 "EHLO ozlabs.ru" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1729379AbgG1Mlj (ORCPT ); Tue, 28 Jul 2020 08:41:39 -0400 Received: from fstn1-p1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id EDB48AE800ED; Tue, 28 Jul 2020 08:38:56 -0400 (EDT) From: Alexey Kardashevskiy To: v9fs-developer@lists.sourceforge.net Cc: Alexey Kardashevskiy , "David S. Miller" , Dominique Martinet , Eric Van Hensbergen , Jakub Kicinski , Latchesar Ionkov , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH kernel] 9p/trans_fd: Check file mode at opening Date: Tue, 28 Jul 2020 22:41:29 +1000 Message-Id: <20200728124129.130856-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. This adds file mode checking in p9_fd_open; this returns -EBADF to preserve the original behavior. Found by syzkaller. Signed-off-by: Alexey Kardashevskiy --- net/9p/trans_fd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index 13cd683a658a..62cdfbd01f0a 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -797,6 +797,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts) static int p9_fd_open(struct p9_client *client, int rfd, int wfd) { + bool perm; struct p9_trans_fd *ts = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); if (!ts) @@ -804,12 +805,16 @@ static int p9_fd_open(struct p9_client *client, int rfd, int wfd) ts->rd = fget(rfd); ts->wr = fget(wfd); - if (!ts->rd || !ts->wr) { + perm = ts->rd && (ts->rd->f_mode & FMODE_READ) && + ts->wr && (ts->wr->f_mode & FMODE_WRITE); + if (!ts->rd || !ts->wr || !perm) { if (ts->rd) fput(ts->rd); if (ts->wr) fput(ts->wr); kfree(ts); + if (!perm) + return -EBADF; return -EIO; } -- 2.17.1