Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2359723lqp; Sun, 24 Mar 2024 15:38:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWsKZRNZ22RGgsoopl582+MhuzceWkuK+SRDq3NlC5RpuAbgy5Fif7A2uIZpeGywPav4vQTxyyS+Y8L5ODeaKbMhYT7YkDIsT0ZFW1wPQ== X-Google-Smtp-Source: AGHT+IEJyYxvJA8J0x0dd5rQKRG5XkWhTpVAjqJVWuWaRhbVpJvhBCQpVDUjN7ySrSA4Bred7SVi X-Received: by 2002:a50:c35b:0:b0:56b:a7e3:7426 with SMTP id q27-20020a50c35b000000b0056ba7e37426mr3591703edb.34.1711319918901; Sun, 24 Mar 2024 15:38:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711319918; cv=pass; d=google.com; s=arc-20160816; b=AK+ZzfkEaAvO624v8S4gaKQWqj/4mazRdZCHOlpoHXESw2Wz0sj3xYUmcs1/8XJYtm O1hjlRfkSPDkZy/pB/30wGyW0/xEiAgKHr5H7zlDuvlSODgXRRhzYmYyqE62H8sj02cK oWWz8aW+zpiwvIU7X1HtoJ4yPsQnsDSEfh6aUmv3qj7ZE0o4LA7xvso59f+rQYnl+6hs xY3z0aOmO/0IZO0niSCRoslksmdi96dESlWIcA79bu6fZ7K9yMrMxYLFtdj7sG5FZRtG y10Eq5Eqljp+hF1U6MBzZOYxddukfcpoORhXecyN8Z6ssnd/cKVx2otfDflt19NX+qHo YyIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DoxK0YNgGjYpGEShNPEQ5ijQfTo3tGD+dkhWuoCDSNY=; fh=Qt8ZLu1zs6vkfOdM2sbLVGj/5Ufj/q4ZdIIDO2YTwR8=; b=qe6LMVY3JsQCGXhNWSvkojTAAKgyOfiw0Qw9lzlk39383LCjl3+79fhiRrKs3PvWz9 942c08TCsIdNNY/atOewvRcrmOtfPV0YWYGo/sDB+YSXAHdRgYsrZuL0Z/oxrNr3Uftj /1hqFrUB81DlIb33O+WnQ5xRRvoDA3lxyederji0yfy/OZCJ0o0Ptow/Hiuqx8/upszN OP/bGTxl2GF+gQyXNESbuKQBPCP+g7uN244AYDVGzdYXlM2nJRYXN4LGJgJMS/t4dpGM sa5CcdNkVnK8WDyMP1p1jiwjm77jFe42/7PjzYc0Lgx3+nThvdMAdklscHwmizTYkfJx uQdg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KjrBFK2j; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112900-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112900-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q29-20020a50c35d000000b00568a684af64si2063991edb.591.2024.03.24.15.38.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 15:38:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112900-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KjrBFK2j; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-112900-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112900-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 981011F21659 for ; Sun, 24 Mar 2024 22:38:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA42455E51; Sun, 24 Mar 2024 22:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KjrBFK2j" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9A1554916; Sun, 24 Mar 2024 22:35:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319710; cv=none; b=PCHd4/JWZPQmj1mhmiyaKY4JIsrMRWMrxn6R1aFJJ4RLnzR0HaHp91lEvp14YfB7tC8WdtvqRhuq2R5jinOtDYEYHUVXOEjSP5VqRU2QTlWVfhCrMW1urrgzsIbX2m8JLXd+CwQ8UvRnX9Rl5cHo9N+Upxmz7hztJpoz1T1pVbk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319710; c=relaxed/simple; bh=76vkGyrV3hb3aWyw3PS3hSUigT9JbLaVi74F4EZkltQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q5s2qc38bKclZY4z5PJiZWc0cmYrxoK1NhFwnU2li7D3TFG3qFpAcCAmrjBHKxQe0f/07a3z9cgTSrfI02JCQ2cav/TkQUNmSLJCk0yLjM0DcnlYbds5XtfjUW6TEqS6IVp3Osaxx5wmMt1Z8fw+raBLQUk9sWK5u9pPD2+53mM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KjrBFK2j; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85C28C433F1; Sun, 24 Mar 2024 22:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319710; bh=76vkGyrV3hb3aWyw3PS3hSUigT9JbLaVi74F4EZkltQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KjrBFK2jOlWhfJ0YF1t2+n+lPhqZGV6fseqd2hDAv1HlOEm2++2m94rhNqpI+mkYg dXDcWyI7pdPVKmdm7c2A26jF2+YWjC4Kmf8kVdvuRjE+A6pe1VoBa4xoKpdvhn+B7Z g2L74Nnfp4PNhII0FUvej4HfHNVx9tRyjZ/GlKwrBsgk6CI9qqbXOamjTF+mqJlggV REYpjTrhSfQkHy2+98Xjp26OfeoNCIhvlYQ5wBPSXRo64VAE+BB0yKlyTUT7xtj3F7 mG+iISNIhrGlpLKwLodVeFLHbFCasZPyQ9Kvh1t9kve7JdFBfLhcDGgWZWEWinMVt7 QI31NR2mY4U8w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bart Van Assche , Christoph Hellwig , Kanchan Joshi , Jeff Layton , Chuck Lever , Jens Axboe , Stephen Rothwell , Christian Brauner , Sasha Levin Subject: [PATCH 6.8 013/715] fs: Fix rw_hint validation Date: Sun, 24 Mar 2024 18:23:12 -0400 Message-ID: <20240324223455.1342824-14-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Bart Van Assche [ Upstream commit ec16b147a55bfa14e858234eb7b1a7c8e7cd5021 ] 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 Reviewed-by: Kanchan Joshi 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 Link: https://lore.kernel.org/r/20240202203926.2478590-2-bvanassche@acm.org Signed-off-by: Christian Brauner Signed-off-by: Sasha Levin --- fs/fcntl.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index c80a6acad742f..3ff707bf2743a 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; -- 2.43.0