linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mkfs.ubifs: Fix runtime assertions when running without crypto
@ 2021-03-08 12:59 Henri Roosen
  2021-03-08 13:09 ` Richard Weinberger
  0 siblings, 1 reply; 4+ messages in thread
From: Henri Roosen @ 2021-03-08 12:59 UTC (permalink / raw)
  To: linux-mtd; +Cc: richard, Henri Roosen

Running mkfs.ubifs which was build without crypto triggered the
following assertion:

mkfs.ubifs: ubifs-utils/mkfs.ubifs/fscrypt.h:166:
inherit_fscrypt_context: Assertion `0' failed.

A previous commit-cc4c5e295f54 ("mkfs.ubifs: Enable support for building
without crypto") added a check for an existing fscrypt context before calling
functions inherit_fscrypt_context() and free_fscrypt_context(),
however did not properly do this for each call to these functions.

Fixes: cc4c5e295f54 ("mkfs.ubifs: Enable support for building without crypto")
Signed-off-by: Henri Roosen <henri.roosen@ginzinger.com>
---
 ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
index 8211ada..c3a909c 100644
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -2092,7 +2092,8 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st,
 		if (S_ISDIR(dent_st.st_mode)) {
 			err = add_directory(name, inum, &dent_st, 1, new_fctx);
 			if (err) {
-				free_fscrypt_context(new_fctx);
+				if (new_fctx)
+					free_fscrypt_context(new_fctx);
 				goto out_free;
 			}
 			nlink += 1;
@@ -2101,20 +2102,23 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st,
 			err = add_non_dir(name, &inum, 0, &type,
 					  &dent_st, new_fctx);
 			if (err) {
-				free_fscrypt_context(new_fctx);
+				if (new_fctx)
+					free_fscrypt_context(new_fctx);
 				goto out_free;
 			}
 		}
 
 		err = create_inum_attr(inum, name);
 		if (err) {
-			free_fscrypt_context(new_fctx);
+			if (new_fctx)
+				free_fscrypt_context(new_fctx);
 			goto out_free;
 		}
 
 		err = add_dent_node(dir_inum, entry->d_name, inum, type, fctx);
 		if (err) {
-			free_fscrypt_context(new_fctx);
+			if (new_fctx)
+				free_fscrypt_context(new_fctx);
 			goto out_free;
 		}
 		size += ALIGN(UBIFS_DENT_NODE_SZ + strlen(entry->d_name) + 1,
@@ -2158,12 +2162,14 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st,
 		name = make_path(dir_name, nh_elt->name);
 		inum = ++c->highest_inum;
 
-		new_fctx = inherit_fscrypt_context(fctx);
+		if (fctx)
+			new_fctx = inherit_fscrypt_context(fctx);
 
 		if (S_ISDIR(nh_elt->mode)) {
 			err = add_directory(name, inum, &fake_st, 0, new_fctx);
 			if (err) {
-				free_fscrypt_context(new_fctx);
+				if (new_fctx)
+					free_fscrypt_context(new_fctx);
 				goto out_free;
 			}
 			nlink += 1;
@@ -2172,20 +2178,23 @@ static int add_directory(const char *dir_name, ino_t dir_inum, struct stat *st,
 			err = add_non_dir(name, &inum, 0, &type,
 					  &fake_st, new_fctx);
 			if (err) {
-				free_fscrypt_context(new_fctx);
+				if (new_fctx)
+					free_fscrypt_context(new_fctx);
 				goto out_free;
 			}
 		}
 
 		err = create_inum_attr(inum, name);
 		if (err) {
-			free_fscrypt_context(new_fctx);
+			if (new_fctx)
+				free_fscrypt_context(new_fctx);
 			goto out_free;
 		}
 
 		err = add_dent_node(dir_inum, nh_elt->name, inum, type, fctx);
 		if (err) {
-			free_fscrypt_context(new_fctx);
+			if (new_fctx)
+				free_fscrypt_context(new_fctx);
 			goto out_free;
 		}
 
-- 
2.20.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mkfs.ubifs: Fix runtime assertions when running without crypto
  2021-03-08 12:59 [PATCH] mkfs.ubifs: Fix runtime assertions when running without crypto Henri Roosen
@ 2021-03-08 13:09 ` Richard Weinberger
  2021-03-08 14:57   ` [PATCH v2] " Henri Roosen
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Weinberger @ 2021-03-08 13:09 UTC (permalink / raw)
  To: Henri Roosen; +Cc: linux-mtd, Henri Roosen

Henri,

----- Ursprüngliche Mail -----
> Von: "Henri Roosen" <henriroosen@gmail.com>
> An: "linux-mtd" <linux-mtd@lists.infradead.org>
> CC: "richard" <richard@nod.at>, "Henri Roosen" <henri.roosen@ginzinger.com>
> Gesendet: Montag, 8. März 2021 13:59:18
> Betreff: [PATCH] mkfs.ubifs: Fix runtime assertions when running without crypto

> Running mkfs.ubifs which was build without crypto triggered the
> following assertion:
> 
> mkfs.ubifs: ubifs-utils/mkfs.ubifs/fscrypt.h:166:
> inherit_fscrypt_context: Assertion `0' failed.
> 
> A previous commit-cc4c5e295f54 ("mkfs.ubifs: Enable support for building
> without crypto") added a check for an existing fscrypt context before calling
> functions inherit_fscrypt_context() and free_fscrypt_context(),
> however did not properly do this for each call to these functions.
> 
> Fixes: cc4c5e295f54 ("mkfs.ubifs: Enable support for building without crypto")
> Signed-off-by: Henri Roosen <henri.roosen@ginzinger.com>
> ---
> ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 27 ++++++++++++++++++---------
> 1 file changed, 18 insertions(+), 9 deletions(-)

Instead of patching every call site please fix the inline function itself.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] mkfs.ubifs: Fix runtime assertions when running without crypto
  2021-03-08 13:09 ` Richard Weinberger
@ 2021-03-08 14:57   ` Henri Roosen
  2021-03-22  0:27     ` David Oberhollenzer
  0 siblings, 1 reply; 4+ messages in thread
From: Henri Roosen @ 2021-03-08 14:57 UTC (permalink / raw)
  To: linux-mtd; +Cc: richard, Henri Roosen

Running mkfs.ubifs which was build without crypto triggered the
following assertion:

mkfs.ubifs: ubifs-utils/mkfs.ubifs/fscrypt.h:166:
inherit_fscrypt_context: Assertion `0' failed.

A previous commit-cc4c5e295f54 ("mkfs.ubifs: Enable support for building
without crypto") added a check for an existing fscrypt context before calling
functions inherit_fscrypt_context() and free_fscrypt_context(),
however did not properly do this for each call to these functions.

Fixes: cc4c5e295f54 ("mkfs.ubifs: Enable support for building without crypto")
Signed-off-by: Henri Roosen <henri.roosen@ginzinger.com>
---
Changes since v1:
 - instead of patching every call site, allow inline functions
   inherit_fscrypt_context() and free_fscrypt_context() to be called with NULL
   fscrypt context.

 ubifs-utils/mkfs.ubifs/fscrypt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ubifs-utils/mkfs.ubifs/fscrypt.h b/ubifs-utils/mkfs.ubifs/fscrypt.h
index 34b799c..ff3d326 100644
--- a/ubifs-utils/mkfs.ubifs/fscrypt.h
+++ b/ubifs-utils/mkfs.ubifs/fscrypt.h
@@ -131,7 +131,7 @@ static inline void free_fscrypt_context(struct fscrypt_context *fctx)
 {
 	(void)fctx;
 
-	assert(0);
+	assert(!fctx);
 }
 
 static inline int encrypt_path(void **outbuf, void *data, unsigned int data_len,
@@ -163,7 +163,7 @@ static inline struct fscrypt_context *inherit_fscrypt_context(struct fscrypt_con
 {
 	(void)fctx;
 
-	assert(0);
+	assert(!fctx);
 	return NULL;
 }
 #endif /* WITH_CRYPTO */
-- 
2.20.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mkfs.ubifs: Fix runtime assertions when running without crypto
  2021-03-08 14:57   ` [PATCH v2] " Henri Roosen
@ 2021-03-22  0:27     ` David Oberhollenzer
  0 siblings, 0 replies; 4+ messages in thread
From: David Oberhollenzer @ 2021-03-22  0:27 UTC (permalink / raw)
  To: Henri Roosen, linux-mtd; +Cc: richard, Henri Roosen

Applied to mtd-utils.git master.

Thanks,

David

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-22  0:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 12:59 [PATCH] mkfs.ubifs: Fix runtime assertions when running without crypto Henri Roosen
2021-03-08 13:09 ` Richard Weinberger
2021-03-08 14:57   ` [PATCH v2] " Henri Roosen
2021-03-22  0:27     ` David Oberhollenzer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).