Skip to contentSkip to conversation

lib-base64-validate-before-writing-in-decode-tail-path.patch removed from -mm tree

merged mm-nonmm-stable Andrew Morton 1 participant 1 message May 29

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: lib/base64: validate before writing in decode tail path
has been removed from the -mm tree. Its filename was
lib-base64-validate-before-writing-in-decode-tail-path.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Josh Law <[email protected]>
Subject: lib/base64: validate before writing in decode tail path
Date: Tue, 24 Mar 2026 22:32:09 +0000

Patch series "lib/base64: decode fixes", v2.

Two small fixes for lib/base64.c:

1. base64_decode() writes a decoded byte to the output buffer before validating the input in the trailing-bytes path. Move the validity checks before any writes so dst is untouched on invalid input.

2. The @padding kernel-doc for base64_decode() was copy-pasted from base64_encode() and describes the wrong direction.

This patch (of 2):

The trailing-bytes path in base64_decode() writes a decoded byte to the output buffer before checking whether the input characters are valid. If the input is malformed, garbage is written to dst before the function returns -1.

Move the validity checks before any writes so the output buffer is left untouched on invalid input.

Fixes 9c7d3cf94d33 ("lib/base64: rework encode/decode for speed and stricter validation")

---

 lib/base64.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/base64.c renamed from lib/base64.c~lib-base64-validate-before-writing-in-decode-tail-path +2 -1
@@ -168,15 +168,16 @@ int base64_decode(const char *src, int s
 		return -1;
 
 	val = (base64_rev_tables[s[0]] << 12) | (base64_rev_tables[s[1]] << 6);
-	*bp++ = val >> 10;
 
 	if (srclen == 2) {
 		if (val & 0x800003ff)
 			return -1;
+		*bp++ = val >> 10;
 	} else {
 		val |= base64_rev_tables[s[2]];
 		if (val & 0x80000003)
 			return -1;
+		*bp++ = val >> 10;
 		*bp++ = val >> 2;
 	}
 	return bp - dst;

_

Patches currently in -mm which might be from [email protected] are

lib-idr-fix-ida_find_first_range-missing-ids-across-chunk-boundaries.patch