2022-11-15 08:14:46

by Lihua (lihua, ran)

[permalink] [raw]
Subject: [PATCH] ubifs: Fix build errors as symbol undefined

When CONFIG_UBIFS_FS is enable but CONFIG_UBIFS_FS_AUTHENTICATION is not set:
ERROR: modpost: "ubifs_bad_hash" [fs/ubifs/ubifs.ko] undefined!

Fixes: 16a26b20d2af ("ubifs: authentication: Add hashes to index nodes")
Signed-off-by: Li Hua <[email protected]>
---
fs/ubifs/Kconfig | 2 ++
1 file changed, 2 insertions(+)

diff --git a/fs/ubifs/Kconfig b/fs/ubifs/Kconfig
index 45d3d207fb99..93bda1057fdc 100644
--- a/fs/ubifs/Kconfig
+++ b/fs/ubifs/Kconfig
@@ -13,6 +13,7 @@ config UBIFS_FS
select CRYPTO_HASH_INFO
select UBIFS_FS_XATTR if FS_ENCRYPTION
select FS_ENCRYPTION_ALGS if FS_ENCRYPTION
+ select UBIFS_FS_AUTHENTICATION
depends on MTD_UBI
help
UBIFS is a file system for flash devices which works on top of UBI.
@@ -91,6 +92,7 @@ config UBIFS_FS_AUTHENTICATION
select KEYS
select CRYPTO_HMAC
select SYSTEM_DATA_VERIFICATION
+ select SYSTEM_TRUSTED_KEYRING
help
Enable authentication support for UBIFS. This feature offers protection
against offline changes for both data and metadata of the filesystem.
--
2.17.1



2022-11-19 05:51:12

by Lihua (lihua, ran)

[permalink] [raw]
Subject: Re: [PATCH] ubifs: Fix build errors as symbol undefined

ping

在 2022/11/15 16:33, Li Hua 写道:
> When CONFIG_UBIFS_FS is enable but CONFIG_UBIFS_FS_AUTHENTICATION is not set:
> ERROR: modpost: "ubifs_bad_hash" [fs/ubifs/ubifs.ko] undefined!
>
> Fixes: 16a26b20d2af ("ubifs: authentication: Add hashes to index nodes")
> Signed-off-by: Li Hua <[email protected]>
> ---
> fs/ubifs/Kconfig | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/ubifs/Kconfig b/fs/ubifs/Kconfig
> index 45d3d207fb99..93bda1057fdc 100644
> --- a/fs/ubifs/Kconfig
> +++ b/fs/ubifs/Kconfig
> @@ -13,6 +13,7 @@ config UBIFS_FS
> select CRYPTO_HASH_INFO
> select UBIFS_FS_XATTR if FS_ENCRYPTION
> select FS_ENCRYPTION_ALGS if FS_ENCRYPTION
> + select UBIFS_FS_AUTHENTICATION
> depends on MTD_UBI
> help
> UBIFS is a file system for flash devices which works on top of UBI.
> @@ -91,6 +92,7 @@ config UBIFS_FS_AUTHENTICATION
> select KEYS
> select CRYPTO_HMAC
> select SYSTEM_DATA_VERIFICATION
> + select SYSTEM_TRUSTED_KEYRING
> help
> Enable authentication support for UBIFS. This feature offers protection
> against offline changes for both data and metadata of the filesystem.
>

2022-11-19 22:13:31

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH] ubifs: Fix build errors as symbol undefined

----- Ursprüngliche Mail -----
> Von: "Lihua (lihua, ran)" <[email protected]>
>> diff --git a/fs/ubifs/Kconfig b/fs/ubifs/Kconfig
>> index 45d3d207fb99..93bda1057fdc 100644
>> --- a/fs/ubifs/Kconfig
>> +++ b/fs/ubifs/Kconfig
>> @@ -13,6 +13,7 @@ config UBIFS_FS
>> select CRYPTO_HASH_INFO
>> select UBIFS_FS_XATTR if FS_ENCRYPTION
>> select FS_ENCRYPTION_ALGS if FS_ENCRYPTION
>> + select UBIFS_FS_AUTHENTICATION

I fear this is not a proper fix.
This changes does not longer allow building UBIFS without the authentication feature.
With what configuration do you see this error?

