From nobody Wed Feb 11 13:12:50 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87FD6C77B75 for ; Mon, 8 May 2023 15:43:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234581AbjEHPnA (ORCPT ); Mon, 8 May 2023 11:43:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234553AbjEHPmo (ORCPT ); Mon, 8 May 2023 11:42:44 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13BB78A65 for ; Mon, 8 May 2023 08:42:41 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2ac8c0fbb16so37364001fa.2 for ; Mon, 08 May 2023 08:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683560559; x=1686152559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4pU3MyVcxC4FE8IDtgLQ5EJoKHTuAszvsZF+J0+YFmc=; b=fmyVwJV0lEr0gOVyjK7Zs2yARkiugtEIIx+DYwUHmOOFSBDoPcMej6cUQyGzl7KLDZ yVI9Uma+a53XuOlTYYnz5PJwx+iMR2eYE0NaxjvsG4gU3/ft0QFxfmCC7mImKNr6c3Zk qCddFae2O/g0P6kz1m37dO7vwePj7a0RorxuJxXhhvV1JuBdIEfzlzvWMPtcIiyn6wUV 0IoKg5z1KQfJYr03iHosJVOonWWN/otaOmg6zqJlDt5bj5hRHCXa/nM113+/3UnpRZQP I+7fPr47yTjvKIKXtPKIouvfpH4ePrF9J95Oh4iX6lh25MxWW6IHYFOv8qTWCpC6i3wp YYag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683560559; x=1686152559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4pU3MyVcxC4FE8IDtgLQ5EJoKHTuAszvsZF+J0+YFmc=; b=UIYX182GiEGyn9NraDH5SuI0+TwFNGCmNCcSCHTBgO5IeQ+9PY5+VgzTfBA1sVSig3 4SWXpabONrEweIVMFxN7wSqq5LooOo2cFsj1JqeYSU4FALYhNl+CpfHtsur2XAYDq25u Wc+j4ogl+VqowLKIi5AHCZCY0aYg+Lce57f8VgSP+ioopYQAFI4veBAtM7dxSHt6+wPU i/9H48cksY7VVlJVuMZ6r24iG6Wzr1GOgPMsqV7Vh7GWX2I2hUf/k22KV9eT6MKeDgoV vsdP0SGSp5D4cdxdeqrPluWdYcNEbDPHpmvz3gHroKjFoCyciJ6VTgTQJ1ARP8pcnLfJ 8GmA== X-Gm-Message-State: AC+VfDzTO909h5kuJgcRq0J5xVV59Z7n/6R4+ZQtInIe6wXaINVkwI1j ZYz4Uxd2HFeODvnUAgG7bfsCrA== X-Google-Smtp-Source: ACHHUZ6h6kvu6HAI2NpYck49HN3F1+F+0o3+VKGFl6dAG8ccfxCIlDuj80J+MkzIA7jF5MgIUTxxaw== X-Received: by 2002:a2e:9d14:0:b0:2a8:a6a5:e26e with SMTP id t20-20020a2e9d14000000b002a8a6a5e26emr2931590lji.20.1683560559390; Mon, 08 May 2023 08:42:39 -0700 (PDT) Received: from ta1.c.googlers.com.com (61.215.228.35.bc.googleusercontent.com. [35.228.215.61]) by smtp.gmail.com with ESMTPSA id a21-20020a2e9815000000b002ad9b741959sm17720ljj.76.2023.05.08.08.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 08:42:38 -0700 (PDT) From: Tudor Ambarus To: tytso@mit.edu Cc: adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, joneslee@google.com, Tudor Ambarus Subject: [RESEND PATCH v2 4/5] ext4: fsmap: Do the validation checks on constified fsmap data Date: Mon, 8 May 2023 15:42:29 +0000 Message-ID: <20230508154230.159654-5-tudor.ambarus@linaro.org> X-Mailer: git-send-email 2.40.1.521.gf1e218fcd8-goog In-Reply-To: <20230508154230.159654-1-tudor.ambarus@linaro.org> References: <20230508154230.159654-1-tudor.ambarus@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now that we do the sanity checks directly on the data copied from user, we can also constify the fsmap data while the checks are in progress. Do the validation checks on constified data, it imposes that the fsmap data is not updated during validation and assures readers that nothing strange happens during the validation sequence of calls. Signed-off-by: Tudor Ambarus --- fs/ext4/fsmap.c | 8 ++++---- fs/ext4/fsmap.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c index 463e8165b1e9..655379c96fcf 100644 --- a/fs/ext4/fsmap.c +++ b/fs/ext4/fsmap.c @@ -572,7 +572,7 @@ static int ext4_getfsmap_datadev(struct super_block *sb, =20 /* Do we recognize the device? */ static bool ext4_getfsmap_is_valid_device(struct super_block *sb, - struct fsmap *fm) + const struct fsmap *fm) { if (fm->fmr_device =3D=3D 0 || fm->fmr_device =3D=3D UINT_MAX || fm->fmr_device =3D=3D new_encode_dev(sb->s_bdev->bd_dev)) @@ -584,8 +584,8 @@ static bool ext4_getfsmap_is_valid_device(struct super_= block *sb, } =20 /* Ensure that the low key is less than the high key. */ -static bool ext4_getfsmap_check_keys(struct fsmap *low_key, - struct fsmap *high_key) +static bool ext4_getfsmap_check_keys(const struct fsmap *low_key, + const struct fsmap *high_key) { u64 l_fmr_phys =3D low_key->fmr_physical + low_key->fmr_length; =20 @@ -607,7 +607,7 @@ static bool ext4_getfsmap_check_keys(struct fsmap *low_= key, return false; } =20 -int ext4_fsmap_check_head(struct super_block *sb, struct fsmap_head *head) +int ext4_fsmap_check_head(struct super_block *sb, const struct fsmap_head = *head) { const struct fsmap *l =3D &head->fmh_keys[0]; const struct fsmap *h =3D &head->fmh_keys[1]; diff --git a/fs/ext4/fsmap.h b/fs/ext4/fsmap.h index e7c510afd672..8325258def7b 100644 --- a/fs/ext4/fsmap.h +++ b/fs/ext4/fsmap.h @@ -33,7 +33,8 @@ void ext4_fsmap_from_internal(struct super_block *sb, str= uct fsmap *dest, struct ext4_fsmap *src); void ext4_fsmap_to_internal(struct super_block *sb, struct ext4_fsmap *des= t, struct fsmap *src); -int ext4_fsmap_check_head(struct super_block *sb, struct fsmap_head *head); +int ext4_fsmap_check_head(struct super_block *sb, + const struct fsmap_head *head); =20 /* fsmap to userspace formatter - copy to user & advance pointer */ typedef int (*ext4_fsmap_format_t)(struct ext4_fsmap *, void *); --=20 2.40.1.521.gf1e218fcd8-goog