From nobody Sat Feb 7 17:54:57 2026 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 E5478DDAD for ; Tue, 20 Aug 2024 01:04:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724115849; cv=none; b=dfTWj768qMIoVklmW5nC5SSfFMCQ74o8xJhGtF9diNnnWjsQyO9LlPvkpCVHG+yDX841Omjg7hXfNK8W4xGkAlhgdt9WaxEIldcg26owNL/On38tfOoKPRqE99V/yE/9Rf0GO1osMXk6f2B6awrLQmj+ZhQ+xkbviKc4qG41gU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724115849; c=relaxed/simple; bh=rlvDPXnw7XS8R0QQespbZ/XZfErKbFUB0YyUS28SphQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=F9WqYS1rdxhZ3eGQLBZOPwU4XygUPMeYvpdCy+GjTN3EyoLKlqTfgqEguQKMC5ru2pdFETwi9IrAC6+EQKmwNEdTMVhpemHmYt5KVjc2v4CHZJaFg1dJbaJ6X1i6bmKZO1wMfCGVUXh2MJEJS6hg2HHVWSvG8nTYVQffZOH7ws0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T/kCvvjJ; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T/kCvvjJ" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a86464934e3so46038066b.3 for ; Mon, 19 Aug 2024 18:04:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724115846; x=1724720646; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=UACsmobsUd8Y9iBIYxx+ODamTggideAg91GBgxrKC+4=; b=T/kCvvjJcmkOJJQ8ApRLw5fdYX5fuMTuzh7SEHent/oi+eavpUaJ5N72e35OnWmpOv /gPbhkC53etC1ixvn31tXH0iIkRJuXbDEZ/2Y9VRhdosddbmYTYOsnwqY/uzxm20PYo/ 43oXd2qHZMjAv340+dT1VwzEkSUQO93e+80REjhdhdJYItTQ33YjahrnEqgvkFx95Asl s2W9ut+VNgo97jq97rZpaD60OMeBh6ohQqb2xmpZy2Ma7mUtLaoUamgq6RsUMezZxj16 b9IBuaUFUvaXTvYkq6ujUtEHU356omMM2Fw8SzDs1ou4cT7T56hn3I5BVcE62md//lDy hPug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724115846; x=1724720646; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UACsmobsUd8Y9iBIYxx+ODamTggideAg91GBgxrKC+4=; b=Sm1WSirMcXc3zVCllO1/FP2Xc93Gl3rsdTKUZNV6tTBPe414ROwFct+Jw4ZFVpEwrC 4mN4fpkCgxmkJbRMwKiHVJxltM3CXs3iddD4074L8epg09q/jTMsEc5uSRp9U7YyKM3k 1qfuWU85Alr36cFahlzkASj0iFLLwMKoqxAJ5VG10gTo72hCC4/5AvDb12oxPs7N5Kve lO1qsKUtRFd52ykCN4Dm4uu3xH8SSt/IxsPC0gb3ehWx7VP1RlTunWTiMLxcURqw8smv vfGstb4gmceQAYILDZQnmo2VG0sd08fZK9I3kYCMDNdyaz/AFPGI7MCgmcGWvn6729p0 Z25w== X-Forwarded-Encrypted: i=1; AJvYcCXdHdbzGPyFlmOcImjlHFgn3juFs3CSI+vFZb7NNGf06kTwCkRqH3f8gpOolO9ywWhvHFxS9LPkNsZm9g2je/tNK3e+YcazVfzTyqLK X-Gm-Message-State: AOJu0YwOJ0LfDe/YrCSXn3JNwds419way7/zQYlkKhqb5KmeR8YFolSR 3pfITf24kkks9NAB2Cfnh2edPi0eN2FZ9crvgZRDlitkNJUv9Bic X-Google-Smtp-Source: AGHT+IFD5aZEqE3cEzDccQnjGQj3peF4UUPSjP3VpAalU8jd/ADbac4NDPAqvijztQCvyiNg3+mzbA== X-Received: by 2002:a17:907:d854:b0:a77:e55a:9e8c with SMTP id a640c23a62f3a-a83929d37b7mr881022866b.47.1724115845888; Mon, 19 Aug 2024 18:04:05 -0700 (PDT) Received: from hostname ([2a02:c7c:6696:8300:44d8:63fa:6beb:ff38]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a838396d7c0sm691572066b.213.2024.08.19.18.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2024 18:04:05 -0700 (PDT) Date: Tue, 20 Aug 2024 02:03:42 +0100 From: qasdev To: Joseph Qi , Heming Zhao , mark@fasheh.com, jlbec@evilplan.org Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2] ocfs2: Fix shift-out-of-bounds UBSAN bug in ocfs2_verify_volume() Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: Content-Type: text/plain; charset="utf-8" On Mon, Aug 19, 2024 at 10:52:29AM +0800, Joseph Qi wrote: >=20 >=20 > On 8/18/24 7:43 PM, Heming Zhao wrote: > > On 8/16/24 21:41, qasdev wrote: > >> =C2=A0From ad1ca2fd2ecf4eb7ec2c76fcbbf34639f0ad87ca Mon Sep 17 00:00:0= 0 2001 > >> From: Qasim Ijaz > >> Date: Fri, 16 Aug 2024 02:30:25 +0100 > >> Subject: [PATCH] ocfs2: Fix shift-out-of-bounds UBSAN bug in > >> =C2=A0 ocfs2_verify_volume() > >> >=20 > The above should be eliminated from patch body.=20 >=20 > >> This patch addresses a shift-out-of-bounds error in the > >> ocfs2_verify_volume() function, identified by UBSAN. The bug was trigg= ered > >> by an invalid s_clustersize_bits value (e.g., 1548), which caused the > >> expression "1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits)" > >> to exceed the limits of a 32-bit integer, > >> leading to an out-of-bounds shift. > >> > >> Reported-by: syzbot > >> Closes: https://syzkaller.appspot.com/bug?extid=3Df3fff775402751ebb471 > >> Tested-by: syzbot > >> Signed-off-by: Qasim Ijaz > >> --- > >> =C2=A0 fs/ocfs2/super.c | 8 ++++++-- > >> =C2=A0 1 file changed, 6 insertions(+), 2 deletions(-) > >> > >> diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c > >> index afee70125ae3..1e43cdca7f40 100644 > >> --- a/fs/ocfs2/super.c > >> +++ b/fs/ocfs2/super.c > >> @@ -2357,8 +2357,12 @@ static int ocfs2_verify_volume(struct ocfs2_din= ode *di, > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (unsigned long long)bh->b_blocknr); > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } else if (le32= _to_cpu(di->id2.i_super.s_clustersize_bits) < 12 || > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 le32_to_cpu(di->id2.i_super.s_clustersize= _bits) > 20) { > >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ml= og(ML_ERROR, "bad cluster size found: %u\n", > >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 1 << le32_to_cpu(di->id2.i_super.s_clustersize_= bits)); > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if= (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 32) > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 mlog(ML_ERROR, "bad cluster size found: %u\n", > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 1 << le32_to_cpu(di->id= 2.i_super.s_clustersize_bits)); > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 el= se > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 mlog(ML_ERROR, "invalid cluster size bit value: %u\n", > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 le32_to_cpu(di->id2.i_s= uper.s_clustersize_bits)); > >=20 > > I prefer to use concise code to fix the error. > > Do you like below code? > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mlog(ML_ERROR, "bad cluster= size found: %u\n", > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 1 << le32_to_cpu(di->id2.i_super.s_clustersize_= bits)); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mlog(ML_ERROR, "bad cluster= size bit found: %u\n", > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 le32_to_cpu(di->id2.i_super.s_clustersize_bits)= ); > >=20 >=20 > Agree. qasdev, Could you please update and send v2? >=20 > Thanks, > Joseph Thanks for the feedback. After considering the input, I've refined the patc= h=20 to make it more concise. I've updated the patch and included it below: This patch addresses a shift-out-of-bounds error in the=20 ocfs2_verify_volume() function, identified by UBSAN. The bug was triggered=20 by an invalid s_clustersize_bits value (e.g., 1548), which caused the=20 expression "1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits)"=20 to exceed the limits of a 32-bit integer,=20 leading to an out-of-bounds shift. Reported-by: syzbot Closes: https://syzkaller.appspot.com/bug?extid=3Df3fff775402751ebb471 Tested-by: syzbot Signed-off-by: Qasim Ijaz --- fs/ocfs2/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index afee70125ae3..b704983b2112 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c @@ -2357,8 +2357,8 @@ static int ocfs2_verify_volume(struct ocfs2_dinode *d= i, (unsigned long long)bh->b_blocknr); } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 1= 2 || le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) { - mlog(ML_ERROR, "bad cluster size found: %u\n", - 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bit= s)); + mlog(ML_ERROR, "bad cluster size bit found: %u\n", + le32_to_cpu(di->id2.i_super.s_clustersize_bits)); } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) { mlog(ML_ERROR, "bad root_blkno: 0\n"); } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) { --=20 2.30.2