Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5451850pxu; Tue, 22 Dec 2020 18:25:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzT88q/5Hnfv3IWgxLAQ7ig8I0VixaYWUbifN1Kun+2zI6b+hvqci9/A9PXE6TWB22nhKry X-Received: by 2002:a17:906:234d:: with SMTP id m13mr22475189eja.270.1608690312357; Tue, 22 Dec 2020 18:25:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608690312; cv=none; d=google.com; s=arc-20160816; b=Qjm7ugrIvsLxxrov7qKvN7ZOBoVONm7GrcBZEmqI/jfPZrcHdnxZGZ6qnvYcFOUgqf lKqzicZQ/uB7wdwgAcEnLVnhHQGhDYBx80XZHSpRhUzJDPB1DtnY2KAhYNdXCQCTvIki JUOHdjFN0PalXuV4dFv73N7Jpyk9q6TNllhHTkUJTf9dBxQ8vDb/QI2Dm5BuoCptmIQ/ 6PyfKmpIH5s86i2oHduGC+tyVIZ8DglPyp/hB00TlGdLn+KXpkYirE9iKI08avRSRMTd 6y79uLWw5AKh5StKbWJy3399P5fQkXqidaNFGKBegDLfT7nxhPTHndJjUIqHJXZnIVEz CW4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UNQuTvEScI+T6sq4UHB2yecWLOtLkO7lobKZUC6PL3I=; b=PK3ja/Y7LxLVnh3e22wfw2j9m1vN0KComkBaXuvNK7NXRI9xvENxkqdDb0S96Ob6O1 ziknkaFd5WTJ3pfi2D31+QP4ii3hMlaETIpsreEnD9YeUqbyzZR+gCWW5fT7PjibKCaH JtdwvTOCW+1kNTu2NTNoNRNiTZOYJCn1oxSvNyKIhXL95SoR3Bgq2lOt0gWI9wHOcGUf VCZKJ+nexZRRl8BSejYCHiC1yueaJW3ZZjnaw+6MEtqFTxZHVRUBl48beiQAijgg6qAR py98hWzf+xue0BnpW3V6exzJyvYpL6CSc69Y9CzUWabb2zgFzdqg6gLGSgUd0bE89bFm 4lKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r3UCaSe8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a89si8209185edf.215.2020.12.22.18.24.50; Tue, 22 Dec 2020 18:25:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r3UCaSe8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728748AbgLWCXR (ORCPT + 99 others); Tue, 22 Dec 2020 21:23:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:52234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729940AbgLWCXQ (ORCPT ); Tue, 22 Dec 2020 21:23:16 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3800E22482; Wed, 23 Dec 2020 02:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608690174; bh=Iv5f45ChYLpTMHlwxxtdoZWBmiNeU1y8uPPFLZlXcBk=; h=From:To:Cc:Subject:Date:From; b=r3UCaSe8FLRjSH1XNvBMFxFsj+7NhA2XznzrAzznwlo6gLuqlNAw7q0+26P2jC49X usRkXOYH9NKGM0X1MwosU0Xyybh2c4uFSqSysU8QGURJL8yDT4kpVd0V8NM+rKmW2K Zumk5jkflgACZCEbREsA24NBa5ZuIU2rr00FuWqjC4BYa3U+mxb2X/DtKe0gYBYw6w ITOKz8KNKcy+RuGUN6zxfH6ZdYIfXDJqYm2FP6/sKWmkD+IiU7ao1k+Vi+7D5idA4j ED4lyt+/I0x+4NoMLjj8iXzQ9UV7El+3NUUmgTJHfTDg56VFYxRb4ONlacABaopmye wE/PyrIssuBaQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Luo Meng , Jeff Layton , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 01/66] locks: Fix UBSAN undefined behaviour in flock64_to_posix_lock Date: Tue, 22 Dec 2020 21:21:47 -0500 Message-Id: <20201223022253.2793452-1-sashal@kernel.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luo Meng [ Upstream commit 16238415eb9886328a89fe7a3cb0b88c7335fe16 ] When the sum of fl->fl_start and l->l_len overflows, UBSAN shows the following warning: UBSAN: Undefined behaviour in fs/locks.c:482:29 signed integer overflow: 2 + 9223372036854775806 cannot be represented in type 'long long int' Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xe4/0x14e lib/dump_stack.c:118 ubsan_epilogue+0xe/0x81 lib/ubsan.c:161 handle_overflow+0x193/0x1e2 lib/ubsan.c:192 flock64_to_posix_lock fs/locks.c:482 [inline] flock_to_posix_lock+0x595/0x690 fs/locks.c:515 fcntl_setlk+0xf3/0xa90 fs/locks.c:2262 do_fcntl+0x456/0xf60 fs/fcntl.c:387 __do_sys_fcntl fs/fcntl.c:483 [inline] __se_sys_fcntl fs/fcntl.c:468 [inline] __x64_sys_fcntl+0x12d/0x180 fs/fcntl.c:468 do_syscall_64+0xc8/0x5a0 arch/x86/entry/common.c:293 entry_SYSCALL_64_after_hwframe+0x49/0xbe Fix it by parenthesizing 'l->l_len - 1'. Signed-off-by: Luo Meng Signed-off-by: Jeff Layton Signed-off-by: Sasha Levin --- fs/locks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/locks.c b/fs/locks.c index 1a40e277eb5e1..11bb382a23c2e 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -488,7 +488,7 @@ static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl, if (l->l_len > 0) { if (l->l_len - 1 > OFFSET_MAX - fl->fl_start) return -EOVERFLOW; - fl->fl_end = fl->fl_start + l->l_len - 1; + fl->fl_end = fl->fl_start + (l->l_len - 1); } else if (l->l_len < 0) { if (fl->fl_start + l->l_len < 0) -- 2.27.0