From patchwork Thu Dec 14 20:40: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: 754775 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 A539F6A359; Thu, 14 Dec 2023 20:41:54 +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-pg1-f179.google.com with SMTP id 41be03b00d2f7-5ca29c131ebso4599a12.0; Thu, 14 Dec 2023 12:41:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702586514; x=1703191314; 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=ETzg6Oovt3X2SPDlikYisWbbxpe/hgCmnhM+z1OHhUsvW+Yrk0Xly/PtPH6ohPa0GR g08iDCa5WckG68XLIst3HtCMz+kN5snAV9nFban0mL7RywsRtR5XKM5JPia1b+Nr+vXV Cfc6zthi8okXL/1giVZ8DNjbGdREi9wNrMfQwV+kL+PrazcicovGJLPl27iEar50Urum OOOh+R6IlH/XvqACRFvjWcLcayCJFDqQhJwInrLlROmh1N+od8ZZ0DLK3v0CHkmc5DJ7 bhIPeTvicmNcmGuJYfr2QQ0bdxSsBm8K9+iw6LVQWFTPYLnHCXXMTejWD0KX60ToRIvZ Z9+g== X-Gm-Message-State: AOJu0Ywp1xSA/pMhOniHzr0XlSrDwz6HJYh+EGLbyRNNGwS9P5YAqn6Y jRcFcXmwGTl7zHkN4wfykK0= X-Google-Smtp-Source: AGHT+IEe4TJfRK4vazMdR+23TcN8xOXS7VWtn5Jf/Y75HUk8ApECKZmA9OpZZ6pQvqqxuaAIzY/30Q== X-Received: by 2002:a17:903:496:b0:1d3:752a:f4ab with SMTP id jj22-20020a170903049600b001d3752af4abmr986134plb.79.1702586513652; Thu, 14 Dec 2023 12:41:53 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:0:1000:8411:bae8:452d:2e24:5984]) by smtp.gmail.com with ESMTPSA id z21-20020a170902ee1500b001d340c71ccasm5091640plb.275.2023.12.14.12.41.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 12:41:53 -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 v6 01/20] fs: Fix rw_hint validation Date: Thu, 14 Dec 2023 12:40:34 -0800 Message-ID: <20231214204119.3670625-2-bvanassche@acm.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231214204119.3670625-1-bvanassche@acm.org> References: <20231214204119.3670625-1-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-scsi@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;