Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2524817lqp; Mon, 25 Mar 2024 01:06:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCURpiEWcFEdP1egl3h2HRppQl1suTj3cFOyxHfJYSLHIYFetR7TC2nQsLYSXPyLoZo5woow9B/i4bOCkvQliyKoa0yC8vN2ZVeaeBUmMA== X-Google-Smtp-Source: AGHT+IFV0M+4+QMNNqvjxW6E7vV6N35RbIbPCoN7aCmiHm+XWAvEbeGEw48+aPaZ4zn1hxdbKMup X-Received: by 2002:a05:6a20:8998:b0:1a3:66e5:5c8f with SMTP id h24-20020a056a20899800b001a366e55c8fmr4351306pzg.28.1711353993450; Mon, 25 Mar 2024 01:06:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711353993; cv=pass; d=google.com; s=arc-20160816; b=dR2YJ5JTfIMyDGuYoVDahlFrKY1qBHA58zSdNIal8DLopUCwUmCwnnhadpWsZkFX7d 8dPXCkhSaFZxiWFaerrDbxwiV/QWxhsexVbJPDLmAMKiSpHk9Oz6NrFCW7keVnYIdO3x 7jOJDVcoRM3DiXv8ppk5jDaxBAFX1xHZ0NnTlBwfi4JpTHGrMjZOxUGx7BPyvRbZ6lgh RskwWgv1OgXZPfEN/IS6dPv43mqtOZ4Ya0y/XqjxNwDKOn4qBf9E6k4f5AH4U+CANFiO 2jEgI7/6uzPTsiShjP8yK9dU05FZTFHPq4kjM0Ecb2H1OHI6e4pdQ/7tKnYasvJTLpYY +0zQ== 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=ZStdQWQEx9VjamvdUtJRyDY/CqjZmgwlJcDjJqVTj6Q=; fh=Qt8ZLu1zs6vkfOdM2sbLVGj/5Ufj/q4ZdIIDO2YTwR8=; b=FbfsJ9PDbWk3DOslLInIeDGyOL0miTwdDGB+TINM4TyXpjvyYF/PCQf+xmFQxddX8h afwmJJ1JGl9+7Wgnhn9dCq2aZkPwIMImO6pj3nDtQgaRTurzF1P/3dtQHPZlwrbMpwgd XK0bWJBQfif0ffvmxD+Oa/p88IhvZ6TIyEgYCpQkHKApkNevMrLlvMYXXS4LFGyX+oXR 1M027Ffci8SK+v9sJgMKTzplYClsHZlVQKB8lxZbINKPWxD2XEHukHPqdckPG3kcyK9c 0l1fW9v6oKZ6XlgT13pdHbY+vrXbc6Dp0OtcmkHvXSeF0e6tsmevoaPypjcEeKL2NkeW M8eg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fzNoI+Ly; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115799-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115799-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id gr20-20020a056a004d1400b006e629ca2803si4620363pfb.180.2024.03.25.01.06.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 01:06:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115799-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fzNoI+Ly; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115799-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115799-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 23C2E296129 for ; Mon, 25 Mar 2024 08:06:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E2583736DC; Mon, 25 Mar 2024 03:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fzNoI+Ly" 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 1478B1448E5; Sun, 24 Mar 2024 23:13:07 +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=1711321987; cv=none; b=I3rTV07d1ZNZNIFQwZiN/T+Rvj60R8v/m304UodNLIG/WAkFgfaCss2aEIsE8dQQKapLr1e3pVS5RsQfeHGvjqXO0aTWAD+2DX2Sd3Ytby1KsrRJe/jUBD9jAb/KHdyT+mn/x9I791uva05Uz2D8oiz3EPZHU7sOuoRKBDjoElo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711321987; c=relaxed/simple; bh=mucHz+Zr6Fkl4kHASezKHfkPzv7eULYOavvfoTfoUzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uj2Cgshvg0WUf8qkzL0Oa2IFDL7zcMrwvUnihbcQVXpu3NmerCGfZVwOqa1n+898rUy4WKrBLBU887fQSd39g6hf6KuLAtSLipu9rIPhPfTBJe/IqxijMHcDo7YjGqdJQGlPH8uTsECNYqFtjrGLV6R33HieXPOan0rKCTGY1lI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fzNoI+Ly; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD916C43394; Sun, 24 Mar 2024 23:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711321986; bh=mucHz+Zr6Fkl4kHASezKHfkPzv7eULYOavvfoTfoUzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fzNoI+Lyo3qVE8rzxc9I1/yeNblOnD1veY4nKpgL6yr1SpLBv3i2eWF9e2OUCVbuk TrPw+4ZwkrYANl9yMmRgI49bZ3sxj7gjciOOYJDgJ3sa62whu5fJb4ygteC1mfp/GL pPkgz3DBWGZpDef5DxTtcK3szQw633TJ4x1yyUfQnrIt55PW1hBPEKcmRs9iewO/KA KCO14j+S/d/NvcRfQ8ilwqcPG9RPThT3Ft6kUd/XiRQABh6tSLLILQryo6sjrxECoq iC0A1a+KmT+r5LshB3rzcUydxGbz/8x1Z03F4TO2dxCGtbU2eIMYZ1OPPt3WntdIuB T3Kold60e4EJw== 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.1 059/451] fs: Fix rw_hint validation Date: Sun, 24 Mar 2024 19:05:35 -0400 Message-ID: <20240324231207.1351418-60-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-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 146c9ab0cd4b7..0964e5dbf0cac 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -267,7 +267,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: @@ -287,19 +287,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