From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1AFA5EA71B3 for ; Mon, 20 Apr 2026 01:52:47 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4fzT5G5QJVz2yrK; Mon, 20 Apr 2026 11:52:34 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=115.124.30.110 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1776649954; cv=none; b=kv0raeRZRgCk76CRbngb7+VImY4dPJo3gzWRxusrl4dcaTOx2csLUEioA6QAj13m/EsLtMq4Q1qCVqab1uIK7y4rxkfz3ksiTHp8s98oldGHWFgj7UH3m2pqftXNsQUVEFl6XVjbrHYb1BRJRIhOJ5akI+w342vVvK1Dw/1vy2n82g1rF829FxoDkQnuuPLulFRwqsyukGk/Af2TIyVFc3ay/xYMPVTXdS33saomJyhzygDiY6VXCqsRCbnV/a2uUePUOyDbs0jIq5Yyxji6t0xX/f+xfw73fa/DezwmDMVDIYFmNj6pXI33MTi6D0VjCthmNMrAW0asg4s4UYNhmA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1776649954; c=relaxed/relaxed; bh=KsdauIfAR68RAruVGluBtZ6ReMPY4MnBQFFBpKbgVVA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ngY1NUPFMZtpRhP2Y0utjX1Q92Cila5miAayl8uD7xhjSuiatUCFM3hIrDfZVY33/A7rUpxdUEC3+8feIZC324QCnVKccUrnQ41rQm1lEjUve82Ab2e6va31mvKzC9i/j5moRhte84fXbShV4XyOdXX84LET0/bXbDeTXlfxpkVdmWH5aCOx33mUQWh1va+aDh6e9/J40oRmBCf3Rgw+kH2SKa+CDuo5VvpoT87DiVSGtV2UfXae2ZTeVMCK4io72SHSeNdaZQy7L4WvQMK0IYDMswuqqm66VbXGstVBTQsBAl9V5OBe7tsaMTyaCrbLC9MzxB2dOBri6zhtBNyaFQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=p3o4t93c; dkim-atps=neutral; spf=pass (client-ip=115.124.30.110; helo=out30-110.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=lists.ozlabs.org) smtp.mailfrom=linux.alibaba.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=p3o4t93c; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.110; helo=out30-110.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=lists.ozlabs.org) Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4fzT5D32cJz2xSB for ; Mon, 20 Apr 2026 11:52:31 +1000 (AEST) DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1776649947; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=KsdauIfAR68RAruVGluBtZ6ReMPY4MnBQFFBpKbgVVA=; b=p3o4t93cVxVCD0d43HNwIn/EAtNTX/hqXoHX3rURnco9s2NGqGivJbtFbLPoeI93rgX33mUwZ+yig5PSd1JrR/XKD4R6gXQrAXWptFFNzy7Fmzra/TUKA543clbfdNSlilP5JIEO03d+NBEsnr1rqyR12aniJQCSlwOUoqmyJ7o= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037033178;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0X1Gaqux_1776649944; Received: from 30.221.130.173(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0X1Gaqux_1776649944 cluster:ay36) by smtp.aliyun-inc.com; Mon, 20 Apr 2026 09:52:25 +0800 Message-ID: <00f14a87-6914-4e4a-96f1-6d0f911edc4d@linux.alibaba.com> Date: Mon, 20 Apr 2026 09:52:24 +0800 X-Mailing-List: linux-erofs@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] erofs-utils: fix undefined behavior shift in erofs_init_devices To: Nithurshen , linux-erofs@lists.ozlabs.org Cc: xiang@kernel.org References: <20260419131604.95875-1-nithurshen.dev@gmail.com> From: Gao Xiang In-Reply-To: <20260419131604.95875-1-nithurshen.dev@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2026/4/19 21:16, Nithurshen wrote: > In erofs_init_devices(), roundup_pow_of_two() can potentially trigger > an undefined behavior shift if the incremented 'ondisk_extradevs' > value results in an overflow or an input that leads to an > out-of-bounds shift. I wonder why there is "out-of-bounds shift"? why you all think it's an issue? Can you please explain in details? ondisk_extradevs is 65535 at most. Thanks, Gao Xiang > > Promote the argument to u64 before the increment to ensure the > rounding logic operates on a safe bit-width. > > Signed-off-by: Nithurshen > --- > lib/super.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/super.c b/lib/super.c > index 088c9a0..10831a7 100644 > --- a/lib/super.c > +++ b/lib/super.c > @@ -49,7 +49,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi, > return 0; > > sbi->extra_devices = ondisk_extradevs; > - sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1; > + sbi->device_id_mask = roundup_pow_of_two((u64)ondisk_extradevs + 1) - 1; > sbi->devs = calloc(ondisk_extradevs, sizeof(*sbi->devs)); > if (!sbi->devs) > return -ENOMEM;