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 D9E95C021A0 for ; Thu, 13 Feb 2025 11:29:04 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4YttHM1dcwz3bTf for ; Thu, 13 Feb 2025 22:29:03 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=115.124.30.132 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1739446142; cv=none; b=O6R+sTKoFQzQRVHR1q1PsxQPiA3XwFRg+0K802m9y6FSZbV0DZznrkFmcK+STK8svQhJdFx9/2M2eBzHYfvTrfS5i6qKI/FlljnJqf9safa9EGxCbUcK86dD+I6ddfkx66Uyq7ARwhcaowd1TbPusM1ybPxwZFftREvGlSKSjGrclJm0NeLIjQgPeiFsXa3hjwcCE6AuvghLWeSyoG9wNEU5dAkpaWaX8H+XqOIzAVF/jW9YBK01S5EFTx8iIUz79N/c3VvLha6IyH33Mu+o4mJzkGqRDmxih6744GshUhrOYa4GZOS00XP/L3YQq+OrWnBK31vJeBm2zwn4Adttmg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1739446142; c=relaxed/relaxed; bh=kv8BMoJpbxc9jojR7+5+zseML6qOiINst/GRSJcHC18=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FpHJRcc+Mh5we2K1Oll2MNjJ+yiuxy+1Ygbg0JRDEgzwqK4lNy4uJxiuLxWAe9QyFppLiTKjUljBdm78JyAZuiEhyPk43y1NuHLV6bu4rxkwhhkGsP+z5pCRKboWW7nbkr7yJvGCl4/L1cGlMKjNvoeR0eY/OAERijauvrmoaHXWh3Hze0Inh6e1Ce08sns7sXegf2PW1ZdQR3si6IWv5iRFtsSlEMedbcj8RkQiBw0CbCuPIM9feK98mIc4VP69G0oRDg0VvDyMc8lHU9w3Y74JwLxxhV8BbtCh384MMYvvVpWppKK+cAgMlfmwPI8hwc/08kzVZseU3p2hZs6pTg== 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=s57AD7aF; dkim-atps=neutral; spf=pass (client-ip=115.124.30.132; helo=out30-132.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=s57AD7aF; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.132; helo=out30-132.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=lists.ozlabs.org) Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (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 4YttHJ4cQ3z2yVV for ; Thu, 13 Feb 2025 22:28:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739446135; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=kv8BMoJpbxc9jojR7+5+zseML6qOiINst/GRSJcHC18=; b=s57AD7aF9ODeXRrlwxejXOLTOlnW/Zba0/wurhX5hbkYE/P3biXMoLFLoblkotwP3IJCWp27QNGxBy0MPcxMZqHybc6UDcyNH3H59bkcoeWmb1COdCckcMnFQv61RTwpTqsyPyXoU1BXqgVMbYyhnaq+pW3fJ4LzrjmX/WhaD9Q= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WPNMGBb_1739446129 cluster:ay36) by smtp.aliyun-inc.com; Thu, 13 Feb 2025 19:28:53 +0800 From: Gao Xiang To: u-boot@lists.denx.de, Tom Rini Subject: [PATCH v2] fs/erofs: fix an integer overflow in symlink resolution Date: Thu, 13 Feb 2025 19:28:47 +0800 Message-ID: <20250213112847.1848317-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gao Xiang , linux-erofs@lists.ozlabs.org, Jonathan Bar Or Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" See the original report [1], otherwise len + 1 will be overflowed. Note that EROFS archive can record arbitary symlink sizes in principle, so we don't assume a short number like 4096. [1] https://lore.kernel.org/r/20250210164151.GN1233568@bill-the-cat Fixes: 830613f8f5bb ("fs/erofs: add erofs filesystem support") Signed-off-by: Gao Xiang --- v2: - use __builtin_add_overflow as Jonathan suggested. fs/erofs/fs.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/erofs/fs.c b/fs/erofs/fs.c index 7bd2e8fcfc..dcdc883e34 100644 --- a/fs/erofs/fs.c +++ b/fs/erofs/fs.c @@ -59,16 +59,19 @@ struct erofs_dir_stream { static int erofs_readlink(struct erofs_inode *vi) { - size_t len = vi->i_size; + size_t alloc_size; char *target; int err; - target = malloc(len + 1); + if (__builtin_add_overflow(vi->i_size, 1, &alloc_size)) + return -EFSCORRUPTED; + + target = malloc(alloc_size); if (!target) return -ENOMEM; - target[len] = '\0'; + target[vi->i_size] = '\0'; - err = erofs_pread(vi, target, len, 0); + err = erofs_pread(vi, target, vi->i_size, 0); if (err) goto err_out; -- 2.43.5