I just tried with:
CONFIG_UBIFS_FS=m
CONFIG_UBIFS_FS_ADVANCED_COMPR=y
CONFIG_UBIFS_FS_LZO=y
CONFIG_UBIFS_FS_ZLIB=y
CONFIG_UBIFS_FS_ZSTD=y
CONFIG_UBIFS_ATIME_SUPPORT=y
CONFIG_UBIFS_FS_XATTR=y
CONFIG_UBIFS_FS_SECURITY=y
# CONFIG_UBIFS_FS_AUTHENTICATION is not set

But don't get the error and, as expected, fs/ubifs/ubifs.o has no
reference to ubifs_bad_hash.

Thanks,
//richard

2022-11-21 02:19:03

by Lihua (lihua, ran)

[permalink] [raw]
Subject: Re: [PATCH] ubifs: Fix build errors as symbol undefined

You can verify it with the config in the attachment. TKS :D

在 2022/11/20 5:25, Richard Weinberger 写道:
> hat configuration do you see this er


Attachments:
config (110.79 kB)

2022-11-21 08:10:50

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH] ubifs: Fix build errors as symbol undefined

----- Ursprüngliche Mail -----
> Von: "Lihua" <[email protected]>
> An: "richard" <[email protected]>
> CC: "Sascha Hauer" <[email protected]>, "linux-mtd" <[email protected]>, "linux-kernel"
> <[email protected]>, "Wei Yongjun" <[email protected]>, "yusongping" <[email protected]>
> Gesendet: Montag, 21. November 2022 02:54:53
> Betreff: Re: [PATCH] ubifs: Fix build errors as symbol undefined

> You can verify it with the config in the attachment. TKS :D

Thanks for your .config, I was able to identify the problem.
When CONFIG_CC_OPTIMIZE_FOR_SIZE is set the compiler does not optimize this construct:

err = ubifs_node_check_hash(c, buf, zbr->hash);
if (err) {
ubifs_bad_hash(c, buf, zbr->hash, lnum, offs);
return 0;
}

With CONFIG_UBIFS_FS_AUTHENTICATION not set, the compiler can assume that
ubifs_node_check_hash() is never true and drops the call to ubifs_bad_hash().
Is CONFIG_CC_OPTIMIZE_FOR_SIZE enabled this optimization does not happen anymore.

So we need a no-op ubifs_bad_hash() for the CONFIG_UBIFS_FS_AUTHENTICATION=n case.

Thanks,
//richard

2022-11-21 10:06:21

by Lihua (lihua, ran)

[permalink] [raw]
Subject: Re: [PATCH] ubifs: Fix build errors as symbol undefined

Follow your suggestion, I will push a new patch,Thanks.

在 2022/11/21 16:00, Richard Weinberger 写道:
> ----- Ursprüngliche Mail -----
>> Von: "Lihua" <[email protected]>
>> An: "richard" <[email protected]>
>> CC: "Sascha Hauer" <[email protected]>, "linux-mtd" <[email protected]>, "linux-kernel"
>> <[email protected]>, "Wei Yongjun" <[email protected]>, "yusongping" <[email protected]>
>> Gesendet: Montag, 21. November 2022 02:54:53
>> Betreff: Re: [PATCH] ubifs: Fix build errors as symbol undefined
>
>> You can verify it with the config in the attachment. TKS :D
>
> Thanks for your .config, I was able to identify the problem.
> When CONFIG_CC_OPTIMIZE_FOR_SIZE is set the compiler does not optimize this construct:
>
> err = ubifs_node_check_hash(c, buf, zbr->hash);
> if (err) {
> ubifs_bad_hash(c, buf, zbr->hash, lnum, offs);
> return 0;
> }
>
> With CONFIG_UBIFS_FS_AUTHENTICATION not set, the compiler can assume that
> ubifs_node_check_hash() is never true and drops the call to ubifs_bad_hash().
> Is CONFIG_CC_OPTIMIZE_FOR_SIZE enabled this optimization does not happen anymore.
>
> So we need a no-op ubifs_bad_hash() for the CONFIG_UBIFS_FS_AUTHENTICATION=n case.
>
> Thanks,
> //richard
>
> .
>