From patchwork Tue Dec 19 00:07:34 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: 13497695 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 6B01E179; Tue, 19 Dec 2023 00:08:22 +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-pj1-f51.google.com with SMTP id 98e67ed59e1d1-28bb6f1b30fso242443a91.2; Mon, 18 Dec 2023 16:08:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702944502; x=1703549302; 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=MMtc2OH1eeru/1qk1qq6zbhDniP3Y/suD//Wbf6f+Fdkgijt1noxZAJ5KdNxEAx8qt EKu/y/ZGriMIdr9JQXXAzORlC5b4coKmp+NZX09xTijZjk3/sysV170olhIRPYa3X+Fw vFiscKHKZ+ruUnzKFXeXmhpPrv/8rhtSDbu2t15hyfsieMdlzIf4xlPAIs6Mrh2CfwIJ vbu7cLU0NG4MKWMXKrxCpkRHDgYvpKoNd7JsiAqwWA0fT7lF1JAANMGQGbDU9aohtuao w99G0HlF2oNW2CNFS4/x4Ja2gGawIdP5iFt4hXXvJhk4124Ifv9zFPPXMElKYxnWcy+q OjOg== X-Gm-Message-State: AOJu0YxoYKFtFxdJrlmC4CiGqYKzxKzae7eAhULH316gf9Qwh0BoTDGE r8ooXtFdGO+AYjp+8jjffd0= X-Google-Smtp-Source: AGHT+IHtlQmmfXbio/5G7mLlXD9DG+O+/fwoOcMkSl4oSjAgodiG/kfEgL4oUekGf8yWo+t0ByeeAQ== X-Received: by 2002:a17:90a:c241:b0:28b:5988:8e5e with SMTP id d1-20020a17090ac24100b0028b59888e5emr2079349pjx.7.1702944501617; Mon, 18 Dec 2023 16:08:21 -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 x17-20020a17090a531100b0028b050e8297sm118630pjh.18.2023.12.18.16.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 16:08:21 -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 v8 01/19] fs: Fix rw_hint validation Date: Mon, 18 Dec 2023 16:07:34 -0800 Message-ID: <20231219000815.2739120-2-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231219000815.2739120-1-bvanassche@acm.org> References: <20231219000815.2739120-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-fsdevel@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;