From patchwork Mon Dec 18 18:56:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 13497410 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB77D5D747; Mon, 18 Dec 2023 18:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6d267461249so2040410b3a.3; Mon, 18 Dec 2023 10:57:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702925833; x=1703530633; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zk+B25u0to8P/Oq1qU35ckd3D9fSBALYYrjdMtzmKns=; b=fWV1EMds4uUz9jz4BjRL4/Rg58ya8oojbdQowvDe0p6BrwqS7fVVYhGSzwNmCJYJdc Vzcx+9wx7PtjEOwp05NkZbYD+vmkNK+yYT2XSS/FtyitubI3dwjYW0+oQZtLJQlZjr5v Xx++o+YbYiy6rbe9P4CzwTQuE3J9+gQKstJEg1TJ7CLz3k6QUMly9Ti2OFgmmrRd3EkH g301lty6Cq2k+xwpCqhi6608M8SV/v3DqA+eWUo3Yuf3M1NToAl0Hjik889PPIv8Xaxm lDmeigvUvTMIlmmCGD3LRCaWAw/9PVWa0oqs6Sat1zJ36QQ5xgjAWJjJmMGFkiP7YDE6 lylQ== X-Gm-Message-State: AOJu0YwDui2wiNQLAsOSzUxph/of/OUeB5BCnY0gngD39fSG8DFB7w0m E/Sdc1BsOc6TwTMPspKWOL8= X-Google-Smtp-Source: AGHT+IHyiBuR0yBmoYLdMtVNfdHUrQZPApFDq4vaRo9LcyYVf/nopB5q0VHRnKGqdqTysnotE5kdxw== X-Received: by 2002:a05:6a20:8b03:b0:18f:97c:5ba0 with SMTP id l3-20020a056a208b0300b0018f097c5ba0mr6073141pzh.110.1702925833038; Mon, 18 Dec 2023 10:57:13 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:e67:7ba6:36a9:8cd5]) by smtp.gmail.com with ESMTPSA id n20-20020a056a0007d400b006d45707d8edsm3918397pfu.7.2023.12.18.10.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 10:57:12 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig , Daejun Park , Kanchan Joshi , Bart Van Assche , Jeff Layton , Chuck Lever , Stephen Rothwell , Alexander Viro , Christian Brauner Subject: [PATCH v7 01/19] fs: Fix rw_hint validation Date: Mon, 18 Dec 2023 10:56:24 -0800 Message-ID: <20231218185705.2002516-2-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231218185705.2002516-1-bvanassche@acm.org> References: <20231218185705.2002516-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reject values that are valid rw_hints after truncation but not before truncation by passing an untruncated value to rw_hint_valid(). Reviewed-by: Christoph Hellwig Cc: Jeff Layton Cc: Chuck Lever Cc: Jens Axboe Cc: Stephen Rothwell Fixes: 5657cb0797c4 ("fs/fcntl: use copy_to/from_user() for u64 types") Signed-off-by: Bart Van Assche --- fs/fcntl.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index c80a6acad742..3ff707bf2743 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -268,7 +268,7 @@ static int f_getowner_uids(struct file *filp, unsigned long arg) } #endif -static bool rw_hint_valid(enum rw_hint hint) +static bool rw_hint_valid(u64 hint) { switch (hint) { case RWH_WRITE_LIFE_NOT_SET: @@ -288,19 +288,17 @@ static long fcntl_rw_hint(struct file *file, unsigned int cmd, { struct inode *inode = file_inode(file); u64 __user *argp = (u64 __user *)arg; - enum rw_hint hint; - u64 h; + u64 hint; switch (cmd) { case F_GET_RW_HINT: - h = inode->i_write_hint; - if (copy_to_user(argp, &h, sizeof(*argp))) + hint = inode->i_write_hint; + if (copy_to_user(argp, &hint, sizeof(*argp))) return -EFAULT; return 0; case F_SET_RW_HINT: - if (copy_from_user(&h, argp, sizeof(h))) + if (copy_from_user(&hint, argp, sizeof(hint))) return -EFAULT; - hint = (enum rw_hint) h; if (!rw_hint_valid(hint)) return -EINVAL;