Re: [PATCH] libfs: fix accidental overflow in offset calculation
From: Al Viro
Date: Thu May 09 2024 - 20:49:26 EST
On Fri, May 10, 2024 at 12:35:51AM +0000, Justin Stitt wrote:
> @@ -147,7 +147,9 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int whence)
> struct dentry *dentry = file->f_path.dentry;
> switch (whence) {
> case 1:
> - offset += file->f_pos;
> + /* cannot represent offset with loff_t */
> + if (check_add_overflow(offset, file->f_pos, &offset))
> + return -EOVERFLOW;
Instead of -EINVAL it correctly returns in such cases? Why?