From nobody Fri Apr 3 02:56:38 2026 Received: from sender-of-o59.zoho.eu (sender-of-o59.zoho.eu [136.143.169.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA43431F99C for ; Tue, 24 Mar 2026 22:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774391539; cv=pass; b=YyV4Ob8Oqywp78N/ey6SCyCfVq20fDY7GlBL8VHzVV4yWdGC5XYgnPONrHgpfQDAa2C+mKlszihSEqcfAcBA2eO8A3uhuu0Gn+fgnS1hRzCjIPL0NV35l3VMC4vEzgjiGS4PGigMUPjpAhoJVUeNUsR/BROv34idpAXY9gT6PRs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774391539; c=relaxed/simple; bh=d3sRiLQiXI4+3KVE8NpIa5ODk0htfml2aa456IrgkKc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=crbIXU37y/z6lyL7AsNfcIJE6GIHZeOUo+BoD5z8zZaAbpWnbSr4GKcEj6ZcAFsvFIIiz73827kT3aDznYjZN7L1L7htObdAR8+mh3Y8/X/XgKUXwqHT+la0V+C1Ju3wXdkgAh7ZKH6lh81LqI7qtxBaHA1gH5Lzq21OSqik/1A= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=I9Aerwj0; arc=pass smtp.client-ip=136.143.169.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="I9Aerwj0" ARC-Seal: i=1; a=rsa-sha256; t=1774391535; cv=none; d=zohomail.eu; s=zohoarc; b=Buj4zSKOBHLAiGTcVkKaRAitLMTdTJKjF34I3z3cak8K72a5VknyaVDxRXYWht/z6ef4zTS+2VEEo8QvFxjuB47vZkvQgSMQFPpkLUSGg8c2e7r2Xr03M9g4DPXOzZuDUeMauojjTcuDhMhOIrppZnf0nzV4oaRLGUD1aq1uTWA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1774391535; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=1ullx5qWszQEPQCUEKsR/LvPVJ03udNGbOn3OOZe9NQ=; b=bxqf91JbxJNtLstcMJc8mwMuJXMDjn1tlqbARZ9QIdwUxicaQO3d5GmqmnfkI5wD7zqxRoj2OST1EUl4WYc9c7Mmy9h4sIabWvVHoOzd0JrlmG15vpAXO9V6oe31jrmxpLtf0LoUwUlXzu8LH1GO907JD0UDCFzpxb5xab9X6wU= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1774391535; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=1ullx5qWszQEPQCUEKsR/LvPVJ03udNGbOn3OOZe9NQ=; b=I9Aerwj07vXGkbnqSZzrXCvF4ay5LVVQ4FdjFsWA/y5kD4AkREH7zl7yoKxA208d gPUbwvYUxemmEbZgoBiwPG8P5FO8MEJXAccEC6g38m1G/nzoiSF3PfDyp33luFs77gk 6gJvVWlMWmpLQRnUnK2Xvy3c5ox/zVP6Hjfa+nBs= Received: by mx.zoho.eu with SMTPS id 1774391531883505.8659420579171; Tue, 24 Mar 2026 23:32:11 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Josh Law , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] lib/base64: validate before writing in decode tail path Date: Tue, 24 Mar 2026 22:32:09 +0000 Message-Id: <20260324223210.47676-2-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260324223210.47676-1-objecting@objecting.org> References: <20260324223210.47676-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" 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 strict= er validation") Signed-off-by: Josh Law --- lib/base64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/base64.c b/lib/base64.c index 41961a444028..20dacee25f65 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -168,15 +168,16 @@ int base64_decode(const char *src, int srclen, u8 *ds= t, bool padding, enum base6 return -1; =20 val =3D (base64_rev_tables[s[0]] << 12) | (base64_rev_tables[s[1]] << 6); - *bp++ =3D val >> 10; =20 if (srclen =3D=3D 2) { if (val & 0x800003ff) return -1; + *bp++ =3D val >> 10; } else { val |=3D base64_rev_tables[s[2]]; if (val & 0x80000003) return -1; + *bp++ =3D val >> 10; *bp++ =3D val >> 2; } return bp - dst; --=20 2.34.1 From nobody Fri Apr 3 02:56:38 2026 Received: from sender-of-o59.zoho.eu (sender-of-o59.zoho.eu [136.143.169.59]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E3D53815D8 for ; Tue, 24 Mar 2026 22:32:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774391540; cv=pass; b=fQLE/+7ej9QFrtqy2fjYG0I3n4g0bLkTNHjPGOzkV7CM9OV7nsAmskyldFZ2Na1f3X+m6E5I44Mzi2+J6uWsnPxxkPdcg23NJRYT5HbGcQ/Ljw1XpnR+Z7CSmNbgk4VyCB7X7LuO5ID588SEobxXw07rwRwzN7w3sekEm45R3+4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774391540; c=relaxed/simple; bh=Eh4psVT2vdXMK4epTfcQyyYYP+7gOh8cfYDwn+qYtT0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bKKU5q75+wfTQZv0vfuOO3OaIqQ60+UJ2ZMLAdq0FKTpLK+L2I8JVUTVi41xwtjFKA+UV90EcED6h+ICfOQQZvpTEp9g7+zzZe277ryMv4OqSdkDEmekVjfsoxdtw6piICRK8JFogFw8hoGzxTLYLb+K+6k/Qk0MAq1HsNTUtts= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=c351KjPZ; arc=pass smtp.client-ip=136.143.169.59 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="c351KjPZ" ARC-Seal: i=1; a=rsa-sha256; t=1774391535; cv=none; d=zohomail.eu; s=zohoarc; b=HxaU+NFkpiMXb6X9XgNlEl8Xuql5nxIMT2ViiJmNd4M4AcRmcZbU7HYFOeHfAHL8nr+gOsT2Tw0snlxCJzuNHWGX4NfWkW6a8G8dDoXEohozjq3S3oLrjEJ9cmyOCrTnP12SoePpog0BNNR/8M0Q/rFUNr9TW566xU97bB6BoHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1774391535; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=XAAGVl/NOMzLqQAJgHxeVmNhTNwLvCnn1B/Y0Dga1q4=; b=cL2K1GFnJufBW0oc8S6YZGCLHsnmO89C3UPu2MnxbExfeiM7ku5aipORrDzDiiA6vJEp4jptkOAojsn9VMfgYYWogR3qAAMIojVS7HpII2v01o/oXVuDXXkTdmvj3OnBPe19y5KEuO0EITCDwH/o6GNNrDWagJzICg9Ls9eVv4A= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1774391534; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=XAAGVl/NOMzLqQAJgHxeVmNhTNwLvCnn1B/Y0Dga1q4=; b=c351KjPZFrMa9FrcEqyq47q61RBmC8iXodkaIFAL2VXiW55ZjM7KN0yabgKPLnX9 jx9ai/7DEBDqNOUZECnvuQtzAwWaAKMiVVnjn/WH6lyi074306niJY5qjKOkrb1dcx5 SS/cHvW3674soMmv/5cEcU7qJ8ayEvpBayc6BBHs= Received: by mx.zoho.eu with SMTPS id 1774391532357860.530752387785; Tue, 24 Mar 2026 23:32:12 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Josh Law , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] lib/base64: fix copy-pasted @padding doc in base64_decode() Date: Tue, 24 Mar 2026 22:32:10 +0000 Message-Id: <20260324223210.47676-3-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260324223210.47676-1-objecting@objecting.org> References: <20260324223210.47676-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" The @padding kernel-doc for base64_decode() says "whether to append '=3D' padding characters", which was copy-pasted from base64_encode(). In the decode context, it controls whether the input is expected to include padding, not whether to append it. Signed-off-by: Josh Law --- lib/base64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/base64.c b/lib/base64.c index 20dacee25f65..325c7332b049 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -122,7 +122,7 @@ EXPORT_SYMBOL_GPL(base64_encode); * @src: the string to decode. Doesn't need to be NUL-terminated. * @srclen: the length of @src in bytes * @dst: (output) the decoded binary data - * @padding: whether to append '=3D' padding characters + * @padding: whether the input is expected to include '=3D' padding charac= ters * @variant: which base64 variant to use * * Decodes a string using the selected Base64 variant. --=20 2.34.1