From nobody Fri Apr 3 02:56:36 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 C680F3C661A for ; Tue, 24 Mar 2026 22:24:47 +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=1774391089; cv=pass; b=AZVLHYy77I84bIzTzPpijn6wJEB1m8dj790OILNVubXMcDghQZLrnTyphpOcYo2DeIc5e+i+PSyUhcid2uOcKy1qs6GSQAeFCLcWPyyqraAoqCxh3bAzcECkgS2uZtjQE3eiminYTpXZoHMwts9DnSj/DcDmSjIEaZ57IRL1AE0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774391089; c=relaxed/simple; bh=0HoV9XEIJwP7U/THeTiWvHo2B1rF1VFLfmUYiA80smc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nX+RkX566BLPfj6/RkDdHcY1r0uMSizxN0g+kbxzL2J4xs/CEj3Cyg3CGAaZV8Ie/6dvFPzgUZRFZtuytY/EmflxzD2H96+33sOAhLG2b6hLV/pJtHjqJRE6k+xQfaQp3DwIf4hH9VBE1VqxAV783nEcIM6H5lGNTVTFdDIGu2E= 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=kiL0c1Xo; 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="kiL0c1Xo" ARC-Seal: i=1; a=rsa-sha256; t=1774391084; cv=none; d=zohomail.eu; s=zohoarc; b=MFDFAm8MI2z6dDL30hsJIJAVMeStGON7jdl+SR5u5PaxnD0bnoNs9kfI/eUa+SakNcXGZnSCVfV3tLCxl7Wu5Snp3vDZlDpEuyoGdAca83biLBgsvfAcgg/dMkVkFFd7NylyqaZUbZnpwxVicTwDuGyd2EOStF+kkYatbnQuoRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1774391084; 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=sCk61HWJtm00gHGjP1a9J7QYl/XfvWolFzsMYOMraHo=; b=QVFdh4KdXDvszLu4DZqOn8ldIBDYhBcVNYYq3dggih7RgT0lFw0zZM2hvX3pD9tQsPtAZHNV2zLqohgu5vsgGZFd4ZKaBg1td3UoxrAN2ZCuPJxniSoDQkzSBeVsz0BSuc0CiKwumycJmVFV9U0U4i7vKn1Aqh8iar0KzH9vYWQ= 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=1774391084; 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=sCk61HWJtm00gHGjP1a9J7QYl/XfvWolFzsMYOMraHo=; b=kiL0c1Xoc3JWZgAu09XHyi/nzLoKsTee8P1bwPwGEj4OD59QiPhYEOrVcoRsUhAK dwU7izAWeEp3JDzgBTC44yqaqw7mWs0aZGE3PF0Q8pfdM0sAOFemHSUQJTE2AA556sE 2GQMRKilt22Ni2SzE7Tj2mdvU7lyc5jZriyhI+Vk= Received: by mx.zoho.eu with SMTPS id 1774391081618577.9319710691086; Tue, 24 Mar 2026 23:24:41 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Josh Law , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] lib/base64: validate before writing in decode tail path Date: Tue, 24 Mar 2026 22:24:38 +0000 Message-Id: <20260324222439.46028-2-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260324222439.46028-1-objecting@objecting.org> References: <20260324222439.46028-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: 98391 ("lib/base64: add base64 encoding/decoding helper") 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:36 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 444CF3559D6 for ; Tue, 24 Mar 2026 22:24:55 +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=1774391097; cv=pass; b=fk245h/BX+lAvx7RTGbk0UtcVSxMZRJXWo6XSD47oJytXSQVHHEwWSovt/eAFeOxwM7KVkejEWOHALX7B7VsiyE7DBNHcxWOeRcui82Q00YvmfVvXgkYldgqBADSKjG37BTNVSnBRZekqOcZ3Wk3FVC4UsdjKQMl8Vj09WU0g+c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774391097; c=relaxed/simple; bh=Eh4psVT2vdXMK4epTfcQyyYYP+7gOh8cfYDwn+qYtT0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dMGqGOU6drgtckTZmqaMsszytpUi+3HPrYbjUBH/qo4ZzFrl05jmj3F/gN7znE9EnR+kW7CKUTlvsGghPkQ0jh4CDXctJctY/n28S1HKjAYkEkZe4mqyG9OMUWyo0OF3H/Q/BOBvKtWvT6Nn1RescFr4XPdcqUjhhi4EnaDhnQg= 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=gaJH1WAq; 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="gaJH1WAq" ARC-Seal: i=1; a=rsa-sha256; t=1774391084; cv=none; d=zohomail.eu; s=zohoarc; b=f1xr3WxfEySoVuUxgpwUOx1aB568IjE7XQYTsj/ca9QXFuZvj3ee0U/SfbhC3e5RmoUxnqpRpZJd3oxMLSqt2PoVXgl37mHieGyWYt/pfxE4vZKnRsGuN+xXOrz1gOBxxxfw+SKLLvv2me+TPVRDsxjxvhFNJlFN+WuaByJndh4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1774391084; 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=TcBJXeCHp1yp2F27vqkfaYdnzI/Ks0WEQ90n9+1NB6v8qdWIUEiWOFw/CViBhSVJ33uRUtbuJX4V4Kb7s7z7kl31bg5IQdmmrkCWzEkuSVJj7DqmLkipD8nbFnUSrVNvFQYXcwpp+53nqT0OWtoleA8t/FzZFh5iO+1gzbQQud8= 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=1774391084; 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=gaJH1WAqilgD0r+Gt+17aPau//YHhOek3uApFfpC2ZgTDlfEREcG3Ph2ZI+pRaed vJEIfaW/1Cu9PHpLgjgdLFXGb6hJ4QNCLZDwTf+ohAX19rtItCdqQFNCuUCz3NpuveO vVIIVZfSv3X28H4Pn9BBs4Lb6zPUDep6cuAh0ic4= Received: by mx.zoho.eu with SMTPS id 1774391082094450.2216608142238; Tue, 24 Mar 2026 23:24:42 +0100 (CET) From: Josh Law To: Andrew Morton Cc: Josh Law , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] lib/base64: fix copy-pasted @padding doc in base64_decode() Date: Tue, 24 Mar 2026 22:24:39 +0000 Message-Id: <20260324222439.46028-3-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260324222439.46028-1-objecting@objecting.org> References: <20260324222439.46028-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