mirror of
https://git.yoctoproject.org/poky
synced 2026-02-21 08:59:41 +01:00
Compare commits
114 Commits
yocto-3.1.
...
yocto-3.1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aeac103466 | ||
|
|
9a045bde41 | ||
|
|
6ebec3f39b | ||
|
|
9f0c1bc687 | ||
|
|
1d15d166d0 | ||
|
|
5c342965c4 | ||
|
|
6f375f52f5 | ||
|
|
52250009cd | ||
|
|
6f56a14cdc | ||
|
|
f1cf9f0f12 | ||
|
|
0d5e538519 | ||
|
|
374e198436 | ||
|
|
42c52c4f24 | ||
|
|
1a3807e0ca | ||
|
|
c7ddb9b198 | ||
|
|
ffbede6d58 | ||
|
|
2f34ea89db | ||
|
|
aa99487732 | ||
|
|
8ae21cd487 | ||
|
|
5a6d2dc704 | ||
|
|
f6f3a08371 | ||
|
|
cd97a607c6 | ||
|
|
f4cb2f5d52 | ||
|
|
3ee56c9b97 | ||
|
|
eebb034b21 | ||
|
|
e4d507b93b | ||
|
|
d01194c739 | ||
|
|
ee94c92957 | ||
|
|
5a893c6e96 | ||
|
|
43ffc2a5e7 | ||
|
|
a9d6f0c153 | ||
|
|
e3ae311c5f | ||
|
|
278d77034e | ||
|
|
c0535262c8 | ||
|
|
5ee2872089 | ||
|
|
f38a69e59f | ||
|
|
b731a65e4f | ||
|
|
da06aaf910 | ||
|
|
4d9612b31c | ||
|
|
cbb7afa601 | ||
|
|
f27e86a4d7 | ||
|
|
16c91216f1 | ||
|
|
e62c723b0c | ||
|
|
fe546dca3f | ||
|
|
00722bacdd | ||
|
|
15854dc716 | ||
|
|
f980ef9fec | ||
|
|
994a224d40 | ||
|
|
d32656ac24 | ||
|
|
669079e7c0 | ||
|
|
ea9b55c858 | ||
|
|
0734868d9d | ||
|
|
007a6e2dad | ||
|
|
926eb08fe3 | ||
|
|
6d6d43248e | ||
|
|
b222a20f8f | ||
|
|
55b09cdc1c | ||
|
|
87f18a42d4 | ||
|
|
3978003135 | ||
|
|
7fc94c93bf | ||
|
|
02356ecdca | ||
|
|
0cbec779f5 | ||
|
|
a1886b3532 | ||
|
|
9e2099f2a8 | ||
|
|
c3d7af5d16 | ||
|
|
a0615a08c5 | ||
|
|
b347ccc7ce | ||
|
|
c58cd65c96 | ||
|
|
ea56bba866 | ||
|
|
1b52dc0663 | ||
|
|
b48424988a | ||
|
|
0485ee7a6b | ||
|
|
90175073f6 | ||
|
|
0121cb4bd1 | ||
|
|
2f978be9e2 | ||
|
|
471e51b18a | ||
|
|
1a6ed0befd | ||
|
|
3fdec9fd90 | ||
|
|
b1fdc92450 | ||
|
|
02cfe361d6 | ||
|
|
8ae48ddf5e | ||
|
|
9fa49f817d | ||
|
|
84c0692d57 | ||
|
|
b1f23e404c | ||
|
|
b4da5c4df4 | ||
|
|
c06bf61270 | ||
|
|
827548d7f7 | ||
|
|
c314fe22fd | ||
|
|
6351d145ba | ||
|
|
268614c13d | ||
|
|
d148690f1d | ||
|
|
bce2280258 | ||
|
|
995f3a6243 | ||
|
|
98d8fdd7ea | ||
|
|
6b17a4af6a | ||
|
|
5e47346311 | ||
|
|
d76406934a | ||
|
|
9ffd5243e9 | ||
|
|
e33ce6f1af | ||
|
|
3b52050443 | ||
|
|
959e7b1432 | ||
|
|
729e5e306f | ||
|
|
3e0bb5455b | ||
|
|
3afaf243ba | ||
|
|
00ba8af956 | ||
|
|
3c6a02f04a | ||
|
|
ebca640cbb | ||
|
|
b5f81a875d | ||
|
|
2ff427ee40 | ||
|
|
0de5f6a27a | ||
|
|
f7f7d5514c | ||
|
|
762bfb5fc5 | ||
|
|
dcc4dbf463 | ||
|
|
91feb9b975 |
24
SECURITY.md
Normal file
24
SECURITY.md
Normal file
@@ -0,0 +1,24 @@
|
||||
How to Report a Potential Vulnerability?
|
||||
========================================
|
||||
|
||||
If you would like to report a public issue (for example, one with a released
|
||||
CVE number), please report it using the
|
||||
[https://bugzilla.yoctoproject.org/enter_bug.cgi?product=Security Security Bugzilla].
|
||||
If you have a patch ready, submit it following the same procedure as any other
|
||||
patch as described in README.md.
|
||||
|
||||
If you are dealing with a not-yet released or urgent issue, please send a
|
||||
message to security AT yoctoproject DOT org, including as many details as
|
||||
possible: the layer or software module affected, the recipe and its version,
|
||||
and any example code, if available.
|
||||
|
||||
Branches maintained with security fixes
|
||||
---------------------------------------
|
||||
|
||||
See [https://wiki.yoctoproject.org/wiki/Stable_Release_and_LTS Stable release and LTS]
|
||||
for detailed info regarding the policies and maintenance of Stable branches.
|
||||
|
||||
The [https://wiki.yoctoproject.org/wiki/Releases Release page] contains a list of all
|
||||
releases of the Yocto Project. Versions in grey are no longer actively maintained with
|
||||
security patches, but well-tested patches may still be accepted for them for
|
||||
significant issues.
|
||||
24
bitbake/SECURITY.md
Normal file
24
bitbake/SECURITY.md
Normal file
@@ -0,0 +1,24 @@
|
||||
How to Report a Potential Vulnerability?
|
||||
========================================
|
||||
|
||||
If you would like to report a public issue (for example, one with a released
|
||||
CVE number), please report it using the
|
||||
[https://bugzilla.yoctoproject.org/enter_bug.cgi?product=Security Security Bugzilla].
|
||||
If you have a patch ready, submit it following the same procedure as any other
|
||||
patch as described in README.md.
|
||||
|
||||
If you are dealing with a not-yet released or urgent issue, please send a
|
||||
message to security AT yoctoproject DOT org, including as many details as
|
||||
possible: the layer or software module affected, the recipe and its version,
|
||||
and any example code, if available.
|
||||
|
||||
Branches maintained with security fixes
|
||||
---------------------------------------
|
||||
|
||||
See [https://wiki.yoctoproject.org/wiki/Stable_Release_and_LTS Stable release and LTS]
|
||||
for detailed info regarding the policies and maintenance of Stable branches.
|
||||
|
||||
The [https://wiki.yoctoproject.org/wiki/Releases Release page] contains a list of all
|
||||
releases of the Yocto Project. Versions in grey are no longer actively maintained with
|
||||
security patches, but well-tested patches may still be accepted for them for
|
||||
significant issues.
|
||||
@@ -1,13 +1,13 @@
|
||||
DISTRO : "3.1.27"
|
||||
DISTRO : "3.1.29"
|
||||
DISTRO_NAME_NO_CAP : "dunfell"
|
||||
DISTRO_NAME : "Dunfell"
|
||||
DISTRO_NAME_NO_CAP_MINUS_ONE : "zeus"
|
||||
YOCTO_DOC_VERSION : "3.1.27"
|
||||
YOCTO_DOC_VERSION : "3.1.29"
|
||||
YOCTO_DOC_VERSION_MINUS_ONE : "3.0.4"
|
||||
DISTRO_REL_TAG : "yocto-3.1.27"
|
||||
DOCCONF_VERSION : "3.1.27"
|
||||
DISTRO_REL_TAG : "yocto-3.1.29"
|
||||
DOCCONF_VERSION : "3.1.29"
|
||||
BITBAKE_SERIES : "1.46"
|
||||
POKYVERSION : "23.0.27"
|
||||
POKYVERSION : "23.0.29"
|
||||
YOCTO_POKY : "poky-&DISTRO_NAME_NO_CAP;-&POKYVERSION;"
|
||||
YOCTO_DL_URL : "https://downloads.yoctoproject.org"
|
||||
YOCTO_AB_URL : "https://autobuilder.yoctoproject.org"
|
||||
|
||||
@@ -34,19 +34,35 @@ and conceptual information in the :doc:`../overview-manual/overview-manual`.
|
||||
Supported Linux Distributions
|
||||
=============================
|
||||
|
||||
Currently, the Yocto Project is supported on the following
|
||||
distributions:
|
||||
Currently, the &DISTRO; release ("&DISTRO_NAME;") of the Yocto Project is
|
||||
supported on the following distributions:
|
||||
|
||||
- Ubuntu 16.04 (LTS)
|
||||
|
||||
- Ubuntu 20.04 (LTS)
|
||||
|
||||
- Ubuntu 22.04 (LTS)
|
||||
|
||||
- Fedora 37
|
||||
|
||||
- Debian GNU/Linux 11.x (Bullseye)
|
||||
|
||||
- AlmaLinux 8.8
|
||||
|
||||
The following distribution versions are still tested (being listed
|
||||
in :term:`SANITY_TESTED_DISTROS`), even though the organizations
|
||||
publishing them no longer make updates publicly available:
|
||||
|
||||
- Ubuntu 18.04 (LTS)
|
||||
|
||||
- OpenSUSE Leap 15.3
|
||||
|
||||
Finally, here are the distribution versions which were previously
|
||||
tested on former revisions of "&DISTRO_NAME;", but no longer are:
|
||||
|
||||
- Ubuntu 16.04 (LTS)
|
||||
|
||||
- Ubuntu 19.04
|
||||
|
||||
- Ubuntu 20.04
|
||||
|
||||
- Ubuntu 22.04
|
||||
|
||||
- Fedora 28
|
||||
|
||||
- Fedora 29
|
||||
@@ -67,20 +83,18 @@ distributions:
|
||||
|
||||
- CentOS 7.x
|
||||
|
||||
- CentOS 8.x
|
||||
|
||||
- Debian GNU/Linux 8.x (Jessie)
|
||||
|
||||
- Debian GNU/Linux 9.x (Stretch)
|
||||
|
||||
- Debian GNU/Linux 10.x (Buster)
|
||||
|
||||
- Debian GNU/Linux 11.x (Bullseye)
|
||||
|
||||
- OpenSUSE Leap 15.1
|
||||
|
||||
- OpenSUSE Leap 15.2
|
||||
|
||||
- OpenSUSE Leap 15.3
|
||||
|
||||
- AlmaLinux 8.5
|
||||
|
||||
- AlmaLinux 8.7
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
DISTRO = "poky"
|
||||
DISTRO_NAME = "Poky (Yocto Project Reference Distro)"
|
||||
DISTRO_VERSION = "3.1.27"
|
||||
DISTRO_VERSION = "3.1.29"
|
||||
DISTRO_CODENAME = "dunfell"
|
||||
SDK_VENDOR = "-pokysdk"
|
||||
SDK_VERSION = "${@d.getVar('DISTRO_VERSION').replace('snapshot-${DATE}', 'snapshot')}"
|
||||
@@ -43,29 +43,13 @@ SANITY_TESTED_DISTROS ?= " \
|
||||
poky-2.7 \n \
|
||||
poky-3.0 \n \
|
||||
poky-3.1 \n \
|
||||
ubuntu-16.04 \n \
|
||||
ubuntu-18.04 \n \
|
||||
ubuntu-19.04 \n \
|
||||
ubuntu-20.04 \n \
|
||||
ubuntu-22.04 \n \
|
||||
fedora-30 \n \
|
||||
fedora-31 \n \
|
||||
fedora-32 \n \
|
||||
fedora-33 \n \
|
||||
fedora-34 \n \
|
||||
fedora-35 \n \
|
||||
fedora-36 \n \
|
||||
centos-7 \n \
|
||||
centos-8 \n \
|
||||
debian-8 \n \
|
||||
debian-9 \n \
|
||||
debian-10 \n \
|
||||
fedora-37 \n \
|
||||
debian-11 \n \
|
||||
opensuseleap-15.1 \n \
|
||||
opensuseleap-15.2 \n \
|
||||
opensuseleap-15.3 \n \
|
||||
almalinux-8.5 \n \
|
||||
almalinux-8.7 \n \
|
||||
almalinux-8.8 \n \
|
||||
"
|
||||
# add poky sanity bbclass
|
||||
INHERIT += "poky-sanity"
|
||||
|
||||
@@ -143,13 +143,14 @@ do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILD
|
||||
do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
|
||||
python do_symlink_kernsrc () {
|
||||
s = d.getVar("S")
|
||||
if s[-1] == '/':
|
||||
# drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail
|
||||
s=s[:-1]
|
||||
kernsrc = d.getVar("STAGING_KERNEL_DIR")
|
||||
if s != kernsrc:
|
||||
bb.utils.mkdirhier(kernsrc)
|
||||
bb.utils.remove(kernsrc, recurse=True)
|
||||
if s[-1] == '/':
|
||||
# drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as
|
||||
# directory name and fail
|
||||
s = s[:-1]
|
||||
if d.getVar("EXTERNALSRC"):
|
||||
# With EXTERNALSRC S will not be wiped so we can symlink to it
|
||||
os.symlink(s, kernsrc)
|
||||
@@ -404,8 +405,8 @@ kernel_do_install() {
|
||||
unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
|
||||
if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
|
||||
oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
|
||||
rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
|
||||
rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
|
||||
rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
|
||||
rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
|
||||
# If the kernel/ directory is empty remove it to prevent QA issues
|
||||
rmdir --ignore-fail-on-non-empty "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel"
|
||||
else
|
||||
@@ -417,12 +418,26 @@ kernel_do_install() {
|
||||
#
|
||||
install -d ${D}/${KERNEL_IMAGEDEST}
|
||||
install -d ${D}/boot
|
||||
|
||||
#
|
||||
# When including an initramfs bundle inside a FIT image, the fitImage is created after the install task
|
||||
# by do_assemble_fitimage_initramfs.
|
||||
# This happens after the generation of the initramfs bundle (done by do_bundle_initramfs).
|
||||
# So, at the level of the install task we should not try to install the fitImage. fitImage is still not
|
||||
# generated yet.
|
||||
# After the generation of the fitImage, the deploy task copies the fitImage from the build directory to
|
||||
# the deploy folder.
|
||||
#
|
||||
|
||||
for imageType in ${KERNEL_IMAGETYPES} ; do
|
||||
install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} ${D}/${KERNEL_IMAGEDEST}/${imageType}-${KERNEL_VERSION}
|
||||
if [ "${KERNEL_PACKAGE_NAME}" = "kernel" ]; then
|
||||
ln -sf ${imageType}-${KERNEL_VERSION} ${D}/${KERNEL_IMAGEDEST}/${imageType}
|
||||
if [ $imageType != "fitImage" ] || [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ] ; then
|
||||
install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} ${D}/${KERNEL_IMAGEDEST}/${imageType}-${KERNEL_VERSION}
|
||||
if [ "${KERNEL_PACKAGE_NAME}" = "kernel" ]; then
|
||||
ln -sf ${imageType}-${KERNEL_VERSION} ${D}/${KERNEL_IMAGEDEST}/${imageType}
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION}
|
||||
install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
|
||||
install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
# Zap the root password if debug-tweaks feature is not enabled
|
||||
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "", "zap_empty_root_password ; ",d)}'
|
||||
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'empty-root-password' ], "", "zap_empty_root_password; ",d)}'
|
||||
|
||||
# Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks or allow-empty-password is enabled
|
||||
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'allow-empty-password' ], "ssh_allow_empty_password; ", "",d)}'
|
||||
@@ -12,7 +12,7 @@ ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'deb
|
||||
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains_any("IMAGE_FEATURES", [ 'debug-tweaks', 'post-install-logging' ], "postinst_enable_logging; ", "",d)}'
|
||||
|
||||
# Create /etc/timestamp during image construction to give a reasonably sane default time setting
|
||||
ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp ; "
|
||||
ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp; "
|
||||
|
||||
# Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled
|
||||
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}'
|
||||
@@ -26,7 +26,7 @@ ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only
|
||||
APPEND_append = '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", " ro", "", d)}'
|
||||
|
||||
# Generates test data file with data store variables expanded in json format
|
||||
ROOTFS_POSTPROCESS_COMMAND += "write_image_test_data ; "
|
||||
ROOTFS_POSTPROCESS_COMMAND += "write_image_test_data; "
|
||||
|
||||
# Write manifest
|
||||
IMAGE_MANIFEST = "${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.manifest"
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
ROOTFS_DEBUG_FILES ?= ""
|
||||
ROOTFS_DEBUG_FILES[doc] = "Lists additional files or directories to be installed with 'cp -a' in the format 'source1 target1;source2 target2;...'"
|
||||
|
||||
ROOTFS_POSTPROCESS_COMMAND += "rootfs_debug_files ;"
|
||||
ROOTFS_POSTPROCESS_COMMAND += "rootfs_debug_files;"
|
||||
rootfs_debug_files () {
|
||||
#!/bin/sh -e
|
||||
echo "${ROOTFS_DEBUG_FILES}" | sed -e 's/;/\n/g' | while read source target mode; do
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
# to the distro running on the build machine.
|
||||
#
|
||||
|
||||
UNINATIVE_MAXGLIBCVERSION = "2.37"
|
||||
UNINATIVE_VERSION = "4.0"
|
||||
UNINATIVE_MAXGLIBCVERSION = "2.38"
|
||||
UNINATIVE_VERSION = "4.3"
|
||||
|
||||
UNINATIVE_URL ?= "http://downloads.yoctoproject.org/releases/uninative/${UNINATIVE_VERSION}/"
|
||||
UNINATIVE_CHECKSUM[aarch64] ?= "7baa8418a302df52e00916193b0a04f318356d9d2670c9a2bce3e966efefd738"
|
||||
UNINATIVE_CHECKSUM[i686] ?= "83114d36883d43a521e280742b9849bf85d039b2f83d8e21d480659babe75ee8"
|
||||
UNINATIVE_CHECKSUM[x86_64] ?= "fd75b2a1a67a10f6b7d65afb7d0f3e71a63b0038e428f34dfe420bb37716558a"
|
||||
UNINATIVE_CHECKSUM[aarch64] ?= "8df05f4a41455018b4303b2e0ea4eac5c960b5a13713f6dbb33dfdb3e32753ec"
|
||||
UNINATIVE_CHECKSUM[i686] ?= "bea76b4a97c9ba0077c0dd1295f519cd599dbf71f0ca1c964471c4cdb043addd"
|
||||
UNINATIVE_CHECKSUM[x86_64] ?= "1c35f09a75c4096749bbe1e009df4e3968cde151424062cf4aa3ed89db22b030"
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import oe.path
|
||||
import oe.types
|
||||
|
||||
@@ -24,7 +27,6 @@ class CmdError(bb.BBHandledException):
|
||||
|
||||
|
||||
def runcmd(args, dir = None):
|
||||
import pipes
|
||||
import subprocess
|
||||
|
||||
if dir:
|
||||
@@ -35,7 +37,7 @@ def runcmd(args, dir = None):
|
||||
# print("cwd: %s -> %s" % (olddir, dir))
|
||||
|
||||
try:
|
||||
args = [ pipes.quote(str(arg)) for arg in args ]
|
||||
args = [ shlex.quote(str(arg)) for arg in args ]
|
||||
cmd = " ".join(args)
|
||||
# print("cmd: %s" % cmd)
|
||||
(exitstatus, output) = subprocess.getstatusoutput(cmd)
|
||||
|
||||
@@ -226,6 +226,9 @@ def SSHCall(command, logger, timeout=None, **opts):
|
||||
endtime = time.time() + timeout
|
||||
except InterruptedError:
|
||||
continue
|
||||
except BlockingIOError:
|
||||
logger.debug('BlockingIOError')
|
||||
continue
|
||||
|
||||
# process hasn't returned yet
|
||||
if not eof:
|
||||
|
||||
@@ -67,7 +67,7 @@ class LtpTest(LtpTestBase):
|
||||
def runltp(self, ltp_group):
|
||||
cmd = '/opt/ltp/runltp -f %s -p -q -r /opt/ltp -l /opt/ltp/results/%s -I 1 -d /opt/ltp' % (ltp_group, ltp_group)
|
||||
starttime = time.time()
|
||||
(status, output) = self.target.run(cmd)
|
||||
(status, output) = self.target.run(cmd, timeout=1200)
|
||||
endtime = time.time()
|
||||
|
||||
with open(os.path.join(self.ltptest_log_dir, "%s-raw.log" % ltp_group), 'w') as f:
|
||||
|
||||
@@ -57,8 +57,8 @@ class RpmBasicTest(OERuntimeTestCase):
|
||||
return
|
||||
time.sleep(1)
|
||||
user_pss = [ps for ps in output.split("\n") if u + ' ' in ps]
|
||||
msg = "There're %s 's process(es) still running: %s".format(u, "\n".join(user_pss))
|
||||
assertTrue(True, msg=msg)
|
||||
msg = "User %s has processes still running: %s" % (u, "\n".join(user_pss))
|
||||
self.fail(msg=msg)
|
||||
|
||||
def unset_up_test_user(u):
|
||||
# ensure no test1 process in running
|
||||
|
||||
@@ -41,7 +41,7 @@ class GlibcSelfTestBase(OESelftestTestCase, OEPTestResultTestCase):
|
||||
with contextlib.ExitStack() as s:
|
||||
# use the base work dir, as the nfs mount, since the recipe directory may not exist
|
||||
tmpdir = get_bb_var("BASE_WORKDIR")
|
||||
nfsport, mountport = s.enter_context(unfs_server(tmpdir))
|
||||
nfsport, mountport = s.enter_context(unfs_server(tmpdir, udp = False))
|
||||
|
||||
# build core-image-minimal with required packages
|
||||
default_installed_packages = [
|
||||
@@ -61,7 +61,7 @@ class GlibcSelfTestBase(OESelftestTestCase, OEPTestResultTestCase):
|
||||
bitbake("core-image-minimal")
|
||||
|
||||
# start runqemu
|
||||
qemu = s.enter_context(runqemu("core-image-minimal", runqemuparams = "nographic"))
|
||||
qemu = s.enter_context(runqemu("core-image-minimal", runqemuparams = "nographic", qemuparams = "-m 1024"))
|
||||
|
||||
# validate that SSH is working
|
||||
status, _ = qemu.run("uname")
|
||||
@@ -70,7 +70,7 @@ class GlibcSelfTestBase(OESelftestTestCase, OEPTestResultTestCase):
|
||||
# setup nfs mount
|
||||
if qemu.run("mkdir -p \"{0}\"".format(tmpdir))[0] != 0:
|
||||
raise Exception("Failed to setup NFS mount directory on target")
|
||||
mountcmd = "mount -o noac,nfsvers=3,port={0},udp,mountport={1} \"{2}:{3}\" \"{3}\"".format(nfsport, mountport, qemu.server_ip, tmpdir)
|
||||
mountcmd = "mount -o noac,nfsvers=3,port={0},mountport={1} \"{2}:{3}\" \"{3}\"".format(nfsport, mountport, qemu.server_ip, tmpdir)
|
||||
status, output = qemu.run(mountcmd)
|
||||
if status != 0:
|
||||
raise Exception("Failed to setup NFS mount on target ({})".format(repr(output)))
|
||||
|
||||
@@ -8,7 +8,7 @@ from oeqa.utils.commands import bitbake, get_bb_var, Command
|
||||
from oeqa.utils.network import get_free_port
|
||||
|
||||
@contextlib.contextmanager
|
||||
def unfs_server(directory, logger = None):
|
||||
def unfs_server(directory, logger = None, udp = True):
|
||||
unfs_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "unfs3-native")
|
||||
if not os.path.exists(os.path.join(unfs_sysroot, "usr", "bin", "unfsd")):
|
||||
# build native tool
|
||||
@@ -22,7 +22,7 @@ def unfs_server(directory, logger = None):
|
||||
exports.write("{0} (rw,no_root_squash,no_all_squash,insecure)\n".format(directory).encode())
|
||||
|
||||
# find some ports for the server
|
||||
nfsport, mountport = get_free_port(udp = True), get_free_port(udp = True)
|
||||
nfsport, mountport = get_free_port(udp), get_free_port(udp)
|
||||
|
||||
nenv = dict(os.environ)
|
||||
nenv['PATH'] = "{0}/sbin:{0}/usr/sbin:{0}/usr/bin:".format(unfs_sysroot) + nenv.get('PATH', '')
|
||||
|
||||
@@ -128,6 +128,8 @@ GRUBPLATFORM ??= "pc"
|
||||
|
||||
inherit autotools gettext texinfo pkgconfig
|
||||
|
||||
CFLAGS_remove = "-O2"
|
||||
|
||||
EXTRA_OECONF = "--with-platform=${GRUBPLATFORM} \
|
||||
--disable-grub-mkfont \
|
||||
--program-prefix="" \
|
||||
|
||||
166
meta/recipes-connectivity/bind/bind/CVE-2023-2828.patch
Normal file
166
meta/recipes-connectivity/bind/bind/CVE-2023-2828.patch
Normal file
@@ -0,0 +1,166 @@
|
||||
|
||||
Upstream-Status: Backport [import from debian security.debian.org/debian-security/pool/updates/main/b/bind9/bind9_9.11.5.P4+dfsg-5.1+deb10u9.debian.tar.xz
|
||||
Upstream patch https://downloads.isc.org/isc/bind9/9.16.42/patches/0001-CVE-2023-2828.patch]
|
||||
Upstream Commit: https://github.com/isc-projects/bind9/commit/da0eafcdee52147e72d407cc3b9f179378ee1d3a
|
||||
CVE: CVE-2023-2828
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
|
||||
---
|
||||
lib/dns/rbtdb.c | 106 +++++++++++++++++++++++++++++++++-----------------------
|
||||
1 file changed, 63 insertions(+), 43 deletions(-)
|
||||
|
||||
diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c
|
||||
index b1b928c..3165e26 100644
|
||||
--- a/lib/dns/rbtdb.c
|
||||
+++ b/lib/dns/rbtdb.c
|
||||
@@ -792,7 +792,7 @@ static void update_header(dns_rbtdb_t *rbtdb, rdatasetheader_t *header,
|
||||
static void expire_header(dns_rbtdb_t *rbtdb, rdatasetheader_t *header,
|
||||
bool tree_locked, expire_t reason);
|
||||
static void overmem_purge(dns_rbtdb_t *rbtdb, unsigned int locknum_start,
|
||||
- isc_stdtime_t now, bool tree_locked);
|
||||
+ size_t purgesize, bool tree_locked);
|
||||
static isc_result_t resign_insert(dns_rbtdb_t *rbtdb, int idx,
|
||||
rdatasetheader_t *newheader);
|
||||
static void resign_delete(dns_rbtdb_t *rbtdb, rbtdb_version_t *version,
|
||||
@@ -6784,6 +6784,16 @@ addclosest(dns_rbtdb_t *rbtdb, rdatasetheader_t *newheader,
|
||||
|
||||
static dns_dbmethods_t zone_methods;
|
||||
|
||||
+static size_t
|
||||
+rdataset_size(rdatasetheader_t *header) {
|
||||
+ if (!NONEXISTENT(header)) {
|
||||
+ return (dns_rdataslab_size((unsigned char *)header,
|
||||
+ sizeof(*header)));
|
||||
+ }
|
||||
+
|
||||
+ return (sizeof(*header));
|
||||
+}
|
||||
+
|
||||
static isc_result_t
|
||||
addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
||||
isc_stdtime_t now, dns_rdataset_t *rdataset, unsigned int options,
|
||||
@@ -6932,7 +6942,8 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
||||
}
|
||||
|
||||
if (cache_is_overmem)
|
||||
- overmem_purge(rbtdb, rbtnode->locknum, now, tree_locked);
|
||||
+ overmem_purge(rbtdb, rbtnode->locknum, rdataset_size(newheader),
|
||||
+ tree_locked);
|
||||
|
||||
NODE_LOCK(&rbtdb->node_locks[rbtnode->locknum].lock,
|
||||
isc_rwlocktype_write);
|
||||
@@ -6947,9 +6958,14 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
|
||||
cleanup_dead_nodes(rbtdb, rbtnode->locknum);
|
||||
|
||||
header = isc_heap_element(rbtdb->heaps[rbtnode->locknum], 1);
|
||||
- if (header && header->rdh_ttl < now - RBTDB_VIRTUAL)
|
||||
- expire_header(rbtdb, header, tree_locked,
|
||||
- expire_ttl);
|
||||
+ if (header != NULL) {
|
||||
+ dns_ttl_t rdh_ttl = header->rdh_ttl;
|
||||
+
|
||||
+ if (rdh_ttl < now - RBTDB_VIRTUAL) {
|
||||
+ expire_header(rbtdb, header, tree_locked,
|
||||
+ expire_ttl);
|
||||
+ }
|
||||
+ }
|
||||
|
||||
/*
|
||||
* If we've been holding a write lock on the tree just for
|
||||
@@ -10388,54 +10404,58 @@ update_header(dns_rbtdb_t *rbtdb, rdatasetheader_t *header,
|
||||
ISC_LIST_PREPEND(rbtdb->rdatasets[header->node->locknum], header, link);
|
||||
}
|
||||
|
||||
+static size_t
|
||||
+expire_lru_headers(dns_rbtdb_t *rbtdb, unsigned int locknum, size_t purgesize,
|
||||
+ bool tree_locked) {
|
||||
+ rdatasetheader_t *header, *header_prev;
|
||||
+ size_t purged = 0;
|
||||
+
|
||||
+ for (header = ISC_LIST_TAIL(rbtdb->rdatasets[locknum]);
|
||||
+ header != NULL && purged <= purgesize; header = header_prev)
|
||||
+ {
|
||||
+ header_prev = ISC_LIST_PREV(header, link);
|
||||
+ /*
|
||||
+ * Unlink the entry at this point to avoid checking it
|
||||
+ * again even if it's currently used someone else and
|
||||
+ * cannot be purged at this moment. This entry won't be
|
||||
+ * referenced any more (so unlinking is safe) since the
|
||||
+ * TTL was reset to 0.
|
||||
+ */
|
||||
+ ISC_LIST_UNLINK(rbtdb->rdatasets[locknum], header, link);
|
||||
+ size_t header_size = rdataset_size(header);
|
||||
+ expire_header(rbtdb, header, tree_locked, expire_lru);
|
||||
+ purged += header_size;
|
||||
+ }
|
||||
+
|
||||
+ return (purged);
|
||||
+}
|
||||
+
|
||||
/*%
|
||||
- * Purge some expired and/or stale (i.e. unused for some period) cache entries
|
||||
- * under an overmem condition. To recover from this condition quickly, up to
|
||||
- * 2 entries will be purged. This process is triggered while adding a new
|
||||
- * entry, and we specifically avoid purging entries in the same LRU bucket as
|
||||
- * the one to which the new entry will belong. Otherwise, we might purge
|
||||
- * entries of the same name of different RR types while adding RRsets from a
|
||||
- * single response (consider the case where we're adding A and AAAA glue records
|
||||
- * of the same NS name).
|
||||
- */
|
||||
+ * Purge some stale (i.e. unused for some period - LRU based cleaning) cache
|
||||
+ * entries under the overmem condition. To recover from this condition quickly,
|
||||
+ * we cleanup entries up to the size of newly added rdata (passed as purgesize).
|
||||
+ *
|
||||
+ * This process is triggered while adding a new entry, and we specifically avoid
|
||||
+ * purging entries in the same LRU bucket as the one to which the new entry will
|
||||
+ * belong. Otherwise, we might purge entries of the same name of different RR
|
||||
+ * types while adding RRsets from a single response (consider the case where
|
||||
+ * we're adding A and AAAA glue records of the same NS name).
|
||||
+*/
|
||||
static void
|
||||
-overmem_purge(dns_rbtdb_t *rbtdb, unsigned int locknum_start,
|
||||
- isc_stdtime_t now, bool tree_locked)
|
||||
+overmem_purge(dns_rbtdb_t *rbtdb, unsigned int locknum_start, size_t purgesize,
|
||||
+ bool tree_locked)
|
||||
{
|
||||
- rdatasetheader_t *header, *header_prev;
|
||||
unsigned int locknum;
|
||||
- int purgecount = 2;
|
||||
+ size_t purged = 0;
|
||||
|
||||
for (locknum = (locknum_start + 1) % rbtdb->node_lock_count;
|
||||
- locknum != locknum_start && purgecount > 0;
|
||||
+ locknum != locknum_start && purged <= purgesize;
|
||||
locknum = (locknum + 1) % rbtdb->node_lock_count) {
|
||||
NODE_LOCK(&rbtdb->node_locks[locknum].lock,
|
||||
isc_rwlocktype_write);
|
||||
|
||||
- header = isc_heap_element(rbtdb->heaps[locknum], 1);
|
||||
- if (header && header->rdh_ttl < now - RBTDB_VIRTUAL) {
|
||||
- expire_header(rbtdb, header, tree_locked,
|
||||
- expire_ttl);
|
||||
- purgecount--;
|
||||
- }
|
||||
-
|
||||
- for (header = ISC_LIST_TAIL(rbtdb->rdatasets[locknum]);
|
||||
- header != NULL && purgecount > 0;
|
||||
- header = header_prev) {
|
||||
- header_prev = ISC_LIST_PREV(header, link);
|
||||
- /*
|
||||
- * Unlink the entry at this point to avoid checking it
|
||||
- * again even if it's currently used someone else and
|
||||
- * cannot be purged at this moment. This entry won't be
|
||||
- * referenced any more (so unlinking is safe) since the
|
||||
- * TTL was reset to 0.
|
||||
- */
|
||||
- ISC_LIST_UNLINK(rbtdb->rdatasets[locknum], header,
|
||||
- link);
|
||||
- expire_header(rbtdb, header, tree_locked,
|
||||
- expire_lru);
|
||||
- purgecount--;
|
||||
- }
|
||||
+ purged += expire_lru_headers(rbtdb, locknum, purgesize - purged,
|
||||
+ tree_locked);
|
||||
|
||||
NODE_UNLOCK(&rbtdb->node_locks[locknum].lock,
|
||||
isc_rwlocktype_write);
|
||||
@@ -22,6 +22,7 @@ SRC_URI = "https://ftp.isc.org/isc/bind9/${PV}/${BPN}-${PV}.tar.gz \
|
||||
file://CVE-2022-2795.patch \
|
||||
file://CVE-2022-38177.patch \
|
||||
file://CVE-2022-38178.patch \
|
||||
file://CVE-2023-2828.patch \
|
||||
"
|
||||
|
||||
SRC_URI[sha256sum] = "0d8efbe7ec166ada90e46add4267b7e7c934790cba9bd5af6b8380a4fbfb5aff"
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
From 703418fe9d2e3b1e8d594df5788d8001a8116265 Mon Sep 17 00:00:00 2001
|
||||
From: Jeffrey Bencteux <jeffbencteux@gmail.com>
|
||||
Date: Fri, 30 Jun 2023 19:02:45 +0200
|
||||
Subject: [PATCH] CVE-2023-40303: ftpd,rcp,rlogin,rsh,rshd,uucpd: fix: check
|
||||
set*id() return values
|
||||
|
||||
Several setuid(), setgid(), seteuid() and setguid() return values
|
||||
were not checked in ftpd/rcp/rlogin/rsh/rshd/uucpd code potentially
|
||||
leading to potential security issues.
|
||||
|
||||
CVE: CVE-2023-40303
|
||||
Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=e4e65c03f4c11292a3e40ef72ca3f194c8bffdd6]
|
||||
Signed-off-by: Jeffrey Bencteux <jeffbencteux@gmail.com>
|
||||
Signed-off-by: Simon Josefsson <simon@josefsson.org>
|
||||
Signed-off-by: Khem Raj <raj.khem@gmail.com>
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
ftpd/ftpd.c | 10 +++++++---
|
||||
src/rcp.c | 39 +++++++++++++++++++++++++++++++++------
|
||||
src/rlogin.c | 11 +++++++++--
|
||||
src/rsh.c | 25 +++++++++++++++++++++----
|
||||
src/rshd.c | 20 +++++++++++++++++---
|
||||
src/uucpd.c | 15 +++++++++++++--
|
||||
6 files changed, 100 insertions(+), 20 deletions(-)
|
||||
|
||||
diff --git a/ftpd/ftpd.c b/ftpd/ftpd.c
|
||||
index 5db88d0..b52b122 100644
|
||||
--- a/ftpd/ftpd.c
|
||||
+++ b/ftpd/ftpd.c
|
||||
@@ -862,7 +862,9 @@ end_login (struct credentials *pcred)
|
||||
char *remotehost = pcred->remotehost;
|
||||
int atype = pcred->auth_type;
|
||||
|
||||
- seteuid ((uid_t) 0);
|
||||
+ if (seteuid ((uid_t) 0) == -1)
|
||||
+ _exit (EXIT_FAILURE);
|
||||
+
|
||||
if (pcred->logged_in)
|
||||
{
|
||||
logwtmp_keep_open (ttyline, "", "");
|
||||
@@ -1151,7 +1153,8 @@ getdatasock (const char *mode)
|
||||
|
||||
if (data >= 0)
|
||||
return fdopen (data, mode);
|
||||
- seteuid ((uid_t) 0);
|
||||
+ if (seteuid ((uid_t) 0) == -1)
|
||||
+ _exit (EXIT_FAILURE);
|
||||
s = socket (ctrl_addr.ss_family, SOCK_STREAM, 0);
|
||||
if (s < 0)
|
||||
goto bad;
|
||||
@@ -1978,7 +1981,8 @@ passive (int epsv, int af)
|
||||
else /* !AF_INET6 */
|
||||
((struct sockaddr_in *) &pasv_addr)->sin_port = 0;
|
||||
|
||||
- seteuid ((uid_t) 0);
|
||||
+ if (seteuid ((uid_t) 0) == -1)
|
||||
+ _exit (EXIT_FAILURE);
|
||||
if (bind (pdata, (struct sockaddr *) &pasv_addr, pasv_addrlen) < 0)
|
||||
{
|
||||
if (seteuid ((uid_t) cred.uid))
|
||||
diff --git a/src/rcp.c b/src/rcp.c
|
||||
index bafa35f..366295c 100644
|
||||
--- a/src/rcp.c
|
||||
+++ b/src/rcp.c
|
||||
@@ -347,14 +347,23 @@ main (int argc, char *argv[])
|
||||
if (from_option)
|
||||
{ /* Follow "protocol", send data. */
|
||||
response ();
|
||||
- setuid (userid);
|
||||
+
|
||||
+ if (setuid (userid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
+
|
||||
source (argc, argv);
|
||||
exit (errs);
|
||||
}
|
||||
|
||||
if (to_option)
|
||||
{ /* Receive data. */
|
||||
- setuid (userid);
|
||||
+ if (setuid (userid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
+
|
||||
sink (argc, argv);
|
||||
exit (errs);
|
||||
}
|
||||
@@ -539,7 +548,11 @@ toremote (char *targ, int argc, char *argv[])
|
||||
if (response () < 0)
|
||||
exit (EXIT_FAILURE);
|
||||
free (bp);
|
||||
- setuid (userid);
|
||||
+
|
||||
+ if (setuid (userid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
}
|
||||
source (1, argv + i);
|
||||
close (rem);
|
||||
@@ -634,7 +647,12 @@ tolocal (int argc, char *argv[])
|
||||
++errs;
|
||||
continue;
|
||||
}
|
||||
- seteuid (userid);
|
||||
+
|
||||
+ if (seteuid (userid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (seteuid() failed)");
|
||||
+ }
|
||||
+
|
||||
#if defined IP_TOS && defined IPPROTO_IP && defined IPTOS_THROUGHPUT
|
||||
sslen = sizeof (ss);
|
||||
(void) getpeername (rem, (struct sockaddr *) &ss, &sslen);
|
||||
@@ -647,7 +665,12 @@ tolocal (int argc, char *argv[])
|
||||
#endif
|
||||
vect[0] = target;
|
||||
sink (1, vect);
|
||||
- seteuid (effuid);
|
||||
+
|
||||
+ if (seteuid (effuid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (seteuid() failed)");
|
||||
+ }
|
||||
+
|
||||
close (rem);
|
||||
rem = -1;
|
||||
#ifdef SHISHI
|
||||
@@ -1453,7 +1476,11 @@ susystem (char *s, int userid)
|
||||
return (127);
|
||||
|
||||
case 0:
|
||||
- setuid (userid);
|
||||
+ if (setuid (userid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
+
|
||||
execl (PATH_BSHELL, "sh", "-c", s, NULL);
|
||||
_exit (127);
|
||||
}
|
||||
diff --git a/src/rlogin.c b/src/rlogin.c
|
||||
index e5e11a7..6b38901 100644
|
||||
--- a/src/rlogin.c
|
||||
+++ b/src/rlogin.c
|
||||
@@ -649,8 +649,15 @@ try_connect:
|
||||
/* Now change to the real user ID. We have to be set-user-ID root
|
||||
to get the privileged port that rcmd () uses. We now want, however,
|
||||
to run as the real user who invoked us. */
|
||||
- seteuid (uid);
|
||||
- setuid (uid);
|
||||
+ if (seteuid (uid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (seteuid() failed)");
|
||||
+ }
|
||||
+
|
||||
+ if (setuid (uid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
|
||||
doit (&osmask); /* The old mask will activate SIGURG and SIGUSR1! */
|
||||
|
||||
diff --git a/src/rsh.c b/src/rsh.c
|
||||
index bd70372..b451a70 100644
|
||||
--- a/src/rsh.c
|
||||
+++ b/src/rsh.c
|
||||
@@ -278,8 +278,17 @@ main (int argc, char **argv)
|
||||
{
|
||||
if (asrsh)
|
||||
*argv = (char *) "rlogin";
|
||||
- seteuid (getuid ());
|
||||
- setuid (getuid ());
|
||||
+
|
||||
+ if (seteuid (getuid ()) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, errno, "seteuid() failed");
|
||||
+ }
|
||||
+
|
||||
+ if (setuid (getuid ()) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, errno, "setuid() failed");
|
||||
+ }
|
||||
+
|
||||
execv (PATH_RLOGIN, argv);
|
||||
error (EXIT_FAILURE, errno, "cannot execute %s", PATH_RLOGIN);
|
||||
}
|
||||
@@ -543,8 +552,16 @@ try_connect:
|
||||
error (0, errno, "setsockopt DEBUG (ignored)");
|
||||
}
|
||||
|
||||
- seteuid (uid);
|
||||
- setuid (uid);
|
||||
+ if (seteuid (uid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, errno, "seteuid() failed");
|
||||
+ }
|
||||
+
|
||||
+ if (setuid (uid) == -1)
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, errno, "setuid() failed");
|
||||
+ }
|
||||
+
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset (&sigs);
|
||||
sigaddset (&sigs, SIGINT);
|
||||
diff --git a/src/rshd.c b/src/rshd.c
|
||||
index b824a10..8cdcd06 100644
|
||||
--- a/src/rshd.c
|
||||
+++ b/src/rshd.c
|
||||
@@ -1848,8 +1848,18 @@ doit (int sockfd, struct sockaddr *fromp, socklen_t fromlen)
|
||||
pwd->pw_shell = PATH_BSHELL;
|
||||
|
||||
/* Set the gid, then uid to become the user specified by "locuser" */
|
||||
- setegid ((gid_t) pwd->pw_gid);
|
||||
- setgid ((gid_t) pwd->pw_gid);
|
||||
+ if (setegid ((gid_t) pwd->pw_gid) == -1)
|
||||
+ {
|
||||
+ rshd_error ("Cannot drop privileges (setegid() failed)\n");
|
||||
+ exit (EXIT_FAILURE);
|
||||
+ }
|
||||
+
|
||||
+ if (setgid ((gid_t) pwd->pw_gid) == -1)
|
||||
+ {
|
||||
+ rshd_error ("Cannot drop privileges (setgid() failed)\n");
|
||||
+ exit (EXIT_FAILURE);
|
||||
+ }
|
||||
+
|
||||
#ifdef HAVE_INITGROUPS
|
||||
initgroups (pwd->pw_name, pwd->pw_gid); /* BSD groups */
|
||||
#endif
|
||||
@@ -1871,7 +1881,11 @@ doit (int sockfd, struct sockaddr *fromp, socklen_t fromlen)
|
||||
}
|
||||
#endif /* WITH_PAM */
|
||||
|
||||
- setuid ((uid_t) pwd->pw_uid);
|
||||
+ if (setuid ((uid_t) pwd->pw_uid) == -1)
|
||||
+ {
|
||||
+ rshd_error ("Cannot drop privileges (setuid() failed)\n");
|
||||
+ exit (EXIT_FAILURE);
|
||||
+ }
|
||||
|
||||
/* We'll execute the client's command in the home directory
|
||||
* of locuser. Note, that the chdir must be executed after
|
||||
diff --git a/src/uucpd.c b/src/uucpd.c
|
||||
index 55c3d44..6aba294 100644
|
||||
--- a/src/uucpd.c
|
||||
+++ b/src/uucpd.c
|
||||
@@ -254,7 +254,12 @@ doit (struct sockaddr *sap, socklen_t salen)
|
||||
sprintf (Username, "USER=%s", user);
|
||||
sprintf (Logname, "LOGNAME=%s", user);
|
||||
dologin (pw, sap, salen);
|
||||
- setgid (pw->pw_gid);
|
||||
+
|
||||
+ if (setgid (pw->pw_gid) == -1)
|
||||
+ {
|
||||
+ fprintf (stderr, "setgid() failed");
|
||||
+ return;
|
||||
+ }
|
||||
#ifdef HAVE_INITGROUPS
|
||||
initgroups (pw->pw_name, pw->pw_gid);
|
||||
#endif
|
||||
@@ -263,7 +268,13 @@ doit (struct sockaddr *sap, socklen_t salen)
|
||||
fprintf (stderr, "Login incorrect.");
|
||||
return;
|
||||
}
|
||||
- setuid (pw->pw_uid);
|
||||
+
|
||||
+ if (setuid (pw->pw_uid) == -1)
|
||||
+ {
|
||||
+ fprintf (stderr, "setuid() failed");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
execl (uucico_location, "uucico", NULL);
|
||||
perror ("uucico server: execl");
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
From 70fe022f9dac760eaece0228cad17e3d29a57fb8 Mon Sep 17 00:00:00 2001
|
||||
From: Simon Josefsson <simon@josefsson.org>
|
||||
Date: Mon, 31 Jul 2023 13:59:05 +0200
|
||||
Subject: [PATCH] CVE-2023-40303: Indent changes in previous commit.
|
||||
|
||||
CVE: CVE-2023-40303
|
||||
Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/inetutils.git/commit/?id=9122999252c7e21eb7774de11d539748e7bdf46d]
|
||||
Signed-off-by: Khem Raj <raj.khem@gmail.com>
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/rcp.c | 42 ++++++++++++++++++++++++------------------
|
||||
src/rlogin.c | 12 ++++++------
|
||||
src/rsh.c | 24 ++++++++++++------------
|
||||
src/rshd.c | 24 ++++++++++++------------
|
||||
src/uucpd.c | 16 ++++++++--------
|
||||
5 files changed, 62 insertions(+), 56 deletions(-)
|
||||
|
||||
diff --git a/src/rcp.c b/src/rcp.c
|
||||
index cdcf8500..652f22e6 100644
|
||||
--- a/src/rcp.c
|
||||
+++ b/src/rcp.c
|
||||
@@ -347,9 +347,10 @@ main (int argc, char *argv[])
|
||||
response ();
|
||||
|
||||
if (setuid (userid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0,
|
||||
+ "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
|
||||
source (argc, argv);
|
||||
exit (errs);
|
||||
@@ -358,9 +359,10 @@ main (int argc, char *argv[])
|
||||
if (to_option)
|
||||
{ /* Receive data. */
|
||||
if (setuid (userid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0,
|
||||
+ "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
|
||||
sink (argc, argv);
|
||||
exit (errs);
|
||||
@@ -548,9 +550,10 @@ toremote (char *targ, int argc, char *argv[])
|
||||
free (bp);
|
||||
|
||||
if (setuid (userid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0,
|
||||
+ "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
}
|
||||
source (1, argv + i);
|
||||
close (rem);
|
||||
@@ -645,9 +648,10 @@ tolocal (int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (seteuid (userid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, 0, "Could not drop privileges (seteuid() failed)");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0,
|
||||
+ "Could not drop privileges (seteuid() failed)");
|
||||
+ }
|
||||
|
||||
#if defined IP_TOS && defined IPPROTO_IP && defined IPTOS_THROUGHPUT
|
||||
sslen = sizeof (ss);
|
||||
@@ -663,9 +667,10 @@ tolocal (int argc, char *argv[])
|
||||
sink (1, vect);
|
||||
|
||||
if (seteuid (effuid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, 0, "Could not drop privileges (seteuid() failed)");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0,
|
||||
+ "Could not drop privileges (seteuid() failed)");
|
||||
+ }
|
||||
|
||||
close (rem);
|
||||
rem = -1;
|
||||
@@ -1465,9 +1470,10 @@ susystem (char *s, int userid)
|
||||
|
||||
case 0:
|
||||
if (setuid (userid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0,
|
||||
+ "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
|
||||
execl (PATH_BSHELL, "sh", "-c", s, NULL);
|
||||
_exit (127);
|
||||
diff --git a/src/rlogin.c b/src/rlogin.c
|
||||
index c543de0c..4360202f 100644
|
||||
--- a/src/rlogin.c
|
||||
+++ b/src/rlogin.c
|
||||
@@ -648,14 +648,14 @@ try_connect:
|
||||
to get the privileged port that rcmd () uses. We now want, however,
|
||||
to run as the real user who invoked us. */
|
||||
if (seteuid (uid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, 0, "Could not drop privileges (seteuid() failed)");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (seteuid() failed)");
|
||||
+ }
|
||||
|
||||
if (setuid (uid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, 0, "Could not drop privileges (setuid() failed)");
|
||||
+ }
|
||||
|
||||
doit (&osmask); /* The old mask will activate SIGURG and SIGUSR1! */
|
||||
|
||||
diff --git a/src/rsh.c b/src/rsh.c
|
||||
index 6f60667d..179b47cd 100644
|
||||
--- a/src/rsh.c
|
||||
+++ b/src/rsh.c
|
||||
@@ -278,14 +278,14 @@ main (int argc, char **argv)
|
||||
*argv = (char *) "rlogin";
|
||||
|
||||
if (seteuid (getuid ()) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, errno, "seteuid() failed");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, errno, "seteuid() failed");
|
||||
+ }
|
||||
|
||||
if (setuid (getuid ()) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, errno, "setuid() failed");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, errno, "setuid() failed");
|
||||
+ }
|
||||
|
||||
execv (PATH_RLOGIN, argv);
|
||||
error (EXIT_FAILURE, errno, "cannot execute %s", PATH_RLOGIN);
|
||||
@@ -551,14 +551,14 @@ try_connect:
|
||||
}
|
||||
|
||||
if (seteuid (uid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, errno, "seteuid() failed");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, errno, "seteuid() failed");
|
||||
+ }
|
||||
|
||||
if (setuid (uid) == -1)
|
||||
- {
|
||||
- error (EXIT_FAILURE, errno, "setuid() failed");
|
||||
- }
|
||||
+ {
|
||||
+ error (EXIT_FAILURE, errno, "setuid() failed");
|
||||
+ }
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
sigemptyset (&sigs);
|
||||
diff --git a/src/rshd.c b/src/rshd.c
|
||||
index 707790e7..3a153a18 100644
|
||||
--- a/src/rshd.c
|
||||
+++ b/src/rshd.c
|
||||
@@ -1848,16 +1848,16 @@ doit (int sockfd, struct sockaddr *fromp, socklen_t fromlen)
|
||||
|
||||
/* Set the gid, then uid to become the user specified by "locuser" */
|
||||
if (setegid ((gid_t) pwd->pw_gid) == -1)
|
||||
- {
|
||||
- rshd_error ("Cannot drop privileges (setegid() failed)\n");
|
||||
- exit (EXIT_FAILURE);
|
||||
- }
|
||||
+ {
|
||||
+ rshd_error ("Cannot drop privileges (setegid() failed)\n");
|
||||
+ exit (EXIT_FAILURE);
|
||||
+ }
|
||||
|
||||
if (setgid ((gid_t) pwd->pw_gid) == -1)
|
||||
- {
|
||||
- rshd_error ("Cannot drop privileges (setgid() failed)\n");
|
||||
- exit (EXIT_FAILURE);
|
||||
- }
|
||||
+ {
|
||||
+ rshd_error ("Cannot drop privileges (setgid() failed)\n");
|
||||
+ exit (EXIT_FAILURE);
|
||||
+ }
|
||||
|
||||
#ifdef HAVE_INITGROUPS
|
||||
initgroups (pwd->pw_name, pwd->pw_gid); /* BSD groups */
|
||||
@@ -1881,10 +1881,10 @@ doit (int sockfd, struct sockaddr *fromp, socklen_t fromlen)
|
||||
#endif /* WITH_PAM */
|
||||
|
||||
if (setuid ((uid_t) pwd->pw_uid) == -1)
|
||||
- {
|
||||
- rshd_error ("Cannot drop privileges (setuid() failed)\n");
|
||||
- exit (EXIT_FAILURE);
|
||||
- }
|
||||
+ {
|
||||
+ rshd_error ("Cannot drop privileges (setuid() failed)\n");
|
||||
+ exit (EXIT_FAILURE);
|
||||
+ }
|
||||
|
||||
/* We'll execute the client's command in the home directory
|
||||
* of locuser. Note, that the chdir must be executed after
|
||||
diff --git a/src/uucpd.c b/src/uucpd.c
|
||||
index 29cfce35..fde7b9c9 100644
|
||||
--- a/src/uucpd.c
|
||||
+++ b/src/uucpd.c
|
||||
@@ -254,10 +254,10 @@ doit (struct sockaddr *sap, socklen_t salen)
|
||||
dologin (pw, sap, salen);
|
||||
|
||||
if (setgid (pw->pw_gid) == -1)
|
||||
- {
|
||||
- fprintf (stderr, "setgid() failed");
|
||||
- return;
|
||||
- }
|
||||
+ {
|
||||
+ fprintf (stderr, "setgid() failed");
|
||||
+ return;
|
||||
+ }
|
||||
#ifdef HAVE_INITGROUPS
|
||||
initgroups (pw->pw_name, pw->pw_gid);
|
||||
#endif
|
||||
@@ -268,10 +268,10 @@ doit (struct sockaddr *sap, socklen_t salen)
|
||||
}
|
||||
|
||||
if (setuid (pw->pw_uid) == -1)
|
||||
- {
|
||||
- fprintf (stderr, "setuid() failed");
|
||||
- return;
|
||||
- }
|
||||
+ {
|
||||
+ fprintf (stderr, "setuid() failed");
|
||||
+ return;
|
||||
+ }
|
||||
|
||||
execl (uucico_location, "uucico", NULL);
|
||||
perror ("uucico server: execl");
|
||||
@@ -25,6 +25,8 @@ SRC_URI = "${GNU_MIRROR}/inetutils/inetutils-${PV}.tar.gz \
|
||||
file://fix-buffer-fortify-tfpt.patch \
|
||||
file://CVE-2021-40491.patch \
|
||||
file://CVE-2022-39028.patch \
|
||||
file://0001-CVE-2023-40303-ftpd-rcp-rlogin-rsh-rshd-uucpd-fix-ch.patch \
|
||||
file://0002-CVE-2023-40303-Indent-changes-in-previous-commit.patch \
|
||||
"
|
||||
|
||||
SRC_URI[md5sum] = "04852c26c47cc8c6b825f2b74f191f52"
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
From f6213e03887237714eb5bcfc9089c707069f87c5 Mon Sep 17 00:00:00 2001
|
||||
From: Damien Miller <djm@mindrot.org>
|
||||
Date: Fri, 1 Oct 2021 16:35:49 +1000
|
||||
Subject: [PATCH 01/12] make OPENSSL_HAS_ECC checks more thorough
|
||||
|
||||
ok dtucker
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/dee22129bbc61e25b1003adfa2bc584c5406ef2d]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-pkcs11-client.c | 16 ++++++++--------
|
||||
ssh-pkcs11.c | 26 +++++++++++++-------------
|
||||
2 files changed, 21 insertions(+), 21 deletions(-)
|
||||
|
||||
diff --git a/ssh-pkcs11-client.c b/ssh-pkcs11-client.c
|
||||
index 8a0ffef..41114c7 100644
|
||||
--- a/ssh-pkcs11-client.c
|
||||
+++ b/ssh-pkcs11-client.c
|
||||
@@ -163,7 +163,7 @@ rsa_encrypt(int flen, const u_char *from, u_char *to, RSA *rsa, int padding)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
static ECDSA_SIG *
|
||||
ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
|
||||
const BIGNUM *rp, EC_KEY *ec)
|
||||
@@ -220,12 +220,12 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
|
||||
sshbuf_free(msg);
|
||||
return (ret);
|
||||
}
|
||||
-#endif /* HAVE_EC_KEY_METHOD_NEW */
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
|
||||
static RSA_METHOD *helper_rsa;
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
static EC_KEY_METHOD *helper_ecdsa;
|
||||
-#endif /* HAVE_EC_KEY_METHOD_NEW */
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
|
||||
/* redirect private key crypto operations to the ssh-pkcs11-helper */
|
||||
static void
|
||||
@@ -233,10 +233,10 @@ wrap_key(struct sshkey *k)
|
||||
{
|
||||
if (k->type == KEY_RSA)
|
||||
RSA_set_method(k->rsa, helper_rsa);
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
else if (k->type == KEY_ECDSA)
|
||||
EC_KEY_set_method(k->ecdsa, helper_ecdsa);
|
||||
-#endif /* HAVE_EC_KEY_METHOD_NEW */
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
else
|
||||
fatal("%s: unknown key type", __func__);
|
||||
}
|
||||
@@ -247,7 +247,7 @@ pkcs11_start_helper_methods(void)
|
||||
if (helper_rsa != NULL)
|
||||
return (0);
|
||||
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
int (*orig_sign)(int, const unsigned char *, int, unsigned char *,
|
||||
unsigned int *, const BIGNUM *, const BIGNUM *, EC_KEY *) = NULL;
|
||||
if (helper_ecdsa != NULL)
|
||||
@@ -257,7 +257,7 @@ pkcs11_start_helper_methods(void)
|
||||
return (-1);
|
||||
EC_KEY_METHOD_get_sign(helper_ecdsa, &orig_sign, NULL, NULL);
|
||||
EC_KEY_METHOD_set_sign(helper_ecdsa, orig_sign, NULL, ecdsa_do_sign);
|
||||
-#endif /* HAVE_EC_KEY_METHOD_NEW */
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
|
||||
if ((helper_rsa = RSA_meth_dup(RSA_get_default_method())) == NULL)
|
||||
fatal("%s: RSA_meth_dup failed", __func__);
|
||||
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c
|
||||
index a302c79..b56a41b 100644
|
||||
--- a/ssh-pkcs11.c
|
||||
+++ b/ssh-pkcs11.c
|
||||
@@ -78,7 +78,7 @@ struct pkcs11_key {
|
||||
|
||||
int pkcs11_interactive = 0;
|
||||
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
static void
|
||||
ossl_error(const char *msg)
|
||||
{
|
||||
@@ -89,7 +89,7 @@ ossl_error(const char *msg)
|
||||
error("%s: libcrypto error: %.100s", __func__,
|
||||
ERR_error_string(e, NULL));
|
||||
}
|
||||
-#endif /* HAVE_EC_KEY_METHOD_NEW */
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
|
||||
int
|
||||
pkcs11_init(int interactive)
|
||||
@@ -190,10 +190,10 @@ pkcs11_del_provider(char *provider_id)
|
||||
|
||||
static RSA_METHOD *rsa_method;
|
||||
static int rsa_idx = 0;
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
static EC_KEY_METHOD *ec_key_method;
|
||||
static int ec_key_idx = 0;
|
||||
-#endif
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
|
||||
/* release a wrapped object */
|
||||
static void
|
||||
@@ -492,7 +492,7 @@ pkcs11_rsa_wrap(struct pkcs11_provider *provider, CK_ULONG slotidx,
|
||||
return (0);
|
||||
}
|
||||
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
/* openssl callback doing the actual signing operation */
|
||||
static ECDSA_SIG *
|
||||
ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
|
||||
@@ -604,7 +604,7 @@ pkcs11_ecdsa_wrap(struct pkcs11_provider *provider, CK_ULONG slotidx,
|
||||
|
||||
return (0);
|
||||
}
|
||||
-#endif /* HAVE_EC_KEY_METHOD_NEW */
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
|
||||
/* remove trailing spaces */
|
||||
static void
|
||||
@@ -679,7 +679,7 @@ pkcs11_key_included(struct sshkey ***keysp, int *nkeys, struct sshkey *key)
|
||||
return (0);
|
||||
}
|
||||
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
static struct sshkey *
|
||||
pkcs11_fetch_ecdsa_pubkey(struct pkcs11_provider *p, CK_ULONG slotidx,
|
||||
CK_OBJECT_HANDLE *obj)
|
||||
@@ -802,7 +802,7 @@ fail:
|
||||
|
||||
return (key);
|
||||
}
|
||||
-#endif /* HAVE_EC_KEY_METHOD_NEW */
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
|
||||
static struct sshkey *
|
||||
pkcs11_fetch_rsa_pubkey(struct pkcs11_provider *p, CK_ULONG slotidx,
|
||||
@@ -910,7 +910,7 @@ pkcs11_fetch_x509_pubkey(struct pkcs11_provider *p, CK_ULONG slotidx,
|
||||
#endif
|
||||
struct sshkey *key = NULL;
|
||||
int i;
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
int nid;
|
||||
#endif
|
||||
const u_char *cp;
|
||||
@@ -999,7 +999,7 @@ pkcs11_fetch_x509_pubkey(struct pkcs11_provider *p, CK_ULONG slotidx,
|
||||
key->type = KEY_RSA;
|
||||
key->flags |= SSHKEY_FLAG_EXT;
|
||||
rsa = NULL; /* now owned by key */
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
} else if (EVP_PKEY_base_id(evp) == EVP_PKEY_EC) {
|
||||
if (EVP_PKEY_get0_EC_KEY(evp) == NULL) {
|
||||
error("invalid x509; no ec key");
|
||||
@@ -1030,7 +1030,7 @@ pkcs11_fetch_x509_pubkey(struct pkcs11_provider *p, CK_ULONG slotidx,
|
||||
key->type = KEY_ECDSA;
|
||||
key->flags |= SSHKEY_FLAG_EXT;
|
||||
ec = NULL; /* now owned by key */
|
||||
-#endif /* HAVE_EC_KEY_METHOD_NEW */
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
} else {
|
||||
error("unknown certificate key type");
|
||||
goto out;
|
||||
@@ -1237,11 +1237,11 @@ pkcs11_fetch_keys(struct pkcs11_provider *p, CK_ULONG slotidx,
|
||||
case CKK_RSA:
|
||||
key = pkcs11_fetch_rsa_pubkey(p, slotidx, &obj);
|
||||
break;
|
||||
-#ifdef HAVE_EC_KEY_METHOD_NEW
|
||||
+#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
case CKK_ECDSA:
|
||||
key = pkcs11_fetch_ecdsa_pubkey(p, slotidx, &obj);
|
||||
break;
|
||||
-#endif /* HAVE_EC_KEY_METHOD_NEW */
|
||||
+#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
default:
|
||||
/* XXX print key type? */
|
||||
key = NULL;
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,581 @@
|
||||
From 92cebfbcc221c9ef3f6bbb78da3d7699c0ae56be Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Wed, 19 Jul 2023 14:03:45 +0000
|
||||
Subject: [PATCH 02/12] upstream: Separate ssh-pkcs11-helpers for each p11
|
||||
module
|
||||
|
||||
Make ssh-pkcs11-client start an independent helper for each provider,
|
||||
providing better isolation between modules and reliability if a single
|
||||
module misbehaves.
|
||||
|
||||
This also implements reference counting of PKCS#11-hosted keys,
|
||||
allowing ssh-pkcs11-helper subprocesses to be automatically reaped
|
||||
when no remaining keys reference them. This fixes some bugs we have
|
||||
that make PKCS11 keys unusable after they have been deleted, e.g.
|
||||
https://bugzilla.mindrot.org/show_bug.cgi?id=3125
|
||||
|
||||
ok markus@
|
||||
|
||||
OpenBSD-Commit-ID: 0ce188b14fe271ab0568f4500070d96c5657244e
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/099cdf59ce1e72f55d421c8445bf6321b3004755]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-pkcs11-client.c | 372 +++++++++++++++++++++++++++++++++-----------
|
||||
1 file changed, 282 insertions(+), 90 deletions(-)
|
||||
|
||||
diff --git a/ssh-pkcs11-client.c b/ssh-pkcs11-client.c
|
||||
index 41114c7..4f3c6ed 100644
|
||||
--- a/ssh-pkcs11-client.c
|
||||
+++ b/ssh-pkcs11-client.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/* $OpenBSD: ssh-pkcs11-client.c,v 1.16 2020/01/25 00:03:36 djm Exp $ */
|
||||
+/* $OpenBSD: ssh-pkcs11-client.c,v 1.18 2023/07/19 14:03:45 djm Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2010 Markus Friedl. All rights reserved.
|
||||
* Copyright (c) 2014 Pedro Martelletto. All rights reserved.
|
||||
@@ -30,12 +30,11 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
+#include <limits.h>
|
||||
|
||||
#include <openssl/ecdsa.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
-#include "openbsd-compat/openssl-compat.h"
|
||||
-
|
||||
#include "pathnames.h"
|
||||
#include "xmalloc.h"
|
||||
#include "sshbuf.h"
|
||||
@@ -47,18 +46,140 @@
|
||||
#include "ssh-pkcs11.h"
|
||||
#include "ssherr.h"
|
||||
|
||||
+#include "openbsd-compat/openssl-compat.h"
|
||||
+
|
||||
/* borrows code from sftp-server and ssh-agent */
|
||||
|
||||
-static int fd = -1;
|
||||
-static pid_t pid = -1;
|
||||
+/*
|
||||
+ * Maintain a list of ssh-pkcs11-helper subprocesses. These may be looked up
|
||||
+ * by provider path or their unique EC/RSA METHOD pointers.
|
||||
+ */
|
||||
+struct helper {
|
||||
+ char *path;
|
||||
+ pid_t pid;
|
||||
+ int fd;
|
||||
+ RSA_METHOD *rsa_meth;
|
||||
+ EC_KEY_METHOD *ec_meth;
|
||||
+ int (*rsa_finish)(RSA *rsa);
|
||||
+ void (*ec_finish)(EC_KEY *key);
|
||||
+ size_t nrsa, nec; /* number of active keys of each type */
|
||||
+};
|
||||
+static struct helper **helpers;
|
||||
+static size_t nhelpers;
|
||||
+
|
||||
+static struct helper *
|
||||
+helper_by_provider(const char *path)
|
||||
+{
|
||||
+ size_t i;
|
||||
+
|
||||
+ for (i = 0; i < nhelpers; i++) {
|
||||
+ if (helpers[i] == NULL || helpers[i]->path == NULL ||
|
||||
+ helpers[i]->fd == -1)
|
||||
+ continue;
|
||||
+ if (strcmp(helpers[i]->path, path) == 0)
|
||||
+ return helpers[i];
|
||||
+ }
|
||||
+ return NULL;
|
||||
+}
|
||||
+
|
||||
+static struct helper *
|
||||
+helper_by_rsa(const RSA *rsa)
|
||||
+{
|
||||
+ size_t i;
|
||||
+ const RSA_METHOD *meth;
|
||||
+
|
||||
+ if ((meth = RSA_get_method(rsa)) == NULL)
|
||||
+ return NULL;
|
||||
+ for (i = 0; i < nhelpers; i++) {
|
||||
+ if (helpers[i] != NULL && helpers[i]->rsa_meth == meth)
|
||||
+ return helpers[i];
|
||||
+ }
|
||||
+ return NULL;
|
||||
+
|
||||
+}
|
||||
+
|
||||
+static struct helper *
|
||||
+helper_by_ec(const EC_KEY *ec)
|
||||
+{
|
||||
+ size_t i;
|
||||
+ const EC_KEY_METHOD *meth;
|
||||
+
|
||||
+ if ((meth = EC_KEY_get_method(ec)) == NULL)
|
||||
+ return NULL;
|
||||
+ for (i = 0; i < nhelpers; i++) {
|
||||
+ if (helpers[i] != NULL && helpers[i]->ec_meth == meth)
|
||||
+ return helpers[i];
|
||||
+ }
|
||||
+ return NULL;
|
||||
+
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+helper_free(struct helper *helper)
|
||||
+{
|
||||
+ size_t i;
|
||||
+ int found = 0;
|
||||
+
|
||||
+ if (helper == NULL)
|
||||
+ return;
|
||||
+ if (helper->path == NULL || helper->ec_meth == NULL ||
|
||||
+ helper->rsa_meth == NULL)
|
||||
+ fatal("%s: inconsistent helper", __func__);
|
||||
+ debug3("%s: free helper for provider %s", __func__ , helper->path);
|
||||
+ for (i = 0; i < nhelpers; i++) {
|
||||
+ if (helpers[i] == helper) {
|
||||
+ if (found)
|
||||
+ fatal("%s: helper recorded more than once", __func__);
|
||||
+ found = 1;
|
||||
+ }
|
||||
+ else if (found)
|
||||
+ helpers[i - 1] = helpers[i];
|
||||
+ }
|
||||
+ if (found) {
|
||||
+ helpers = xrecallocarray(helpers, nhelpers,
|
||||
+ nhelpers - 1, sizeof(*helpers));
|
||||
+ nhelpers--;
|
||||
+ }
|
||||
+ free(helper->path);
|
||||
+ EC_KEY_METHOD_free(helper->ec_meth);
|
||||
+ RSA_meth_free(helper->rsa_meth);
|
||||
+ free(helper);
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+helper_terminate(struct helper *helper)
|
||||
+{
|
||||
+ if (helper == NULL) {
|
||||
+ return;
|
||||
+ } else if (helper->fd == -1) {
|
||||
+ debug3("%s: already terminated", __func__);
|
||||
+ } else {
|
||||
+ debug3("terminating helper for %s; "
|
||||
+ "remaining %zu RSA %zu ECDSA", __func__,
|
||||
+ helper->path, helper->nrsa, helper->nec);
|
||||
+ close(helper->fd);
|
||||
+ /* XXX waitpid() */
|
||||
+ helper->fd = -1;
|
||||
+ helper->pid = -1;
|
||||
+ }
|
||||
+ /*
|
||||
+ * Don't delete the helper entry until there are no remaining keys
|
||||
+ * that reference it. Otherwise, any signing operation would call
|
||||
+ * a free'd METHOD pointer and that would be bad.
|
||||
+ */
|
||||
+ if (helper->nrsa == 0 && helper->nec == 0)
|
||||
+ helper_free(helper);
|
||||
+}
|
||||
|
||||
static void
|
||||
-send_msg(struct sshbuf *m)
|
||||
+send_msg(int fd, struct sshbuf *m)
|
||||
{
|
||||
u_char buf[4];
|
||||
size_t mlen = sshbuf_len(m);
|
||||
int r;
|
||||
|
||||
+ if (fd == -1)
|
||||
+ return;
|
||||
POKE_U32(buf, mlen);
|
||||
if (atomicio(vwrite, fd, buf, 4) != 4 ||
|
||||
atomicio(vwrite, fd, sshbuf_mutable_ptr(m),
|
||||
@@ -69,12 +190,15 @@ send_msg(struct sshbuf *m)
|
||||
}
|
||||
|
||||
static int
|
||||
-recv_msg(struct sshbuf *m)
|
||||
+recv_msg(int fd, struct sshbuf *m)
|
||||
{
|
||||
u_int l, len;
|
||||
u_char c, buf[1024];
|
||||
int r;
|
||||
|
||||
+ sshbuf_reset(m);
|
||||
+ if (fd == -1)
|
||||
+ return 0; /* XXX */
|
||||
if ((len = atomicio(read, fd, buf, 4)) != 4) {
|
||||
error("read from helper failed: %u", len);
|
||||
return (0); /* XXX */
|
||||
@@ -83,7 +207,6 @@ recv_msg(struct sshbuf *m)
|
||||
if (len > 256 * 1024)
|
||||
fatal("response too long: %u", len);
|
||||
/* read len bytes into m */
|
||||
- sshbuf_reset(m);
|
||||
while (len > 0) {
|
||||
l = len;
|
||||
if (l > sizeof(buf))
|
||||
@@ -104,14 +227,17 @@ recv_msg(struct sshbuf *m)
|
||||
int
|
||||
pkcs11_init(int interactive)
|
||||
{
|
||||
- return (0);
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
void
|
||||
pkcs11_terminate(void)
|
||||
{
|
||||
- if (fd >= 0)
|
||||
- close(fd);
|
||||
+ size_t i;
|
||||
+
|
||||
+ debug3("%s: terminating %zu helpers", __func__, nhelpers);
|
||||
+ for (i = 0; i < nhelpers; i++)
|
||||
+ helper_terminate(helpers[i]);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -122,7 +248,11 @@ rsa_encrypt(int flen, const u_char *from, u_char *to, RSA *rsa, int padding)
|
||||
u_char *blob = NULL, *signature = NULL;
|
||||
size_t blen, slen = 0;
|
||||
int r, ret = -1;
|
||||
+ struct helper *helper;
|
||||
|
||||
+ if ((helper = helper_by_rsa(rsa)) == NULL || helper->fd == -1)
|
||||
+ fatal("%s: no helper for PKCS11 key", __func__);
|
||||
+ debug3("%s: signing with PKCS11 provider %s", __func__, helper->path);
|
||||
if (padding != RSA_PKCS1_PADDING)
|
||||
goto fail;
|
||||
key = sshkey_new(KEY_UNSPEC);
|
||||
@@ -144,10 +274,10 @@ rsa_encrypt(int flen, const u_char *from, u_char *to, RSA *rsa, int padding)
|
||||
(r = sshbuf_put_string(msg, from, flen)) != 0 ||
|
||||
(r = sshbuf_put_u32(msg, 0)) != 0)
|
||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
- send_msg(msg);
|
||||
+ send_msg(helper->fd, msg);
|
||||
sshbuf_reset(msg);
|
||||
|
||||
- if (recv_msg(msg) == SSH2_AGENT_SIGN_RESPONSE) {
|
||||
+ if (recv_msg(helper->fd, msg) == SSH2_AGENT_SIGN_RESPONSE) {
|
||||
if ((r = sshbuf_get_string(msg, &signature, &slen)) != 0)
|
||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
if (slen <= (size_t)RSA_size(rsa)) {
|
||||
@@ -163,7 +293,26 @@ rsa_encrypt(int flen, const u_char *from, u_char *to, RSA *rsa, int padding)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
-#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
+static int
|
||||
+rsa_finish(RSA *rsa)
|
||||
+{
|
||||
+ struct helper *helper;
|
||||
+
|
||||
+ if ((helper = helper_by_rsa(rsa)) == NULL)
|
||||
+ fatal("%s: no helper for PKCS11 key", __func__);
|
||||
+ debug3("%s: free PKCS11 RSA key for provider %s", __func__, helper->path);
|
||||
+ if (helper->rsa_finish != NULL)
|
||||
+ helper->rsa_finish(rsa);
|
||||
+ if (helper->nrsa == 0)
|
||||
+ fatal("%s: RSA refcount error", __func__);
|
||||
+ helper->nrsa--;
|
||||
+ debug3("%s: provider %s remaining keys: %zu RSA %zu ECDSA", __func__,
|
||||
+ helper->path, helper->nrsa, helper->nec);
|
||||
+ if (helper->nrsa == 0 && helper->nec == 0)
|
||||
+ helper_terminate(helper);
|
||||
+ return 1;
|
||||
+}
|
||||
+
|
||||
static ECDSA_SIG *
|
||||
ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
|
||||
const BIGNUM *rp, EC_KEY *ec)
|
||||
@@ -175,7 +324,11 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
|
||||
u_char *blob = NULL, *signature = NULL;
|
||||
size_t blen, slen = 0;
|
||||
int r, nid;
|
||||
+ struct helper *helper;
|
||||
|
||||
+ if ((helper = helper_by_ec(ec)) == NULL || helper->fd == -1)
|
||||
+ fatal("%s: no helper for PKCS11 key", __func__);
|
||||
+ debug3("%s: signing with PKCS11 provider %s", __func__, helper->path);
|
||||
nid = sshkey_ecdsa_key_to_nid(ec);
|
||||
if (nid < 0) {
|
||||
error("%s: couldn't get curve nid", __func__);
|
||||
@@ -203,10 +356,10 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
|
||||
(r = sshbuf_put_string(msg, dgst, dgst_len)) != 0 ||
|
||||
(r = sshbuf_put_u32(msg, 0)) != 0)
|
||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
- send_msg(msg);
|
||||
+ send_msg(helper->fd, msg);
|
||||
sshbuf_reset(msg);
|
||||
|
||||
- if (recv_msg(msg) == SSH2_AGENT_SIGN_RESPONSE) {
|
||||
+ if (recv_msg(helper->fd, msg) == SSH2_AGENT_SIGN_RESPONSE) {
|
||||
if ((r = sshbuf_get_string(msg, &signature, &slen)) != 0)
|
||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
cp = signature;
|
||||
@@ -220,75 +373,110 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv,
|
||||
sshbuf_free(msg);
|
||||
return (ret);
|
||||
}
|
||||
-#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
|
||||
-static RSA_METHOD *helper_rsa;
|
||||
-#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
-static EC_KEY_METHOD *helper_ecdsa;
|
||||
-#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
+static void
|
||||
+ecdsa_do_finish(EC_KEY *ec)
|
||||
+{
|
||||
+ struct helper *helper;
|
||||
+
|
||||
+ if ((helper = helper_by_ec(ec)) == NULL)
|
||||
+ fatal("%s: no helper for PKCS11 key", __func__);
|
||||
+ debug3("%s: free PKCS11 ECDSA key for provider %s", __func__, helper->path);
|
||||
+ if (helper->ec_finish != NULL)
|
||||
+ helper->ec_finish(ec);
|
||||
+ if (helper->nec == 0)
|
||||
+ fatal("%s: ECDSA refcount error", __func__);
|
||||
+ helper->nec--;
|
||||
+ debug3("%s: provider %s remaining keys: %zu RSA %zu ECDSA", __func__,
|
||||
+ helper->path, helper->nrsa, helper->nec);
|
||||
+ if (helper->nrsa == 0 && helper->nec == 0)
|
||||
+ helper_terminate(helper);
|
||||
+}
|
||||
|
||||
/* redirect private key crypto operations to the ssh-pkcs11-helper */
|
||||
static void
|
||||
-wrap_key(struct sshkey *k)
|
||||
+wrap_key(struct helper *helper, struct sshkey *k)
|
||||
{
|
||||
- if (k->type == KEY_RSA)
|
||||
- RSA_set_method(k->rsa, helper_rsa);
|
||||
-#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
- else if (k->type == KEY_ECDSA)
|
||||
- EC_KEY_set_method(k->ecdsa, helper_ecdsa);
|
||||
-#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
- else
|
||||
+ debug3("%s: wrap %s for provider %s", __func__, sshkey_type(k), helper->path);
|
||||
+ if (k->type == KEY_RSA) {
|
||||
+ RSA_set_method(k->rsa, helper->rsa_meth);
|
||||
+ if (helper->nrsa++ >= INT_MAX)
|
||||
+ fatal("%s: RSA refcount error", __func__);
|
||||
+ } else if (k->type == KEY_ECDSA) {
|
||||
+ EC_KEY_set_method(k->ecdsa, helper->ec_meth);
|
||||
+ if (helper->nec++ >= INT_MAX)
|
||||
+ fatal("%s: EC refcount error", __func__);
|
||||
+ } else
|
||||
fatal("%s: unknown key type", __func__);
|
||||
+ k->flags |= SSHKEY_FLAG_EXT;
|
||||
+ debug3("%s: provider %s remaining keys: %zu RSA %zu ECDSA", __func__,
|
||||
+ helper->path, helper->nrsa, helper->nec);
|
||||
}
|
||||
|
||||
static int
|
||||
-pkcs11_start_helper_methods(void)
|
||||
+pkcs11_start_helper_methods(struct helper *helper)
|
||||
{
|
||||
- if (helper_rsa != NULL)
|
||||
- return (0);
|
||||
-
|
||||
-#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
||||
- int (*orig_sign)(int, const unsigned char *, int, unsigned char *,
|
||||
+ int (*ec_init)(EC_KEY *key);
|
||||
+ int (*ec_copy)(EC_KEY *dest, const EC_KEY *src);
|
||||
+ int (*ec_set_group)(EC_KEY *key, const EC_GROUP *grp);
|
||||
+ int (*ec_set_private)(EC_KEY *key, const BIGNUM *priv_key);
|
||||
+ int (*ec_set_public)(EC_KEY *key, const EC_POINT *pub_key);
|
||||
+ int (*ec_sign)(int, const unsigned char *, int, unsigned char *,
|
||||
unsigned int *, const BIGNUM *, const BIGNUM *, EC_KEY *) = NULL;
|
||||
- if (helper_ecdsa != NULL)
|
||||
- return (0);
|
||||
- helper_ecdsa = EC_KEY_METHOD_new(EC_KEY_OpenSSL());
|
||||
- if (helper_ecdsa == NULL)
|
||||
- return (-1);
|
||||
- EC_KEY_METHOD_get_sign(helper_ecdsa, &orig_sign, NULL, NULL);
|
||||
- EC_KEY_METHOD_set_sign(helper_ecdsa, orig_sign, NULL, ecdsa_do_sign);
|
||||
-#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
||||
-
|
||||
- if ((helper_rsa = RSA_meth_dup(RSA_get_default_method())) == NULL)
|
||||
+ RSA_METHOD *rsa_meth;
|
||||
+ EC_KEY_METHOD *ec_meth;
|
||||
+
|
||||
+ if ((ec_meth = EC_KEY_METHOD_new(EC_KEY_OpenSSL())) == NULL)
|
||||
+ return -1;
|
||||
+ EC_KEY_METHOD_get_sign(ec_meth, &ec_sign, NULL, NULL);
|
||||
+ EC_KEY_METHOD_set_sign(ec_meth, ec_sign, NULL, ecdsa_do_sign);
|
||||
+ EC_KEY_METHOD_get_init(ec_meth, &ec_init, &helper->ec_finish,
|
||||
+ &ec_copy, &ec_set_group, &ec_set_private, &ec_set_public);
|
||||
+ EC_KEY_METHOD_set_init(ec_meth, ec_init, ecdsa_do_finish,
|
||||
+ ec_copy, ec_set_group, ec_set_private, ec_set_public);
|
||||
+
|
||||
+ if ((rsa_meth = RSA_meth_dup(RSA_get_default_method())) == NULL)
|
||||
fatal("%s: RSA_meth_dup failed", __func__);
|
||||
- if (!RSA_meth_set1_name(helper_rsa, "ssh-pkcs11-helper") ||
|
||||
- !RSA_meth_set_priv_enc(helper_rsa, rsa_encrypt))
|
||||
+ helper->rsa_finish = RSA_meth_get_finish(rsa_meth);
|
||||
+ if (!RSA_meth_set1_name(rsa_meth, "ssh-pkcs11-helper") ||
|
||||
+ !RSA_meth_set_priv_enc(rsa_meth, rsa_encrypt) ||
|
||||
+ !RSA_meth_set_finish(rsa_meth, rsa_finish))
|
||||
fatal("%s: failed to prepare method", __func__);
|
||||
|
||||
- return (0);
|
||||
+ helper->ec_meth = ec_meth;
|
||||
+ helper->rsa_meth = rsa_meth;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
-static int
|
||||
-pkcs11_start_helper(void)
|
||||
+static struct helper *
|
||||
+pkcs11_start_helper(const char *path)
|
||||
{
|
||||
int pair[2];
|
||||
- char *helper, *verbosity = NULL;
|
||||
-
|
||||
- if (log_level_get() >= SYSLOG_LEVEL_DEBUG1)
|
||||
- verbosity = "-vvv";
|
||||
-
|
||||
- if (pkcs11_start_helper_methods() == -1) {
|
||||
- error("pkcs11_start_helper_methods failed");
|
||||
- return (-1);
|
||||
- }
|
||||
+ char *prog, *verbosity = NULL;
|
||||
+ struct helper *helper;
|
||||
+ pid_t pid;
|
||||
|
||||
+ if (nhelpers >= INT_MAX)
|
||||
+ fatal("%s: too many helpers", __func__);
|
||||
+ debug3("%s: start helper for %s", __func__, path);
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
|
||||
error("socketpair: %s", strerror(errno));
|
||||
- return (-1);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ helper = xcalloc(1, sizeof(*helper));
|
||||
+ if (pkcs11_start_helper_methods(helper) == -1) {
|
||||
+ error("pkcs11_start_helper_methods failed");
|
||||
+ goto fail;
|
||||
}
|
||||
if ((pid = fork()) == -1) {
|
||||
error("fork: %s", strerror(errno));
|
||||
- return (-1);
|
||||
+ fail:
|
||||
+ close(pair[0]);
|
||||
+ close(pair[1]);
|
||||
+ RSA_meth_free(helper->rsa_meth);
|
||||
+ EC_KEY_METHOD_free(helper->ec_meth);
|
||||
+ free(helper);
|
||||
+ return NULL;
|
||||
} else if (pid == 0) {
|
||||
if ((dup2(pair[1], STDIN_FILENO) == -1) ||
|
||||
(dup2(pair[1], STDOUT_FILENO) == -1)) {
|
||||
@@ -297,18 +485,27 @@ pkcs11_start_helper(void)
|
||||
}
|
||||
close(pair[0]);
|
||||
close(pair[1]);
|
||||
- helper = getenv("SSH_PKCS11_HELPER");
|
||||
- if (helper == NULL || strlen(helper) == 0)
|
||||
- helper = _PATH_SSH_PKCS11_HELPER;
|
||||
+ prog = getenv("SSH_PKCS11_HELPER");
|
||||
+ if (prog == NULL || strlen(prog) == 0)
|
||||
+ prog = _PATH_SSH_PKCS11_HELPER;
|
||||
+ if (log_level_get() >= SYSLOG_LEVEL_DEBUG1)
|
||||
+ verbosity = "-vvv";
|
||||
debug("%s: starting %s %s", __func__, helper,
|
||||
verbosity == NULL ? "" : verbosity);
|
||||
- execlp(helper, helper, verbosity, (char *)NULL);
|
||||
- fprintf(stderr, "exec: %s: %s\n", helper, strerror(errno));
|
||||
+ execlp(prog, prog, verbosity, (char *)NULL);
|
||||
+ fprintf(stderr, "exec: %s: %s\n", prog, strerror(errno));
|
||||
_exit(1);
|
||||
}
|
||||
close(pair[1]);
|
||||
- fd = pair[0];
|
||||
- return (0);
|
||||
+ helper->fd = pair[0];
|
||||
+ helper->path = xstrdup(path);
|
||||
+ helper->pid = pid;
|
||||
+ debug3("%s: helper %zu for \"%s\" on fd %d pid %ld", __func__, nhelpers,
|
||||
+ helper->path, helper->fd, (long)helper->pid);
|
||||
+ helpers = xrecallocarray(helpers, nhelpers,
|
||||
+ nhelpers + 1, sizeof(*helpers));
|
||||
+ helpers[nhelpers++] = helper;
|
||||
+ return helper;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -322,9 +519,11 @@ pkcs11_add_provider(char *name, char *pin, struct sshkey ***keysp,
|
||||
size_t blen;
|
||||
u_int nkeys, i;
|
||||
struct sshbuf *msg;
|
||||
+ struct helper *helper;
|
||||
|
||||
- if (fd < 0 && pkcs11_start_helper() < 0)
|
||||
- return (-1);
|
||||
+ if ((helper = helper_by_provider(name)) == NULL &&
|
||||
+ (helper = pkcs11_start_helper(name)) == NULL)
|
||||
+ return -1;
|
||||
|
||||
if ((msg = sshbuf_new()) == NULL)
|
||||
fatal("%s: sshbuf_new failed", __func__);
|
||||
@@ -332,10 +531,10 @@ pkcs11_add_provider(char *name, char *pin, struct sshkey ***keysp,
|
||||
(r = sshbuf_put_cstring(msg, name)) != 0 ||
|
||||
(r = sshbuf_put_cstring(msg, pin)) != 0)
|
||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
- send_msg(msg);
|
||||
+ send_msg(helper->fd, msg);
|
||||
sshbuf_reset(msg);
|
||||
|
||||
- type = recv_msg(msg);
|
||||
+ type = recv_msg(helper->fd, msg);
|
||||
if (type == SSH2_AGENT_IDENTITIES_ANSWER) {
|
||||
if ((r = sshbuf_get_u32(msg, &nkeys)) != 0)
|
||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
@@ -350,7 +549,7 @@ pkcs11_add_provider(char *name, char *pin, struct sshkey ***keysp,
|
||||
__func__, ssh_err(r));
|
||||
if ((r = sshkey_from_blob(blob, blen, &k)) != 0)
|
||||
fatal("%s: bad key: %s", __func__, ssh_err(r));
|
||||
- wrap_key(k);
|
||||
+ wrap_key(helper, k);
|
||||
(*keysp)[i] = k;
|
||||
if (labelsp)
|
||||
(*labelsp)[i] = label;
|
||||
@@ -371,22 +570,15 @@ pkcs11_add_provider(char *name, char *pin, struct sshkey ***keysp,
|
||||
int
|
||||
pkcs11_del_provider(char *name)
|
||||
{
|
||||
- int r, ret = -1;
|
||||
- struct sshbuf *msg;
|
||||
-
|
||||
- if ((msg = sshbuf_new()) == NULL)
|
||||
- fatal("%s: sshbuf_new failed", __func__);
|
||||
- if ((r = sshbuf_put_u8(msg, SSH_AGENTC_REMOVE_SMARTCARD_KEY)) != 0 ||
|
||||
- (r = sshbuf_put_cstring(msg, name)) != 0 ||
|
||||
- (r = sshbuf_put_cstring(msg, "")) != 0)
|
||||
- fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
- send_msg(msg);
|
||||
- sshbuf_reset(msg);
|
||||
-
|
||||
- if (recv_msg(msg) == SSH_AGENT_SUCCESS)
|
||||
- ret = 0;
|
||||
- sshbuf_free(msg);
|
||||
- return (ret);
|
||||
+ struct helper *helper;
|
||||
+
|
||||
+ /*
|
||||
+ * ssh-agent deletes keys before calling this, so the helper entry
|
||||
+ * should be gone before we get here.
|
||||
+ */
|
||||
+ debug3("%s: delete %s", __func__, name);
|
||||
+ if ((helper = helper_by_provider(name)) != NULL)
|
||||
+ helper_terminate(helper);
|
||||
+ return 0;
|
||||
}
|
||||
-
|
||||
#endif /* ENABLE_PKCS11 */
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,171 @@
|
||||
From 2f1be98e83feb90665b9292eff8bb734537fd491 Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Wed, 19 Jul 2023 14:02:27 +0000
|
||||
Subject: [PATCH 03/12] upstream: Ensure FIDO/PKCS11 libraries contain expected
|
||||
symbols
|
||||
|
||||
This checks via nlist(3) that candidate provider libraries contain one
|
||||
of the symbols that we will require prior to dlopen(), which can cause
|
||||
a number of side effects, including execution of constructors.
|
||||
|
||||
Feedback deraadt; ok markus
|
||||
|
||||
OpenBSD-Commit-ID: 1508a5fbd74e329e69a55b56c453c292029aefbe
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/29ef8a04866ca14688d5b7fed7b8b9deab851f77]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
misc.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
misc.h | 1 +
|
||||
ssh-pkcs11.c | 4 +++
|
||||
ssh-sk.c | 6 ++--
|
||||
4 files changed, 86 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/misc.c b/misc.c
|
||||
index 3a31d5c..8a107e4 100644
|
||||
--- a/misc.c
|
||||
+++ b/misc.c
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
+#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
@@ -41,6 +42,9 @@
|
||||
#ifdef HAVE_POLL_H
|
||||
#include <poll.h>
|
||||
#endif
|
||||
+#ifdef HAVE_NLIST_H
|
||||
+#include <nlist.h>
|
||||
+#endif
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
@@ -2266,3 +2270,76 @@ ssh_signal(int signum, sshsig_t handler)
|
||||
}
|
||||
return osa.sa_handler;
|
||||
}
|
||||
+
|
||||
+
|
||||
+/*
|
||||
+ * Returns zero if the library at 'path' contains symbol 's', nonzero
|
||||
+ * otherwise.
|
||||
+ */
|
||||
+int
|
||||
+lib_contains_symbol(const char *path, const char *s)
|
||||
+{
|
||||
+#ifdef HAVE_NLIST_H
|
||||
+ struct nlist nl[2];
|
||||
+ int ret = -1, r;
|
||||
+
|
||||
+ memset(nl, 0, sizeof(nl));
|
||||
+ nl[0].n_name = xstrdup(s);
|
||||
+ nl[1].n_name = NULL;
|
||||
+ if ((r = nlist(path, nl)) == -1) {
|
||||
+ error("%s: nlist failed for %s", __func__, path);
|
||||
+ goto out;
|
||||
+ }
|
||||
+ if (r != 0 || nl[0].n_value == 0 || nl[0].n_type == 0) {
|
||||
+ error("%s: library %s does not contain symbol %s", __func__, path, s);
|
||||
+ goto out;
|
||||
+ }
|
||||
+ /* success */
|
||||
+ ret = 0;
|
||||
+ out:
|
||||
+ free(nl[0].n_name);
|
||||
+ return ret;
|
||||
+#else /* HAVE_NLIST_H */
|
||||
+ int fd, ret = -1;
|
||||
+ struct stat st;
|
||||
+ void *m = NULL;
|
||||
+ size_t sz = 0;
|
||||
+
|
||||
+ memset(&st, 0, sizeof(st));
|
||||
+ if ((fd = open(path, O_RDONLY)) < 0) {
|
||||
+ error("%s: open %s: %s", __func__, path, strerror(errno));
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (fstat(fd, &st) != 0) {
|
||||
+ error("%s: fstat %s: %s", __func__, path, strerror(errno));
|
||||
+ goto out;
|
||||
+ }
|
||||
+ if (!S_ISREG(st.st_mode)) {
|
||||
+ error("%s: %s is not a regular file", __func__, path);
|
||||
+ goto out;
|
||||
+ }
|
||||
+ if (st.st_size < 0 ||
|
||||
+ (size_t)st.st_size < strlen(s) ||
|
||||
+ st.st_size >= INT_MAX/2) {
|
||||
+ error("%s: %s bad size %lld", __func__, path, (long long)st.st_size);
|
||||
+ goto out;
|
||||
+ }
|
||||
+ sz = (size_t)st.st_size;
|
||||
+ if ((m = mmap(NULL, sz, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED ||
|
||||
+ m == NULL) {
|
||||
+ error("%s: mmap %s: %s", __func__, path, strerror(errno));
|
||||
+ goto out;
|
||||
+ }
|
||||
+ if (memmem(m, sz, s, strlen(s)) == NULL) {
|
||||
+ error("%s: %s does not contain expected string %s", __func__, path, s);
|
||||
+ goto out;
|
||||
+ }
|
||||
+ /* success */
|
||||
+ ret = 0;
|
||||
+ out:
|
||||
+ if (m != NULL && m != MAP_FAILED)
|
||||
+ munmap(m, sz);
|
||||
+ close(fd);
|
||||
+ return ret;
|
||||
+#endif /* HAVE_NLIST_H */
|
||||
+}
|
||||
diff --git a/misc.h b/misc.h
|
||||
index 4a05db2..3f9f4db 100644
|
||||
--- a/misc.h
|
||||
+++ b/misc.h
|
||||
@@ -86,6 +86,7 @@ const char *atoi_err(const char *, int *);
|
||||
int parse_absolute_time(const char *, uint64_t *);
|
||||
void format_absolute_time(uint64_t, char *, size_t);
|
||||
int path_absolute(const char *);
|
||||
+int lib_contains_symbol(const char *, const char *);
|
||||
|
||||
void sock_set_v6only(int);
|
||||
|
||||
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c
|
||||
index b56a41b..639a6f7 100644
|
||||
--- a/ssh-pkcs11.c
|
||||
+++ b/ssh-pkcs11.c
|
||||
@@ -1499,6 +1499,10 @@ pkcs11_register_provider(char *provider_id, char *pin,
|
||||
__func__, provider_id);
|
||||
goto fail;
|
||||
}
|
||||
+ if (lib_contains_symbol(provider_id, "C_GetFunctionList") != 0) {
|
||||
+ error("provider %s is not a PKCS11 library", provider_id);
|
||||
+ goto fail;
|
||||
+ }
|
||||
/* open shared pkcs11-library */
|
||||
if ((handle = dlopen(provider_id, RTLD_NOW)) == NULL) {
|
||||
error("dlopen %s failed: %s", provider_id, dlerror());
|
||||
diff --git a/ssh-sk.c b/ssh-sk.c
|
||||
index 5ff9381..9df12cc 100644
|
||||
--- a/ssh-sk.c
|
||||
+++ b/ssh-sk.c
|
||||
@@ -119,10 +119,12 @@ sshsk_open(const char *path)
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
- if ((ret->dlhandle = dlopen(path, RTLD_NOW)) == NULL) {
|
||||
- error("Provider \"%s\" dlopen failed: %s", path, dlerror());
|
||||
+ if (lib_contains_symbol(path, "sk_api_version") != 0) {
|
||||
+ error("provider %s is not an OpenSSH FIDO library", path);
|
||||
goto fail;
|
||||
}
|
||||
+ if ((ret->dlhandle = dlopen(path, RTLD_NOW)) == NULL)
|
||||
+ fatal("Provider \"%s\" dlopen failed: %s", path, dlerror());
|
||||
if ((ret->sk_api_version = dlsym(ret->dlhandle,
|
||||
"sk_api_version")) == NULL) {
|
||||
error("Provider \"%s\" dlsym(sk_api_version) failed: %s",
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,34 @@
|
||||
From 0862f338941bfdfb2cadee87de6d5fdca1b8f457 Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Wed, 19 Jul 2023 13:55:53 +0000
|
||||
Subject: [PATCH 04/12] upstream: terminate process if requested to load a
|
||||
PKCS#11 provider that isn't a PKCS#11 provider; from / ok markus@
|
||||
|
||||
OpenBSD-Commit-ID: 39532cf18b115881bb4cfaee32084497aadfa05c
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/892506b13654301f69f9545f48213fc210e5c5cc]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-pkcs11.c | 6 ++----
|
||||
1 file changed, 2 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c
|
||||
index 639a6f7..7530acc 100644
|
||||
--- a/ssh-pkcs11.c
|
||||
+++ b/ssh-pkcs11.c
|
||||
@@ -1508,10 +1508,8 @@ pkcs11_register_provider(char *provider_id, char *pin,
|
||||
error("dlopen %s failed: %s", provider_id, dlerror());
|
||||
goto fail;
|
||||
}
|
||||
- if ((getfunctionlist = dlsym(handle, "C_GetFunctionList")) == NULL) {
|
||||
- error("dlsym(C_GetFunctionList) failed: %s", dlerror());
|
||||
- goto fail;
|
||||
- }
|
||||
+ if ((getfunctionlist = dlsym(handle, "C_GetFunctionList")) == NULL)
|
||||
+ fatal("dlsym(C_GetFunctionList) failed: %s", dlerror());
|
||||
p = xcalloc(1, sizeof(*p));
|
||||
p->name = xstrdup(provider_id);
|
||||
p->handle = handle;
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,194 @@
|
||||
From a6cee3905edf070c0de135d3f2ee5b74da1dbd28 Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Tue, 26 May 2020 01:26:58 +0000
|
||||
Subject: [PATCH 05/12] upstream: Restrict ssh-agent from signing web
|
||||
challenges for FIDO
|
||||
|
||||
keys.
|
||||
|
||||
When signing messages in ssh-agent using a FIDO key that has an
|
||||
application string that does not start with "ssh:", ensure that the
|
||||
message being signed is one of the forms expected for the SSH protocol
|
||||
(currently pubkey authentication and sshsig signatures).
|
||||
|
||||
This prevents ssh-agent forwarding on a host that has FIDO keys
|
||||
attached granting the ability for the remote side to sign challenges
|
||||
for web authentication using those keys too.
|
||||
|
||||
Note that the converse case of web browsers signing SSH challenges is
|
||||
already precluded because no web RP can have the "ssh:" prefix in the
|
||||
application string that we require.
|
||||
|
||||
ok markus@
|
||||
|
||||
OpenBSD-Commit-ID: 9ab6012574ed0352d2f097d307f4a988222d1b19
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/0c111eb84efba7c2a38b2cc3278901a0123161b9]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-agent.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++-----
|
||||
1 file changed, 100 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/ssh-agent.c b/ssh-agent.c
|
||||
index ceb348c..1794f35 100644
|
||||
--- a/ssh-agent.c
|
||||
+++ b/ssh-agent.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/* $OpenBSD: ssh-agent.c,v 1.255 2020/02/06 22:30:54 naddy Exp $ */
|
||||
+/* $OpenBSD: ssh-agent.c,v 1.258 2020/05/26 01:26:58 djm Exp $ */
|
||||
/*
|
||||
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||
@@ -77,6 +77,7 @@
|
||||
|
||||
#include "xmalloc.h"
|
||||
#include "ssh.h"
|
||||
+#include "ssh2.h"
|
||||
#include "sshbuf.h"
|
||||
#include "sshkey.h"
|
||||
#include "authfd.h"
|
||||
@@ -167,6 +168,9 @@ static long lifetime = 0;
|
||||
|
||||
static int fingerprint_hash = SSH_FP_HASH_DEFAULT;
|
||||
|
||||
+/* Refuse signing of non-SSH messages for web-origin FIDO keys */
|
||||
+static int restrict_websafe = 1;
|
||||
+
|
||||
static void
|
||||
close_socket(SocketEntry *e)
|
||||
{
|
||||
@@ -282,6 +286,80 @@ agent_decode_alg(struct sshkey *key, u_int flags)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * This function inspects a message to be signed by a FIDO key that has a
|
||||
+ * web-like application string (i.e. one that does not begin with "ssh:".
|
||||
+ * It checks that the message is one of those expected for SSH operations
|
||||
+ * (pubkey userauth, sshsig, CA key signing) to exclude signing challenges
|
||||
+ * for the web.
|
||||
+ */
|
||||
+static int
|
||||
+check_websafe_message_contents(struct sshkey *key,
|
||||
+ const u_char *msg, size_t len)
|
||||
+{
|
||||
+ int matched = 0;
|
||||
+ struct sshbuf *b;
|
||||
+ u_char m, n;
|
||||
+ char *cp1 = NULL, *cp2 = NULL;
|
||||
+ int r;
|
||||
+ struct sshkey *mkey = NULL;
|
||||
+
|
||||
+ if ((b = sshbuf_from(msg, len)) == NULL)
|
||||
+ fatal("%s: sshbuf_new", __func__);
|
||||
+
|
||||
+ /* SSH userauth request */
|
||||
+ if ((r = sshbuf_get_string_direct(b, NULL, NULL)) == 0 && /* sess_id */
|
||||
+ (r = sshbuf_get_u8(b, &m)) == 0 && /* SSH2_MSG_USERAUTH_REQUEST */
|
||||
+ (r = sshbuf_get_cstring(b, NULL, NULL)) == 0 && /* server user */
|
||||
+ (r = sshbuf_get_cstring(b, &cp1, NULL)) == 0 && /* service */
|
||||
+ (r = sshbuf_get_cstring(b, &cp2, NULL)) == 0 && /* method */
|
||||
+ (r = sshbuf_get_u8(b, &n)) == 0 && /* sig-follows */
|
||||
+ (r = sshbuf_get_cstring(b, NULL, NULL)) == 0 && /* alg */
|
||||
+ (r = sshkey_froms(b, &mkey)) == 0 && /* key */
|
||||
+ sshbuf_len(b) == 0) {
|
||||
+ debug("%s: parsed userauth", __func__);
|
||||
+ if (m == SSH2_MSG_USERAUTH_REQUEST && n == 1 &&
|
||||
+ strcmp(cp1, "ssh-connection") == 0 &&
|
||||
+ strcmp(cp2, "publickey") == 0 &&
|
||||
+ sshkey_equal(key, mkey)) {
|
||||
+ debug("%s: well formed userauth", __func__);
|
||||
+ matched = 1;
|
||||
+ }
|
||||
+ }
|
||||
+ free(cp1);
|
||||
+ free(cp2);
|
||||
+ sshkey_free(mkey);
|
||||
+ sshbuf_free(b);
|
||||
+ if (matched)
|
||||
+ return 1;
|
||||
+
|
||||
+ if ((b = sshbuf_from(msg, len)) == NULL)
|
||||
+ fatal("%s: sshbuf_new", __func__);
|
||||
+ cp1 = cp2 = NULL;
|
||||
+ mkey = NULL;
|
||||
+
|
||||
+ /* SSHSIG */
|
||||
+ if ((r = sshbuf_cmp(b, 0, "SSHSIG", 6)) == 0 &&
|
||||
+ (r = sshbuf_consume(b, 6)) == 0 &&
|
||||
+ (r = sshbuf_get_cstring(b, NULL, NULL)) == 0 && /* namespace */
|
||||
+ (r = sshbuf_get_string_direct(b, NULL, NULL)) == 0 && /* reserved */
|
||||
+ (r = sshbuf_get_cstring(b, NULL, NULL)) == 0 && /* hashalg */
|
||||
+ (r = sshbuf_get_string_direct(b, NULL, NULL)) == 0 && /* H(msg) */
|
||||
+ sshbuf_len(b) == 0) {
|
||||
+ debug("%s: parsed sshsig", __func__);
|
||||
+ matched = 1;
|
||||
+ }
|
||||
+
|
||||
+ sshbuf_free(b);
|
||||
+ if (matched)
|
||||
+ return 1;
|
||||
+
|
||||
+ /* XXX CA signature operation */
|
||||
+
|
||||
+ error("web-origin key attempting to sign non-SSH message");
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
/* ssh2 only */
|
||||
static void
|
||||
process_sign_request2(SocketEntry *e)
|
||||
@@ -314,14 +392,20 @@ process_sign_request2(SocketEntry *e)
|
||||
verbose("%s: user refused key", __func__);
|
||||
goto send;
|
||||
}
|
||||
- if (sshkey_is_sk(id->key) &&
|
||||
- (id->key->sk_flags & SSH_SK_USER_PRESENCE_REQD)) {
|
||||
- if ((fp = sshkey_fingerprint(key, SSH_FP_HASH_DEFAULT,
|
||||
- SSH_FP_DEFAULT)) == NULL)
|
||||
- fatal("%s: fingerprint failed", __func__);
|
||||
- notifier = notify_start(0,
|
||||
- "Confirm user presence for key %s %s",
|
||||
- sshkey_type(id->key), fp);
|
||||
+ if (sshkey_is_sk(id->key)) {
|
||||
+ if (strncmp(id->key->sk_application, "ssh:", 4) != 0 &&
|
||||
+ !check_websafe_message_contents(key, data, dlen)) {
|
||||
+ /* error already logged */
|
||||
+ goto send;
|
||||
+ }
|
||||
+ if ((id->key->sk_flags & SSH_SK_USER_PRESENCE_REQD)) {
|
||||
+ if ((fp = sshkey_fingerprint(key, SSH_FP_HASH_DEFAULT,
|
||||
+ SSH_FP_DEFAULT)) == NULL)
|
||||
+ fatal("%s: fingerprint failed", __func__);
|
||||
+ notifier = notify_start(0,
|
||||
+ "Confirm user presence for key %s %s",
|
||||
+ sshkey_type(id->key), fp);
|
||||
+ }
|
||||
}
|
||||
if ((r = sshkey_sign(id->key, &signature, &slen,
|
||||
data, dlen, agent_decode_alg(key, flags),
|
||||
@@ -1214,7 +1298,7 @@ main(int ac, char **av)
|
||||
__progname = ssh_get_progname(av[0]);
|
||||
seed_rng();
|
||||
|
||||
- while ((ch = getopt(ac, av, "cDdksE:a:P:t:")) != -1) {
|
||||
+ while ((ch = getopt(ac, av, "cDdksE:a:O:P:t:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'E':
|
||||
fingerprint_hash = ssh_digest_alg_by_name(optarg);
|
||||
@@ -1229,6 +1313,12 @@ main(int ac, char **av)
|
||||
case 'k':
|
||||
k_flag++;
|
||||
break;
|
||||
+ case 'O':
|
||||
+ if (strcmp(optarg, "no-restrict-websafe") == 0)
|
||||
+ restrict_websafe = 0;
|
||||
+ else
|
||||
+ fatal("Unknown -O option");
|
||||
+ break;
|
||||
case 'P':
|
||||
if (provider_whitelist != NULL)
|
||||
fatal("-P option already specified");
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,73 @@
|
||||
From a5d845b7b42861d18f43e83de9f24c7374d1b458 Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Fri, 18 Sep 2020 08:16:38 +0000
|
||||
Subject: [PATCH 06/12] upstream: handle multiple messages in a single read()
|
||||
|
||||
PR#183 by Dennis Kaarsemaker; feedback and ok markus@
|
||||
|
||||
OpenBSD-Commit-ID: 8570bb4d02d00cf70b98590716ea6a7d1cce68d1
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/52a03e9fca2d74eef953ddd4709250f365ca3975]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-agent.c | 19 +++++++++++++------
|
||||
1 file changed, 13 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/ssh-agent.c b/ssh-agent.c
|
||||
index 1794f35..78f7268 100644
|
||||
--- a/ssh-agent.c
|
||||
+++ b/ssh-agent.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/* $OpenBSD: ssh-agent.c,v 1.258 2020/05/26 01:26:58 djm Exp $ */
|
||||
+/* $OpenBSD: ssh-agent.c,v 1.264 2020/09/18 08:16:38 djm Exp $ */
|
||||
/*
|
||||
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||
@@ -853,8 +853,10 @@ send:
|
||||
}
|
||||
#endif /* ENABLE_PKCS11 */
|
||||
|
||||
-/* dispatch incoming messages */
|
||||
-
|
||||
+/*
|
||||
+ * dispatch incoming message.
|
||||
+ * returns 1 on success, 0 for incomplete messages or -1 on error.
|
||||
+ */
|
||||
static int
|
||||
process_message(u_int socknum)
|
||||
{
|
||||
@@ -908,7 +910,7 @@ process_message(u_int socknum)
|
||||
/* send a fail message for all other request types */
|
||||
send_status(e, 0);
|
||||
}
|
||||
- return 0;
|
||||
+ return 1;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
@@ -952,7 +954,7 @@ process_message(u_int socknum)
|
||||
send_status(e, 0);
|
||||
break;
|
||||
}
|
||||
- return 0;
|
||||
+ return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1043,7 +1045,12 @@ handle_conn_read(u_int socknum)
|
||||
if ((r = sshbuf_put(sockets[socknum].input, buf, len)) != 0)
|
||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
explicit_bzero(buf, sizeof(buf));
|
||||
- process_message(socknum);
|
||||
+ for (;;) {
|
||||
+ if ((r = process_message(socknum)) == -1)
|
||||
+ return -1;
|
||||
+ else if (r == 0)
|
||||
+ break;
|
||||
+ }
|
||||
return 0;
|
||||
}
|
||||
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,125 @@
|
||||
From 653cc18c922fc387b3d3aa1b081c5e5283cce28a Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Tue, 26 Jan 2021 00:47:47 +0000
|
||||
Subject: [PATCH 07/12] upstream: use recallocarray to allocate the agent
|
||||
sockets table;
|
||||
|
||||
also clear socket entries that are being marked as unused.
|
||||
|
||||
spinkle in some debug2() spam to make it easier to watch an agent
|
||||
do its thing.
|
||||
|
||||
ok markus
|
||||
|
||||
OpenBSD-Commit-ID: 74582c8e82e96afea46f6c7b6813a429cbc75922
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/1fe16fd61bb53944ec510882acc0491abd66ff76]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-agent.c | 20 ++++++++++++++++----
|
||||
1 file changed, 16 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/ssh-agent.c b/ssh-agent.c
|
||||
index 78f7268..2635bc5 100644
|
||||
--- a/ssh-agent.c
|
||||
+++ b/ssh-agent.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/* $OpenBSD: ssh-agent.c,v 1.264 2020/09/18 08:16:38 djm Exp $ */
|
||||
+/* $OpenBSD: ssh-agent.c,v 1.269 2021/01/26 00:47:47 djm Exp $ */
|
||||
/*
|
||||
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||
@@ -175,11 +175,12 @@ static void
|
||||
close_socket(SocketEntry *e)
|
||||
{
|
||||
close(e->fd);
|
||||
- e->fd = -1;
|
||||
- e->type = AUTH_UNUSED;
|
||||
sshbuf_free(e->input);
|
||||
sshbuf_free(e->output);
|
||||
sshbuf_free(e->request);
|
||||
+ memset(e, '\0', sizeof(*e));
|
||||
+ e->fd = -1;
|
||||
+ e->type = AUTH_UNUSED;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -249,6 +250,8 @@ process_request_identities(SocketEntry *e)
|
||||
struct sshbuf *msg;
|
||||
int r;
|
||||
|
||||
+ debug2("%s: entering", __func__);
|
||||
+
|
||||
if ((msg = sshbuf_new()) == NULL)
|
||||
fatal("%s: sshbuf_new failed", __func__);
|
||||
if ((r = sshbuf_put_u8(msg, SSH2_AGENT_IDENTITIES_ANSWER)) != 0 ||
|
||||
@@ -441,6 +444,7 @@ process_remove_identity(SocketEntry *e)
|
||||
struct sshkey *key = NULL;
|
||||
Identity *id;
|
||||
|
||||
+ debug2("%s: entering", __func__);
|
||||
if ((r = sshkey_froms(e->request, &key)) != 0) {
|
||||
error("%s: get key: %s", __func__, ssh_err(r));
|
||||
goto done;
|
||||
@@ -467,6 +471,7 @@ process_remove_all_identities(SocketEntry *e)
|
||||
{
|
||||
Identity *id;
|
||||
|
||||
+ debug2("%s: entering", __func__);
|
||||
/* Loop over all identities and clear the keys. */
|
||||
for (id = TAILQ_FIRST(&idtab->idlist); id;
|
||||
id = TAILQ_FIRST(&idtab->idlist)) {
|
||||
@@ -520,6 +525,7 @@ process_add_identity(SocketEntry *e)
|
||||
u_char ctype;
|
||||
int r = SSH_ERR_INTERNAL_ERROR;
|
||||
|
||||
+ debug2("%s: entering", __func__);
|
||||
if ((r = sshkey_private_deserialize(e->request, &k)) != 0 ||
|
||||
k == NULL ||
|
||||
(r = sshbuf_get_cstring(e->request, &comment, NULL)) != 0) {
|
||||
@@ -667,6 +673,7 @@ process_lock_agent(SocketEntry *e, int lock)
|
||||
static u_int fail_count = 0;
|
||||
size_t pwlen;
|
||||
|
||||
+ debug2("%s: entering", __func__);
|
||||
/*
|
||||
* This is deliberately fatal: the user has requested that we lock,
|
||||
* but we can't parse their request properly. The only safe thing to
|
||||
@@ -738,6 +745,7 @@ process_add_smartcard_key(SocketEntry *e)
|
||||
struct sshkey **keys = NULL, *k;
|
||||
Identity *id;
|
||||
|
||||
+ debug2("%s: entering", __func__);
|
||||
if ((r = sshbuf_get_cstring(e->request, &provider, NULL)) != 0 ||
|
||||
(r = sshbuf_get_cstring(e->request, &pin, NULL)) != 0) {
|
||||
error("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
@@ -818,6 +826,7 @@ process_remove_smartcard_key(SocketEntry *e)
|
||||
int r, success = 0;
|
||||
Identity *id, *nxt;
|
||||
|
||||
+ debug2("%s: entering", __func__);
|
||||
if ((r = sshbuf_get_cstring(e->request, &provider, NULL)) != 0 ||
|
||||
(r = sshbuf_get_cstring(e->request, &pin, NULL)) != 0) {
|
||||
error("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
@@ -962,6 +971,8 @@ new_socket(sock_type type, int fd)
|
||||
{
|
||||
u_int i, old_alloc, new_alloc;
|
||||
|
||||
+ debug("%s: type = %s", __func__, type == AUTH_CONNECTION ? "CONNECTION" :
|
||||
+ (type == AUTH_SOCKET ? "SOCKET" : "UNKNOWN"));
|
||||
set_nonblock(fd);
|
||||
|
||||
if (fd > max_fd)
|
||||
@@ -981,7 +992,8 @@ new_socket(sock_type type, int fd)
|
||||
}
|
||||
old_alloc = sockets_alloc;
|
||||
new_alloc = sockets_alloc + 10;
|
||||
- sockets = xreallocarray(sockets, new_alloc, sizeof(sockets[0]));
|
||||
+ sockets = xrecallocarray(sockets, old_alloc, new_alloc,
|
||||
+ sizeof(sockets[0]));
|
||||
for (i = old_alloc; i < new_alloc; i++)
|
||||
sockets[i].type = AUTH_UNUSED;
|
||||
sockets_alloc = new_alloc;
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,315 @@
|
||||
From c30158ea225cf8ad67c3dcc88fa9e4afbf8959a7 Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Tue, 26 Jan 2021 00:53:31 +0000
|
||||
Subject: [PATCH 08/12] upstream: more ssh-agent refactoring
|
||||
|
||||
Allow confirm_key() to accept an additional reason suffix
|
||||
|
||||
Factor publickey userauth parsing out into its own function and allow
|
||||
it to optionally return things it parsed out of the message to its
|
||||
caller.
|
||||
|
||||
feedback/ok markus@
|
||||
|
||||
OpenBSD-Commit-ID: 29006515617d1aa2d8b85cd2bf667e849146477e
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/e0e8bee8024fa9e31974244d14f03d799e5c0775]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-agent.c | 197 ++++++++++++++++++++++++++++++++++------------------
|
||||
1 file changed, 130 insertions(+), 67 deletions(-)
|
||||
|
||||
diff --git a/ssh-agent.c b/ssh-agent.c
|
||||
index 2635bc5..7ad323c 100644
|
||||
--- a/ssh-agent.c
|
||||
+++ b/ssh-agent.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/* $OpenBSD: ssh-agent.c,v 1.269 2021/01/26 00:47:47 djm Exp $ */
|
||||
+/* $OpenBSD: ssh-agent.c,v 1.270 2021/01/26 00:53:31 djm Exp $ */
|
||||
/*
|
||||
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||
@@ -216,15 +216,16 @@ lookup_identity(struct sshkey *key)
|
||||
|
||||
/* Check confirmation of keysign request */
|
||||
static int
|
||||
-confirm_key(Identity *id)
|
||||
+confirm_key(Identity *id, const char *extra)
|
||||
{
|
||||
char *p;
|
||||
int ret = -1;
|
||||
|
||||
p = sshkey_fingerprint(id->key, fingerprint_hash, SSH_FP_DEFAULT);
|
||||
if (p != NULL &&
|
||||
- ask_permission("Allow use of key %s?\nKey fingerprint %s.",
|
||||
- id->comment, p))
|
||||
+ ask_permission("Allow use of key %s?\nKey fingerprint %s.%s%s",
|
||||
+ id->comment, p,
|
||||
+ extra == NULL ? "" : "\n", extra == NULL ? "" : extra))
|
||||
ret = 0;
|
||||
free(p);
|
||||
|
||||
@@ -290,74 +291,133 @@ agent_decode_alg(struct sshkey *key, u_int flags)
|
||||
}
|
||||
|
||||
/*
|
||||
- * This function inspects a message to be signed by a FIDO key that has a
|
||||
- * web-like application string (i.e. one that does not begin with "ssh:".
|
||||
- * It checks that the message is one of those expected for SSH operations
|
||||
- * (pubkey userauth, sshsig, CA key signing) to exclude signing challenges
|
||||
- * for the web.
|
||||
+ * Attempt to parse the contents of a buffer as a SSH publickey userauth
|
||||
+ * request, checking its contents for consistency and matching the embedded
|
||||
+ * key against the one that is being used for signing.
|
||||
+ * Note: does not modify msg buffer.
|
||||
+ * Optionally extract the username and session ID from the request.
|
||||
*/
|
||||
static int
|
||||
-check_websafe_message_contents(struct sshkey *key,
|
||||
- const u_char *msg, size_t len)
|
||||
+parse_userauth_request(struct sshbuf *msg, const struct sshkey *expected_key,
|
||||
+ char **userp, struct sshbuf **sess_idp)
|
||||
{
|
||||
- int matched = 0;
|
||||
- struct sshbuf *b;
|
||||
- u_char m, n;
|
||||
- char *cp1 = NULL, *cp2 = NULL;
|
||||
+ struct sshbuf *b = NULL, *sess_id = NULL;
|
||||
+ char *user = NULL, *service = NULL, *method = NULL, *pkalg = NULL;
|
||||
int r;
|
||||
+ u_char t, sig_follows;
|
||||
struct sshkey *mkey = NULL;
|
||||
|
||||
- if ((b = sshbuf_from(msg, len)) == NULL)
|
||||
- fatal("%s: sshbuf_new", __func__);
|
||||
+ if (userp != NULL)
|
||||
+ *userp = NULL;
|
||||
+ if (sess_idp != NULL)
|
||||
+ *sess_idp = NULL;
|
||||
+ if ((b = sshbuf_fromb(msg)) == NULL)
|
||||
+ fatal("%s: sshbuf_fromb", __func__);
|
||||
|
||||
/* SSH userauth request */
|
||||
- if ((r = sshbuf_get_string_direct(b, NULL, NULL)) == 0 && /* sess_id */
|
||||
- (r = sshbuf_get_u8(b, &m)) == 0 && /* SSH2_MSG_USERAUTH_REQUEST */
|
||||
- (r = sshbuf_get_cstring(b, NULL, NULL)) == 0 && /* server user */
|
||||
- (r = sshbuf_get_cstring(b, &cp1, NULL)) == 0 && /* service */
|
||||
- (r = sshbuf_get_cstring(b, &cp2, NULL)) == 0 && /* method */
|
||||
- (r = sshbuf_get_u8(b, &n)) == 0 && /* sig-follows */
|
||||
- (r = sshbuf_get_cstring(b, NULL, NULL)) == 0 && /* alg */
|
||||
- (r = sshkey_froms(b, &mkey)) == 0 && /* key */
|
||||
- sshbuf_len(b) == 0) {
|
||||
- debug("%s: parsed userauth", __func__);
|
||||
- if (m == SSH2_MSG_USERAUTH_REQUEST && n == 1 &&
|
||||
- strcmp(cp1, "ssh-connection") == 0 &&
|
||||
- strcmp(cp2, "publickey") == 0 &&
|
||||
- sshkey_equal(key, mkey)) {
|
||||
- debug("%s: well formed userauth", __func__);
|
||||
- matched = 1;
|
||||
- }
|
||||
+ if ((r = sshbuf_froms(b, &sess_id)) != 0)
|
||||
+ goto out;
|
||||
+ if (sshbuf_len(sess_id) == 0) {
|
||||
+ r = SSH_ERR_INVALID_FORMAT;
|
||||
+ goto out;
|
||||
}
|
||||
- free(cp1);
|
||||
- free(cp2);
|
||||
- sshkey_free(mkey);
|
||||
+ if ((r = sshbuf_get_u8(b, &t)) != 0 || /* SSH2_MSG_USERAUTH_REQUEST */
|
||||
+ (r = sshbuf_get_cstring(b, &user, NULL)) != 0 || /* server user */
|
||||
+ (r = sshbuf_get_cstring(b, &service, NULL)) != 0 || /* service */
|
||||
+ (r = sshbuf_get_cstring(b, &method, NULL)) != 0 || /* method */
|
||||
+ (r = sshbuf_get_u8(b, &sig_follows)) != 0 || /* sig-follows */
|
||||
+ (r = sshbuf_get_cstring(b, &pkalg, NULL)) != 0 || /* alg */
|
||||
+ (r = sshkey_froms(b, &mkey)) != 0) /* key */
|
||||
+ goto out;
|
||||
+ if (t != SSH2_MSG_USERAUTH_REQUEST ||
|
||||
+ sig_follows != 1 ||
|
||||
+ strcmp(service, "ssh-connection") != 0 ||
|
||||
+ !sshkey_equal(expected_key, mkey) ||
|
||||
+ sshkey_type_from_name(pkalg) != expected_key->type) {
|
||||
+ r = SSH_ERR_INVALID_FORMAT;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ if (strcmp(method, "publickey") != 0) {
|
||||
+ r = SSH_ERR_INVALID_FORMAT;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ if (sshbuf_len(b) != 0) {
|
||||
+ r = SSH_ERR_INVALID_FORMAT;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ /* success */
|
||||
+ r = 0;
|
||||
+ debug("%s: well formed userauth", __func__);
|
||||
+ if (userp != NULL) {
|
||||
+ *userp = user;
|
||||
+ user = NULL;
|
||||
+ }
|
||||
+ if (sess_idp != NULL) {
|
||||
+ *sess_idp = sess_id;
|
||||
+ sess_id = NULL;
|
||||
+ }
|
||||
+ out:
|
||||
sshbuf_free(b);
|
||||
- if (matched)
|
||||
- return 1;
|
||||
+ sshbuf_free(sess_id);
|
||||
+ free(user);
|
||||
+ free(service);
|
||||
+ free(method);
|
||||
+ free(pkalg);
|
||||
+ sshkey_free(mkey);
|
||||
+ return r;
|
||||
+}
|
||||
|
||||
- if ((b = sshbuf_from(msg, len)) == NULL)
|
||||
- fatal("%s: sshbuf_new", __func__);
|
||||
- cp1 = cp2 = NULL;
|
||||
- mkey = NULL;
|
||||
-
|
||||
- /* SSHSIG */
|
||||
- if ((r = sshbuf_cmp(b, 0, "SSHSIG", 6)) == 0 &&
|
||||
- (r = sshbuf_consume(b, 6)) == 0 &&
|
||||
- (r = sshbuf_get_cstring(b, NULL, NULL)) == 0 && /* namespace */
|
||||
- (r = sshbuf_get_string_direct(b, NULL, NULL)) == 0 && /* reserved */
|
||||
- (r = sshbuf_get_cstring(b, NULL, NULL)) == 0 && /* hashalg */
|
||||
- (r = sshbuf_get_string_direct(b, NULL, NULL)) == 0 && /* H(msg) */
|
||||
- sshbuf_len(b) == 0) {
|
||||
- debug("%s: parsed sshsig", __func__);
|
||||
- matched = 1;
|
||||
- }
|
||||
+/*
|
||||
+ * Attempt to parse the contents of a buffer as a SSHSIG signature request.
|
||||
+ * Note: does not modify buffer.
|
||||
+ */
|
||||
+static int
|
||||
+parse_sshsig_request(struct sshbuf *msg)
|
||||
+{
|
||||
+ int r;
|
||||
+ struct sshbuf *b;
|
||||
|
||||
+ if ((b = sshbuf_fromb(msg)) == NULL)
|
||||
+ fatal("%s: sshbuf_fromb", __func__);
|
||||
+
|
||||
+ if ((r = sshbuf_cmp(b, 0, "SSHSIG", 6)) != 0 ||
|
||||
+ (r = sshbuf_consume(b, 6)) != 0 ||
|
||||
+ (r = sshbuf_get_cstring(b, NULL, NULL)) != 0 || /* namespace */
|
||||
+ (r = sshbuf_get_string_direct(b, NULL, NULL)) != 0 || /* reserved */
|
||||
+ (r = sshbuf_get_cstring(b, NULL, NULL)) != 0 || /* hashalg */
|
||||
+ (r = sshbuf_get_string_direct(b, NULL, NULL)) != 0) /* H(msg) */
|
||||
+ goto out;
|
||||
+ if (sshbuf_len(b) != 0) {
|
||||
+ r = SSH_ERR_INVALID_FORMAT;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ /* success */
|
||||
+ r = 0;
|
||||
+ out:
|
||||
sshbuf_free(b);
|
||||
- if (matched)
|
||||
+ return r;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * This function inspects a message to be signed by a FIDO key that has a
|
||||
+ * web-like application string (i.e. one that does not begin with "ssh:".
|
||||
+ * It checks that the message is one of those expected for SSH operations
|
||||
+ * (pubkey userauth, sshsig, CA key signing) to exclude signing challenges
|
||||
+ * for the web.
|
||||
+ */
|
||||
+static int
|
||||
+check_websafe_message_contents(struct sshkey *key, struct sshbuf *data)
|
||||
+{
|
||||
+ if (parse_userauth_request(data, key, NULL, NULL) == 0) {
|
||||
+ debug("%s: signed data matches public key userauth request", __func__);
|
||||
return 1;
|
||||
+ }
|
||||
+ if (parse_sshsig_request(data) == 0) {
|
||||
+ debug("%s: signed data matches SSHSIG signature request", __func__);
|
||||
+ return 1;
|
||||
+ }
|
||||
|
||||
- /* XXX CA signature operation */
|
||||
+ /* XXX check CA signature operation */
|
||||
|
||||
error("web-origin key attempting to sign non-SSH message");
|
||||
return 0;
|
||||
@@ -367,21 +427,22 @@ check_websafe_message_contents(struct sshkey *key,
|
||||
static void
|
||||
process_sign_request2(SocketEntry *e)
|
||||
{
|
||||
- const u_char *data;
|
||||
u_char *signature = NULL;
|
||||
- size_t dlen, slen = 0;
|
||||
+ size_t i, slen = 0;
|
||||
u_int compat = 0, flags;
|
||||
int r, ok = -1;
|
||||
char *fp = NULL;
|
||||
- struct sshbuf *msg;
|
||||
+ struct sshbuf *msg = NULL, *data = NULL;
|
||||
struct sshkey *key = NULL;
|
||||
struct identity *id;
|
||||
struct notifier_ctx *notifier = NULL;
|
||||
|
||||
- if ((msg = sshbuf_new()) == NULL)
|
||||
+ debug("%s: entering", __func__);
|
||||
+
|
||||
+ if ((msg = sshbuf_new()) == NULL | (data = sshbuf_new()) == NULL)
|
||||
fatal("%s: sshbuf_new failed", __func__);
|
||||
if ((r = sshkey_froms(e->request, &key)) != 0 ||
|
||||
- (r = sshbuf_get_string_direct(e->request, &data, &dlen)) != 0 ||
|
||||
+ (r = sshbuf_get_stringb(e->request, data)) != 0 ||
|
||||
(r = sshbuf_get_u32(e->request, &flags)) != 0) {
|
||||
error("%s: couldn't parse request: %s", __func__, ssh_err(r));
|
||||
goto send;
|
||||
@@ -391,13 +452,13 @@ process_sign_request2(SocketEntry *e)
|
||||
verbose("%s: %s key not found", __func__, sshkey_type(key));
|
||||
goto send;
|
||||
}
|
||||
- if (id->confirm && confirm_key(id) != 0) {
|
||||
+ if (id->confirm && confirm_key(id, NULL) != 0) {
|
||||
verbose("%s: user refused key", __func__);
|
||||
goto send;
|
||||
}
|
||||
if (sshkey_is_sk(id->key)) {
|
||||
if (strncmp(id->key->sk_application, "ssh:", 4) != 0 &&
|
||||
- !check_websafe_message_contents(key, data, dlen)) {
|
||||
+ !check_websafe_message_contents(key, data)) {
|
||||
/* error already logged */
|
||||
goto send;
|
||||
}
|
||||
@@ -411,7 +472,7 @@ process_sign_request2(SocketEntry *e)
|
||||
}
|
||||
}
|
||||
if ((r = sshkey_sign(id->key, &signature, &slen,
|
||||
- data, dlen, agent_decode_alg(key, flags),
|
||||
+ sshbuf_ptr(data), sshbuf_len(data), agent_decode_alg(key, flags),
|
||||
id->sk_provider, compat)) != 0) {
|
||||
error("%s: sshkey_sign: %s", __func__, ssh_err(r));
|
||||
goto send;
|
||||
@@ -420,8 +481,7 @@ process_sign_request2(SocketEntry *e)
|
||||
ok = 0;
|
||||
send:
|
||||
notify_complete(notifier);
|
||||
- sshkey_free(key);
|
||||
- free(fp);
|
||||
+
|
||||
if (ok == 0) {
|
||||
if ((r = sshbuf_put_u8(msg, SSH2_AGENT_SIGN_RESPONSE)) != 0 ||
|
||||
(r = sshbuf_put_string(msg, signature, slen)) != 0)
|
||||
@@ -432,7 +492,10 @@ process_sign_request2(SocketEntry *e)
|
||||
if ((r = sshbuf_put_stringb(e->output, msg)) != 0)
|
||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
|
||||
+ sshbuf_free(data);
|
||||
sshbuf_free(msg);
|
||||
+ sshkey_free(key);
|
||||
+ free(fp);
|
||||
free(signature);
|
||||
}
|
||||
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,38 @@
|
||||
From 7adba46611e5d076d7d12d9f4162dd4cabd5ff50 Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Fri, 29 Jan 2021 06:28:10 +0000
|
||||
Subject: [PATCH 09/12] upstream: give typedef'd struct a struct name; makes
|
||||
the fuzzer I'm
|
||||
|
||||
writing a bit easier
|
||||
|
||||
OpenBSD-Commit-ID: 1052ab521505a4d8384d67acb3974ef81b8896cb
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/8afaa7d7918419d3da6c0477b83db2159879cb33]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-agent.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/ssh-agent.c b/ssh-agent.c
|
||||
index 7ad323c..c99927c 100644
|
||||
--- a/ssh-agent.c
|
||||
+++ b/ssh-agent.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/* $OpenBSD: ssh-agent.c,v 1.270 2021/01/26 00:53:31 djm Exp $ */
|
||||
+/* $OpenBSD: ssh-agent.c,v 1.274 2021/01/29 06:28:10 djm Exp $ */
|
||||
/*
|
||||
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||
@@ -108,7 +108,7 @@ typedef enum {
|
||||
AUTH_CONNECTION
|
||||
} sock_type;
|
||||
|
||||
-typedef struct {
|
||||
+typedef struct socket_entry {
|
||||
int fd;
|
||||
sock_type type;
|
||||
struct sshbuf *input;
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,39 @@
|
||||
From 343e2a2c0ef754a7a86118016b248f7a73f8d510 Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Fri, 29 Jan 2021 06:29:46 +0000
|
||||
Subject: [PATCH 10/12] upstream: fix the values of enum sock_type
|
||||
|
||||
OpenBSD-Commit-ID: 18d048f4dbfbb159ff500cfc2700b8fb1407facd
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/1a4b92758690faa12f49079dd3b72567f909466d]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-agent.c | 8 ++++----
|
||||
1 file changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/ssh-agent.c b/ssh-agent.c
|
||||
index c99927c..7f1e14b 100644
|
||||
--- a/ssh-agent.c
|
||||
+++ b/ssh-agent.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/* $OpenBSD: ssh-agent.c,v 1.274 2021/01/29 06:28:10 djm Exp $ */
|
||||
+/* $OpenBSD: ssh-agent.c,v 1.275 2021/01/29 06:29:46 djm Exp $ */
|
||||
/*
|
||||
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||
@@ -103,9 +103,9 @@
|
||||
#define AGENT_RBUF_LEN (4096)
|
||||
|
||||
typedef enum {
|
||||
- AUTH_UNUSED,
|
||||
- AUTH_SOCKET,
|
||||
- AUTH_CONNECTION
|
||||
+ AUTH_UNUSED = 0,
|
||||
+ AUTH_SOCKET = 1,
|
||||
+ AUTH_CONNECTION = 2,
|
||||
} sock_type;
|
||||
|
||||
typedef struct socket_entry {
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,307 @@
|
||||
From 2b3b369c8cf71f9ef5942a5e074e6f86e7ca1e0c Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Sun, 19 Dec 2021 22:09:23 +0000
|
||||
Subject: [PATCH 11/12] upstream: ssh-agent side of binding
|
||||
|
||||
record session ID/hostkey/forwarding status for each active socket.
|
||||
|
||||
Attempt to parse data-to-be-signed at signature request time and extract
|
||||
session ID from the blob if it is a pubkey userauth request.
|
||||
|
||||
ok markus@
|
||||
|
||||
OpenBSD-Commit-ID: a80fd41e292b18b67508362129e9fed549abd318
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/4c1e3ce85e183a9d0c955c88589fed18e4d6a058]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
authfd.h | 3 +
|
||||
ssh-agent.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++---
|
||||
2 files changed, 170 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/authfd.h b/authfd.h
|
||||
index c3bf625..9cc9807 100644
|
||||
--- a/authfd.h
|
||||
+++ b/authfd.h
|
||||
@@ -76,6 +76,9 @@ int ssh_agent_sign(int sock, const struct sshkey *key,
|
||||
#define SSH2_AGENTC_ADD_ID_CONSTRAINED 25
|
||||
#define SSH_AGENTC_ADD_SMARTCARD_KEY_CONSTRAINED 26
|
||||
|
||||
+/* generic extension mechanism */
|
||||
+#define SSH_AGENTC_EXTENSION 27
|
||||
+
|
||||
#define SSH_AGENT_CONSTRAIN_LIFETIME 1
|
||||
#define SSH_AGENT_CONSTRAIN_CONFIRM 2
|
||||
#define SSH_AGENT_CONSTRAIN_MAXSIGN 3
|
||||
diff --git a/ssh-agent.c b/ssh-agent.c
|
||||
index 7f1e14b..01c7f2b 100644
|
||||
--- a/ssh-agent.c
|
||||
+++ b/ssh-agent.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/* $OpenBSD: ssh-agent.c,v 1.275 2021/01/29 06:29:46 djm Exp $ */
|
||||
+/* $OpenBSD: ssh-agent.c,v 1.280 2021/12/19 22:09:23 djm Exp $ */
|
||||
/*
|
||||
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||
@@ -98,9 +98,15 @@
|
||||
#endif
|
||||
|
||||
/* Maximum accepted message length */
|
||||
-#define AGENT_MAX_LEN (256*1024)
|
||||
+#define AGENT_MAX_LEN (256*1024)
|
||||
/* Maximum bytes to read from client socket */
|
||||
-#define AGENT_RBUF_LEN (4096)
|
||||
+#define AGENT_RBUF_LEN (4096)
|
||||
+/* Maximum number of recorded session IDs/hostkeys per connection */
|
||||
+#define AGENT_MAX_SESSION_IDS 16
|
||||
+/* Maximum size of session ID */
|
||||
+#define AGENT_MAX_SID_LEN 128
|
||||
+
|
||||
+/* XXX store hostkey_sid in a refcounted tree */
|
||||
|
||||
typedef enum {
|
||||
AUTH_UNUSED = 0,
|
||||
@@ -108,12 +114,20 @@ typedef enum {
|
||||
AUTH_CONNECTION = 2,
|
||||
} sock_type;
|
||||
|
||||
+struct hostkey_sid {
|
||||
+ struct sshkey *key;
|
||||
+ struct sshbuf *sid;
|
||||
+ int forwarded;
|
||||
+};
|
||||
+
|
||||
typedef struct socket_entry {
|
||||
int fd;
|
||||
sock_type type;
|
||||
struct sshbuf *input;
|
||||
struct sshbuf *output;
|
||||
struct sshbuf *request;
|
||||
+ size_t nsession_ids;
|
||||
+ struct hostkey_sid *session_ids;
|
||||
} SocketEntry;
|
||||
|
||||
u_int sockets_alloc = 0;
|
||||
@@ -174,10 +188,17 @@ static int restrict_websafe = 1;
|
||||
static void
|
||||
close_socket(SocketEntry *e)
|
||||
{
|
||||
+ size_t i;
|
||||
+
|
||||
close(e->fd);
|
||||
sshbuf_free(e->input);
|
||||
sshbuf_free(e->output);
|
||||
sshbuf_free(e->request);
|
||||
+ for (i = 0; i < e->nsession_ids; i++) {
|
||||
+ sshkey_free(e->session_ids[i].key);
|
||||
+ sshbuf_free(e->session_ids[i].sid);
|
||||
+ }
|
||||
+ free(e->session_ids);
|
||||
memset(e, '\0', sizeof(*e));
|
||||
e->fd = -1;
|
||||
e->type = AUTH_UNUSED;
|
||||
@@ -423,6 +444,18 @@ check_websafe_message_contents(struct sshkey *key, struct sshbuf *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static int
|
||||
+buf_equal(const struct sshbuf *a, const struct sshbuf *b)
|
||||
+{
|
||||
+ if (sshbuf_ptr(a) == NULL || sshbuf_ptr(b) == NULL)
|
||||
+ return SSH_ERR_INVALID_ARGUMENT;
|
||||
+ if (sshbuf_len(a) != sshbuf_len(b))
|
||||
+ return SSH_ERR_INVALID_FORMAT;
|
||||
+ if (timingsafe_bcmp(sshbuf_ptr(a), sshbuf_ptr(b), sshbuf_len(a)) != 0)
|
||||
+ return SSH_ERR_INVALID_FORMAT;
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
/* ssh2 only */
|
||||
static void
|
||||
process_sign_request2(SocketEntry *e)
|
||||
@@ -431,8 +464,8 @@ process_sign_request2(SocketEntry *e)
|
||||
size_t i, slen = 0;
|
||||
u_int compat = 0, flags;
|
||||
int r, ok = -1;
|
||||
- char *fp = NULL;
|
||||
- struct sshbuf *msg = NULL, *data = NULL;
|
||||
+ char *fp = NULL, *user = NULL, *sig_dest = NULL;
|
||||
+ struct sshbuf *msg = NULL, *data = NULL, *sid = NULL;
|
||||
struct sshkey *key = NULL;
|
||||
struct identity *id;
|
||||
struct notifier_ctx *notifier = NULL;
|
||||
@@ -452,7 +485,33 @@ process_sign_request2(SocketEntry *e)
|
||||
verbose("%s: %s key not found", __func__, sshkey_type(key));
|
||||
goto send;
|
||||
}
|
||||
- if (id->confirm && confirm_key(id, NULL) != 0) {
|
||||
+ /*
|
||||
+ * If session IDs were recorded for this socket, then use them to
|
||||
+ * annotate the confirmation messages with the host keys.
|
||||
+ */
|
||||
+ if (e->nsession_ids > 0 &&
|
||||
+ parse_userauth_request(data, key, &user, &sid) == 0) {
|
||||
+ /*
|
||||
+ * session ID from userauth request should match the final
|
||||
+ * ID in the list recorded in the socket, unless the ssh
|
||||
+ * client at that point lacks the binding extension (or if
|
||||
+ * an attacker is trying to steal use of the agent).
|
||||
+ */
|
||||
+ i = e->nsession_ids - 1;
|
||||
+ if (buf_equal(sid, e->session_ids[i].sid) == 0) {
|
||||
+ if ((fp = sshkey_fingerprint(e->session_ids[i].key,
|
||||
+ SSH_FP_HASH_DEFAULT, SSH_FP_DEFAULT)) == NULL)
|
||||
+ fatal("%s: fingerprint failed", __func__);
|
||||
+ debug3("%s: destination %s %s (slot %zu)", __func__,
|
||||
+ sshkey_type(e->session_ids[i].key), fp, i);
|
||||
+ xasprintf(&sig_dest, "public key request for "
|
||||
+ "target user \"%s\" to %s %s", user,
|
||||
+ sshkey_type(e->session_ids[i].key), fp);
|
||||
+ free(fp);
|
||||
+ fp = NULL;
|
||||
+ }
|
||||
+ }//
|
||||
+ if (id->confirm && confirm_key(id, sig_dest) != 0) {
|
||||
verbose("%s: user refused key", __func__);
|
||||
goto send;
|
||||
}
|
||||
@@ -467,8 +526,10 @@ process_sign_request2(SocketEntry *e)
|
||||
SSH_FP_DEFAULT)) == NULL)
|
||||
fatal("%s: fingerprint failed", __func__);
|
||||
notifier = notify_start(0,
|
||||
- "Confirm user presence for key %s %s",
|
||||
- sshkey_type(id->key), fp);
|
||||
+ "Confirm user presence for key %s %s%s%s",
|
||||
+ sshkey_type(id->key), fp,
|
||||
+ sig_dest == NULL ? "" : "\n",
|
||||
+ sig_dest == NULL ? "" : sig_dest);
|
||||
}
|
||||
}
|
||||
if ((r = sshkey_sign(id->key, &signature, &slen,
|
||||
@@ -492,11 +553,14 @@ process_sign_request2(SocketEntry *e)
|
||||
if ((r = sshbuf_put_stringb(e->output, msg)) != 0)
|
||||
fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
||||
|
||||
+ sshbuf_free(sid);
|
||||
sshbuf_free(data);
|
||||
sshbuf_free(msg);
|
||||
sshkey_free(key);
|
||||
free(fp);
|
||||
free(signature);
|
||||
+ free(sig_dest);
|
||||
+ free(user);
|
||||
}
|
||||
|
||||
/* shared */
|
||||
@@ -925,6 +989,98 @@ send:
|
||||
}
|
||||
#endif /* ENABLE_PKCS11 */
|
||||
|
||||
+static int
|
||||
+process_ext_session_bind(SocketEntry *e)
|
||||
+{
|
||||
+ int r, sid_match, key_match;
|
||||
+ struct sshkey *key = NULL;
|
||||
+ struct sshbuf *sid = NULL, *sig = NULL;
|
||||
+ char *fp = NULL;
|
||||
+ u_char fwd;
|
||||
+ size_t i;
|
||||
+
|
||||
+ debug2("%s: entering", __func__);
|
||||
+ if ((r = sshkey_froms(e->request, &key)) != 0 ||
|
||||
+ (r = sshbuf_froms(e->request, &sid)) != 0 ||
|
||||
+ (r = sshbuf_froms(e->request, &sig)) != 0 ||
|
||||
+ (r = sshbuf_get_u8(e->request, &fwd)) != 0) {
|
||||
+ error("%s: parse: %s", __func__, ssh_err(r));
|
||||
+ goto out;
|
||||
+ }
|
||||
+ if ((fp = sshkey_fingerprint(key, SSH_FP_HASH_DEFAULT,
|
||||
+ SSH_FP_DEFAULT)) == NULL)
|
||||
+ fatal("%s: fingerprint failed", __func__);
|
||||
+ /* check signature with hostkey on session ID */
|
||||
+ if ((r = sshkey_verify(key, sshbuf_ptr(sig), sshbuf_len(sig),
|
||||
+ sshbuf_ptr(sid), sshbuf_len(sid), NULL, 0, NULL)) != 0) {
|
||||
+ error("%s: sshkey_verify for %s %s: %s", __func__, sshkey_type(key), fp, ssh_err(r));
|
||||
+ goto out;
|
||||
+ }
|
||||
+ /* check whether sid/key already recorded */
|
||||
+ for (i = 0; i < e->nsession_ids; i++) {
|
||||
+ sid_match = buf_equal(sid, e->session_ids[i].sid) == 0;
|
||||
+ key_match = sshkey_equal(key, e->session_ids[i].key);
|
||||
+ if (sid_match && key_match) {
|
||||
+ debug("%s: session ID already recorded for %s %s", __func__,
|
||||
+ sshkey_type(key), fp);
|
||||
+ r = 0;
|
||||
+ goto out;
|
||||
+ } else if (sid_match) {
|
||||
+ error("%s: session ID recorded against different key "
|
||||
+ "for %s %s", __func__, sshkey_type(key), fp);
|
||||
+ r = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ /*
|
||||
+ * new sid with previously-seen key can happen, e.g. multiple
|
||||
+ * connections to the same host.
|
||||
+ */
|
||||
+ }
|
||||
+ /* record new key/sid */
|
||||
+ if (e->nsession_ids >= AGENT_MAX_SESSION_IDS) {
|
||||
+ error("%s: too many session IDs recorded", __func__);
|
||||
+ goto out;
|
||||
+ }
|
||||
+ e->session_ids = xrecallocarray(e->session_ids, e->nsession_ids,
|
||||
+ e->nsession_ids + 1, sizeof(*e->session_ids));
|
||||
+ i = e->nsession_ids++;
|
||||
+ debug("%s: recorded %s %s (slot %zu of %d)", __func__, sshkey_type(key), fp, i,
|
||||
+ AGENT_MAX_SESSION_IDS);
|
||||
+ e->session_ids[i].key = key;
|
||||
+ e->session_ids[i].forwarded = fwd != 0;
|
||||
+ key = NULL; /* transferred */
|
||||
+ /* can't transfer sid; it's refcounted and scoped to request's life */
|
||||
+ if ((e->session_ids[i].sid = sshbuf_new()) == NULL)
|
||||
+ fatal("%s: sshbuf_new", __func__);
|
||||
+ if ((r = sshbuf_putb(e->session_ids[i].sid, sid)) != 0)
|
||||
+ fatal("%s: sshbuf_putb session ID: %s", __func__, ssh_err(r));
|
||||
+ /* success */
|
||||
+ r = 0;
|
||||
+ out:
|
||||
+ sshkey_free(key);
|
||||
+ sshbuf_free(sid);
|
||||
+ sshbuf_free(sig);
|
||||
+ return r == 0 ? 1 : 0;
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+process_extension(SocketEntry *e)
|
||||
+{
|
||||
+ int r, success = 0;
|
||||
+ char *name;
|
||||
+
|
||||
+ debug2("%s: entering", __func__);
|
||||
+ if ((r = sshbuf_get_cstring(e->request, &name, NULL)) != 0) {
|
||||
+ error("%s: parse: %s", __func__, ssh_err(r));
|
||||
+ goto send;
|
||||
+ }
|
||||
+ if (strcmp(name, "session-bind@openssh.com") == 0)
|
||||
+ success = process_ext_session_bind(e);
|
||||
+ else
|
||||
+ debug("%s: unsupported extension \"%s\"", __func__, name);
|
||||
+send:
|
||||
+ send_status(e, success);
|
||||
+}
|
||||
/*
|
||||
* dispatch incoming message.
|
||||
* returns 1 on success, 0 for incomplete messages or -1 on error.
|
||||
@@ -1019,6 +1175,9 @@ process_message(u_int socknum)
|
||||
process_remove_smartcard_key(e);
|
||||
break;
|
||||
#endif /* ENABLE_PKCS11 */
|
||||
+ case SSH_AGENTC_EXTENSION:
|
||||
+ process_extension(e);
|
||||
+ break;
|
||||
default:
|
||||
/* Unknown message. Respond with failure. */
|
||||
error("Unknown message %d", type);
|
||||
--
|
||||
2.41.0
|
||||
@@ -0,0 +1,120 @@
|
||||
From 4fe3d0fbd3d6dc1f19354e0d73a3231c461ed044 Mon Sep 17 00:00:00 2001
|
||||
From: "djm@openbsd.org" <djm@openbsd.org>
|
||||
Date: Wed, 19 Jul 2023 13:56:33 +0000
|
||||
Subject: [PATCH 12/12] upstream: Disallow remote addition of FIDO/PKCS11
|
||||
provider libraries to ssh-agent by default.
|
||||
|
||||
The old behaviour of allowing remote clients from loading providers
|
||||
can be restored using `ssh-agent -O allow-remote-pkcs11`.
|
||||
|
||||
Detection of local/remote clients requires a ssh(1) that supports
|
||||
the `session-bind@openssh.com` extension. Forwarding access to a
|
||||
ssh-agent socket using non-OpenSSH tools may circumvent this control.
|
||||
|
||||
ok markus@
|
||||
|
||||
OpenBSD-Commit-ID: 4c2bdf79b214ae7e60cc8c39a45501344fa7bd7c
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssh/openssh-portable/commit/1f2731f5d7a8f8a8385c6031667ed29072c0d92a]
|
||||
CVE: CVE-2023-38408
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
ssh-agent.1 | 20 ++++++++++++++++++++
|
||||
ssh-agent.c | 26 ++++++++++++++++++++++++--
|
||||
2 files changed, 44 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/ssh-agent.1 b/ssh-agent.1
|
||||
index fff0db6..a0f1e21 100644
|
||||
--- a/ssh-agent.1
|
||||
+++ b/ssh-agent.1
|
||||
@@ -97,6 +97,26 @@ The default is
|
||||
Kill the current agent (given by the
|
||||
.Ev SSH_AGENT_PID
|
||||
environment variable).
|
||||
+Currently two options are supported:
|
||||
+.Cm allow-remote-pkcs11
|
||||
+and
|
||||
+.Pp
|
||||
+The
|
||||
+.Cm allow-remote-pkcs11
|
||||
+option allows clients of a forwarded
|
||||
+.Nm
|
||||
+to load PKCS#11 or FIDO provider libraries.
|
||||
+By default only local clients may perform this operation.
|
||||
+Note that signalling that a
|
||||
+.Nm
|
||||
+client remote is performed by
|
||||
+.Xr ssh 1 ,
|
||||
+and use of other tools to forward access to the agent socket may circumvent
|
||||
+this restriction.
|
||||
+.Pp
|
||||
+The
|
||||
+.Cm no-restrict-websafe ,
|
||||
+instructs
|
||||
.It Fl P Ar provider_whitelist
|
||||
Specify a pattern-list of acceptable paths for PKCS#11 and FIDO authenticator
|
||||
shared libraries that may be used with the
|
||||
diff --git a/ssh-agent.c b/ssh-agent.c
|
||||
index 01c7f2b..40c1b6b 100644
|
||||
--- a/ssh-agent.c
|
||||
+++ b/ssh-agent.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/* $OpenBSD: ssh-agent.c,v 1.280 2021/12/19 22:09:23 djm Exp $ */
|
||||
+/* $OpenBSD: ssh-agent.c,v 1.300 2023/07/19 13:56:33 djm Exp $ */
|
||||
/*
|
||||
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
||||
@@ -167,6 +167,12 @@ char socket_dir[PATH_MAX];
|
||||
/* PKCS#11/Security key path whitelist */
|
||||
static char *provider_whitelist;
|
||||
|
||||
+/*
|
||||
+ * Allows PKCS11 providers or SK keys that use non-internal providers to
|
||||
+ * be added over a remote connection (identified by session-bind@openssh.com).
|
||||
+ */
|
||||
+static int remote_add_provider;
|
||||
+
|
||||
/* locking */
|
||||
#define LOCK_SIZE 32
|
||||
#define LOCK_SALT_SIZE 16
|
||||
@@ -736,6 +742,15 @@ process_add_identity(SocketEntry *e)
|
||||
if (strcasecmp(sk_provider, "internal") == 0) {
|
||||
debug("%s: internal provider", __func__);
|
||||
} else {
|
||||
+ if (e->nsession_ids != 0 && !remote_add_provider) {
|
||||
+ verbose("failed add of SK provider \"%.100s\": "
|
||||
+ "remote addition of providers is disabled",
|
||||
+ sk_provider);
|
||||
+ free(sk_provider);
|
||||
+ free(comment);
|
||||
+ sshkey_free(k);
|
||||
+ goto send;
|
||||
+ }
|
||||
if (realpath(sk_provider, canonical_provider) == NULL) {
|
||||
verbose("failed provider \"%.100s\": "
|
||||
"realpath: %s", sk_provider,
|
||||
@@ -901,6 +916,11 @@ process_add_smartcard_key(SocketEntry *e)
|
||||
goto send;
|
||||
}
|
||||
}
|
||||
+ if (e->nsession_ids != 0 && !remote_add_provider) {
|
||||
+ verbose("failed PKCS#11 add of \"%.100s\": remote addition of "
|
||||
+ "providers is disabled", provider);
|
||||
+ goto send;
|
||||
+ }
|
||||
if (realpath(provider, canonical_provider) == NULL) {
|
||||
verbose("failed PKCS#11 add of \"%.100s\": realpath: %s",
|
||||
provider, strerror(errno));
|
||||
@@ -1556,7 +1576,9 @@ main(int ac, char **av)
|
||||
break;
|
||||
case 'O':
|
||||
if (strcmp(optarg, "no-restrict-websafe") == 0)
|
||||
- restrict_websafe = 0;
|
||||
+ restrict_websafe = 0;
|
||||
+ else if (strcmp(optarg, "allow-remote-pkcs11") == 0)
|
||||
+ remote_add_provider = 1;
|
||||
else
|
||||
fatal("Unknown -O option");
|
||||
break;
|
||||
--
|
||||
2.41.0
|
||||
@@ -27,6 +27,18 @@ SRC_URI = "http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${PV}.tar
|
||||
file://CVE-2020-14145.patch \
|
||||
file://CVE-2021-28041.patch \
|
||||
file://CVE-2021-41617.patch \
|
||||
file://CVE-2023-38408-01.patch \
|
||||
file://CVE-2023-38408-02.patch \
|
||||
file://CVE-2023-38408-03.patch \
|
||||
file://CVE-2023-38408-04.patch \
|
||||
file://CVE-2023-38408-05.patch \
|
||||
file://CVE-2023-38408-06.patch \
|
||||
file://CVE-2023-38408-07.patch \
|
||||
file://CVE-2023-38408-08.patch \
|
||||
file://CVE-2023-38408-09.patch \
|
||||
file://CVE-2023-38408-10.patch \
|
||||
file://CVE-2023-38408-11.patch \
|
||||
file://CVE-2023-38408-12.patch \
|
||||
"
|
||||
SRC_URI[md5sum] = "3076e6413e8dbe56d33848c1054ac091"
|
||||
SRC_URI[sha256sum] = "43925151e6cf6cee1450190c0e9af4dc36b41c12737619edff8bcebdff64e671"
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
From 326909baf81a638d51fa8be1d8227518784f5cc4 Mon Sep 17 00:00:00 2001
|
||||
From: Alexander Kanavin <alex@linutronix.de>
|
||||
Date: Tue, 14 Sep 2021 12:18:25 +0200
|
||||
Subject: [PATCH] Configure: do not tweak mips cflags
|
||||
|
||||
This conflicts with mips machine definitons from yocto,
|
||||
e.g.
|
||||
| Error: -mips3 conflicts with the other architecture options, which imply -mips64r2
|
||||
|
||||
Upstream-Status: Inappropriate [oe-core specific]
|
||||
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
|
||||
Signed-off-by: Peter Marko <peter.marko@siemens.com>
|
||||
---
|
||||
Configure | 10 ----------
|
||||
1 file changed, 10 deletions(-)
|
||||
|
||||
Index: openssl-3.0.4/Configure
|
||||
===================================================================
|
||||
--- openssl-3.0.4.orig/Configure
|
||||
+++ openssl-3.0.4/Configure
|
||||
@@ -1243,16 +1243,6 @@ if ($target =~ /^mingw/ && `$config{CC} --target-help 2>&1` =~ m/-mno-cygwin/m)
|
||||
push @{$config{shared_ldflag}}, "-mno-cygwin";
|
||||
}
|
||||
|
||||
-if ($target =~ /linux.*-mips/ && !$disabled{asm}
|
||||
- && !grep { $_ =~ /-m(ips|arch=)/ } (@{$config{CFLAGS}})) {
|
||||
- # minimally required architecture flags for assembly modules
|
||||
- my $value;
|
||||
- $value = '-mips2' if ($target =~ /mips32/);
|
||||
- $value = '-mips3' if ($target =~ /mips64/);
|
||||
- unshift @{$config{cflags}}, $value;
|
||||
- unshift @{$config{cxxflags}}, $value if $config{CXX};
|
||||
-}
|
||||
-
|
||||
# If threads aren't disabled, check how possible they are
|
||||
unless ($disabled{threads}) {
|
||||
if ($auto_threads) {
|
||||
@@ -1,226 +0,0 @@
|
||||
From 879f7080d7e141f415c79eaa3a8ac4a3dad0348b Mon Sep 17 00:00:00 2001
|
||||
From: Pauli <pauli@openssl.org>
|
||||
Date: Wed, 8 Mar 2023 15:28:20 +1100
|
||||
Subject: [PATCH] x509: excessive resource use verifying policy constraints
|
||||
|
||||
A security vulnerability has been identified in all supported versions
|
||||
of OpenSSL related to the verification of X.509 certificate chains
|
||||
that include policy constraints. Attackers may be able to exploit this
|
||||
vulnerability by creating a malicious certificate chain that triggers
|
||||
exponential use of computational resources, leading to a denial-of-service
|
||||
(DoS) attack on affected systems.
|
||||
|
||||
Fixes CVE-2023-0464
|
||||
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
|
||||
(Merged from https://github.com/openssl/openssl/pull/20569)
|
||||
|
||||
CVE: CVE-2023-0464
|
||||
Upstream-Status: Backport [https://git.openssl.org/gitweb/?p=openssl.git;a=patch;h=879f7080d7e141f415c79eaa3a8ac4a3dad0348b]
|
||||
Signed-off-by: Nikhil R <nikhil.r@kpit.com>
|
||||
|
||||
---
|
||||
crypto/x509v3/pcy_local.h | 8 +++++++-
|
||||
crypto/x509v3/pcy_node.c | 12 +++++++++---
|
||||
crypto/x509v3/pcy_tree.c | 37 +++++++++++++++++++++++++++----------
|
||||
3 files changed, 43 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/crypto/x509v3/pcy_local.h b/crypto/x509v3/pcy_local.h
|
||||
index 5daf78de45..344aa06765 100644
|
||||
--- a/crypto/x509v3/pcy_local.h
|
||||
+++ b/crypto/x509v3/pcy_local.h
|
||||
@@ -111,6 +111,11 @@ struct X509_POLICY_LEVEL_st {
|
||||
};
|
||||
|
||||
struct X509_POLICY_TREE_st {
|
||||
+ /* The number of nodes in the tree */
|
||||
+ size_t node_count;
|
||||
+ /* The maximum number of nodes in the tree */
|
||||
+ size_t node_maximum;
|
||||
+
|
||||
/* This is the tree 'level' data */
|
||||
X509_POLICY_LEVEL *levels;
|
||||
int nlevel;
|
||||
@@ -159,7 +164,8 @@ X509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk,
|
||||
X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
|
||||
X509_POLICY_DATA *data,
|
||||
X509_POLICY_NODE *parent,
|
||||
- X509_POLICY_TREE *tree);
|
||||
+ X509_POLICY_TREE *tree,
|
||||
+ int extra_data);
|
||||
void policy_node_free(X509_POLICY_NODE *node);
|
||||
int policy_node_match(const X509_POLICY_LEVEL *lvl,
|
||||
const X509_POLICY_NODE *node, const ASN1_OBJECT *oid);
|
||||
diff --git a/crypto/x509v3/pcy_node.c b/crypto/x509v3/pcy_node.c
|
||||
index e2d7b15322..d574fb9d66 100644
|
||||
--- a/crypto/x509v3/pcy_node.c
|
||||
+++ b/crypto/x509v3/pcy_node.c
|
||||
@@ -59,10 +59,15 @@ X509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level,
|
||||
X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
|
||||
X509_POLICY_DATA *data,
|
||||
X509_POLICY_NODE *parent,
|
||||
- X509_POLICY_TREE *tree)
|
||||
+ X509_POLICY_TREE *tree,
|
||||
+ int extra_data)
|
||||
{
|
||||
X509_POLICY_NODE *node;
|
||||
|
||||
+ /* Verify that the tree isn't too large. This mitigates CVE-2023-0464 */
|
||||
+ if (tree->node_maximum > 0 && tree->node_count >= tree->node_maximum)
|
||||
+ return NULL;
|
||||
+
|
||||
node = OPENSSL_zalloc(sizeof(*node));
|
||||
if (node == NULL) {
|
||||
X509V3err(X509V3_F_LEVEL_ADD_NODE, ERR_R_MALLOC_FAILURE);
|
||||
@@ -70,7 +75,7 @@ X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
|
||||
}
|
||||
node->data = data;
|
||||
node->parent = parent;
|
||||
- if (level) {
|
||||
+ if (level != NULL) {
|
||||
if (OBJ_obj2nid(data->valid_policy) == NID_any_policy) {
|
||||
if (level->anyPolicy)
|
||||
goto node_error;
|
||||
@@ -90,7 +95,7 @@ X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
|
||||
}
|
||||
}
|
||||
|
||||
- if (tree) {
|
||||
+ if (extra_data) {
|
||||
if (tree->extra_data == NULL)
|
||||
tree->extra_data = sk_X509_POLICY_DATA_new_null();
|
||||
if (tree->extra_data == NULL){
|
||||
@@ -103,6 +108,7 @@ X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
|
||||
}
|
||||
}
|
||||
|
||||
+ tree->node_count++;
|
||||
if (parent)
|
||||
parent->nchild++;
|
||||
|
||||
diff --git a/crypto/x509v3/pcy_tree.c b/crypto/x509v3/pcy_tree.c
|
||||
index 6e8322cbc5..6c7fd35405 100644
|
||||
--- a/crypto/x509v3/pcy_tree.c
|
||||
+++ b/crypto/x509v3/pcy_tree.c
|
||||
@@ -13,6 +13,18 @@
|
||||
|
||||
#include "pcy_local.h"
|
||||
|
||||
+/*
|
||||
+ * If the maximum number of nodes in the policy tree isn't defined, set it to
|
||||
+ * a generous default of 1000 nodes.
|
||||
+ *
|
||||
+ * Defining this to be zero means unlimited policy tree growth which opens the
|
||||
+ * door on CVE-2023-0464.
|
||||
+ */
|
||||
+
|
||||
+#ifndef OPENSSL_POLICY_TREE_NODES_MAX
|
||||
+# define OPENSSL_POLICY_TREE_NODES_MAX 1000
|
||||
+#endif
|
||||
+
|
||||
/*
|
||||
* Enable this to print out the complete policy tree at various point during
|
||||
* evaluation.
|
||||
@@ -168,6 +180,9 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
|
||||
return X509_PCY_TREE_INTERNAL;
|
||||
}
|
||||
|
||||
+ /* Limit the growth of the tree to mitigate CVE-2023-0464 */
|
||||
+ tree->node_maximum = OPENSSL_POLICY_TREE_NODES_MAX;
|
||||
+
|
||||
/*
|
||||
* http://tools.ietf.org/html/rfc5280#section-6.1.2, figure 3.
|
||||
*
|
||||
@@ -184,7 +199,7 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
|
||||
level = tree->levels;
|
||||
if ((data = policy_data_new(NULL, OBJ_nid2obj(NID_any_policy), 0)) == NULL)
|
||||
goto bad_tree;
|
||||
- if (level_add_node(level, data, NULL, tree) == NULL) {
|
||||
+ if (level_add_node(level, data, NULL, tree, 1) == NULL) {
|
||||
policy_data_free(data);
|
||||
goto bad_tree;
|
||||
}
|
||||
@@ -243,7 +258,8 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
|
||||
* Return value: 1 on success, 0 otherwise
|
||||
*/
|
||||
static int tree_link_matching_nodes(X509_POLICY_LEVEL *curr,
|
||||
- X509_POLICY_DATA *data)
|
||||
+ X509_POLICY_DATA *data,
|
||||
+ X509_POLICY_TREE *tree)
|
||||
{
|
||||
X509_POLICY_LEVEL *last = curr - 1;
|
||||
int i, matched = 0;
|
||||
@@ -253,13 +269,13 @@ static int tree_link_matching_nodes(X509_POLICY_LEVEL *curr,
|
||||
X509_POLICY_NODE *node = sk_X509_POLICY_NODE_value(last->nodes, i);
|
||||
|
||||
if (policy_node_match(last, node, data->valid_policy)) {
|
||||
- if (level_add_node(curr, data, node, NULL) == NULL)
|
||||
+ if (level_add_node(curr, data, node, tree, 0) == NULL)
|
||||
return 0;
|
||||
matched = 1;
|
||||
}
|
||||
}
|
||||
if (!matched && last->anyPolicy) {
|
||||
- if (level_add_node(curr, data, last->anyPolicy, NULL) == NULL)
|
||||
+ if (level_add_node(curr, data, last->anyPolicy, tree, 0) == NULL)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@@ -272,7 +288,8 @@ static int tree_link_matching_nodes(X509_POLICY_LEVEL *curr,
|
||||
* Return value: 1 on success, 0 otherwise.
|
||||
*/
|
||||
static int tree_link_nodes(X509_POLICY_LEVEL *curr,
|
||||
- const X509_POLICY_CACHE *cache)
|
||||
+ const X509_POLICY_CACHE *cache,
|
||||
+ X509_POLICY_TREE *tree)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -280,7 +297,7 @@ static int tree_link_nodes(X509_POLICY_LEVEL *curr,
|
||||
X509_POLICY_DATA *data = sk_X509_POLICY_DATA_value(cache->data, i);
|
||||
|
||||
/* Look for matching nodes in previous level */
|
||||
- if (!tree_link_matching_nodes(curr, data))
|
||||
+ if (!tree_link_matching_nodes(curr, data, tree))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@@ -311,7 +328,7 @@ static int tree_add_unmatched(X509_POLICY_LEVEL *curr,
|
||||
/* Curr may not have anyPolicy */
|
||||
data->qualifier_set = cache->anyPolicy->qualifier_set;
|
||||
data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS;
|
||||
- if (level_add_node(curr, data, node, tree) == NULL) {
|
||||
+ if (level_add_node(curr, data, node, tree, 1) == NULL) {
|
||||
policy_data_free(data);
|
||||
return 0;
|
||||
}
|
||||
@@ -373,7 +390,7 @@ static int tree_link_any(X509_POLICY_LEVEL *curr,
|
||||
}
|
||||
/* Finally add link to anyPolicy */
|
||||
if (last->anyPolicy &&
|
||||
- level_add_node(curr, cache->anyPolicy, last->anyPolicy, NULL) == NULL)
|
||||
+ level_add_node(curr, cache->anyPolicy, last->anyPolicy, tree, 0) == NULL)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
@@ -555,7 +572,7 @@ static int tree_calculate_user_set(X509_POLICY_TREE *tree,
|
||||
extra->qualifier_set = anyPolicy->data->qualifier_set;
|
||||
extra->flags = POLICY_DATA_FLAG_SHARED_QUALIFIERS
|
||||
| POLICY_DATA_FLAG_EXTRA_NODE;
|
||||
- node = level_add_node(NULL, extra, anyPolicy->parent, tree);
|
||||
+ node = level_add_node(NULL, extra, anyPolicy->parent, tree, 1);
|
||||
}
|
||||
if (!tree->user_policies) {
|
||||
tree->user_policies = sk_X509_POLICY_NODE_new_null();
|
||||
@@ -582,7 +599,7 @@ static int tree_evaluate(X509_POLICY_TREE *tree)
|
||||
|
||||
for (i = 1; i < tree->nlevel; i++, curr++) {
|
||||
cache = policy_cache_set(curr->cert);
|
||||
- if (!tree_link_nodes(curr, cache))
|
||||
+ if (!tree_link_nodes(curr, cache, tree))
|
||||
return X509_PCY_TREE_INTERNAL;
|
||||
|
||||
if (!(curr->flags & X509_V_FLAG_INHIBIT_ANY)
|
||||
--
|
||||
2.34.1
|
||||
@@ -1,60 +0,0 @@
|
||||
From b013765abfa80036dc779dd0e50602c57bb3bf95 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Tue, 7 Mar 2023 16:52:55 +0000
|
||||
Subject: [PATCH] Ensure that EXFLAG_INVALID_POLICY is checked even in leaf
|
||||
certs
|
||||
|
||||
Even though we check the leaf cert to confirm it is valid, we
|
||||
later ignored the invalid flag and did not notice that the leaf
|
||||
cert was bad.
|
||||
|
||||
Fixes: CVE-2023-0465
|
||||
|
||||
Reviewed-by: Hugo Landau <hlandau@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/20588)
|
||||
|
||||
CVE: CVE-2023-0465
|
||||
Upstream-Status: Backport [https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=b013765abfa80036dc779dd0e50602c57bb3bf95]
|
||||
Comment: Refreshed first hunk
|
||||
Signed-off-by: Omkar Patil <omkar.patil@kpit.com>
|
||||
|
||||
---
|
||||
crypto/x509/x509_vfy.c | 11 +++++++++--
|
||||
1 file changed, 9 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c
|
||||
index 925fbb5412..1dfe4f9f31 100644
|
||||
--- a/crypto/x509/x509_vfy.c
|
||||
+++ b/crypto/x509/x509_vfy.c
|
||||
@@ -1649,18 +1649,25 @@
|
||||
}
|
||||
/* Invalid or inconsistent extensions */
|
||||
if (ret == X509_PCY_TREE_INVALID) {
|
||||
- int i;
|
||||
+ int i, cbcalled = 0;
|
||||
|
||||
/* Locate certificates with bad extensions and notify callback. */
|
||||
- for (i = 1; i < sk_X509_num(ctx->chain); i++) {
|
||||
+ for (i = 0; i < sk_X509_num(ctx->chain); i++) {
|
||||
X509 *x = sk_X509_value(ctx->chain, i);
|
||||
|
||||
if (!(x->ex_flags & EXFLAG_INVALID_POLICY))
|
||||
continue;
|
||||
+ cbcalled = 1;
|
||||
if (!verify_cb_cert(ctx, x, i,
|
||||
X509_V_ERR_INVALID_POLICY_EXTENSION))
|
||||
return 0;
|
||||
}
|
||||
+ if (!cbcalled) {
|
||||
+ /* Should not be able to get here */
|
||||
+ X509err(X509_F_CHECK_POLICY, ERR_R_INTERNAL_ERROR);
|
||||
+ return 0;
|
||||
+ }
|
||||
+ /* The callback ignored the error so we return success */
|
||||
return 1;
|
||||
}
|
||||
if (ret == X509_PCY_TREE_FAILURE) {
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
From 0d16b7e99aafc0b4a6d729eec65a411a7e025f0a Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Mraz <tomas@openssl.org>
|
||||
Date: Tue, 21 Mar 2023 16:15:47 +0100
|
||||
Subject: [PATCH] Fix documentation of X509_VERIFY_PARAM_add0_policy()
|
||||
|
||||
The function was incorrectly documented as enabling policy checking.
|
||||
|
||||
Fixes: CVE-2023-0466
|
||||
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/20564)
|
||||
|
||||
CVE: CVE-2023-0466
|
||||
Upstream-Status: Backport [https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=0d16b7e99aafc0b4a6d729eec65a411a7e025f0a]
|
||||
Comment: Refreshed first hunk from CHANGE and NEWS
|
||||
Signed-off-by: Omkar Patil <omkar.patil@kpit.com>
|
||||
|
||||
---
|
||||
CHANGES | 5 +++++
|
||||
NEWS | 1 +
|
||||
doc/man3/X509_VERIFY_PARAM_set_flags.pod | 9 +++++++--
|
||||
3 files changed, 13 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/CHANGES b/CHANGES
|
||||
index efccf7838e..b19f1429bb 100644
|
||||
--- a/CHANGES
|
||||
+++ b/CHANGES
|
||||
@@ -9,6 +9,11 @@
|
||||
|
||||
Changes between 1.1.1s and 1.1.1t [7 Feb 2023]
|
||||
|
||||
+ *) Corrected documentation of X509_VERIFY_PARAM_add0_policy() to mention
|
||||
+ that it does not enable policy checking. Thanks to
|
||||
+ David Benjamin for discovering this issue. (CVE-2023-0466)
|
||||
+ [Tomas Mraz]
|
||||
+
|
||||
*) Fixed X.400 address type confusion in X.509 GeneralName.
|
||||
|
||||
There is a type confusion vulnerability relating to X.400 address processing
|
||||
diff --git a/NEWS b/NEWS
|
||||
index 36a9bb6890..62615693fa 100644
|
||||
--- a/NEWS
|
||||
+++ b/NEWS
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
Major changes between OpenSSL 1.1.1s and OpenSSL 1.1.1t [7 Feb 2023]
|
||||
|
||||
+ o Fixed documentation of X509_VERIFY_PARAM_add0_policy() (CVE-2023-0466)
|
||||
o Fixed X.400 address type confusion in X.509 GeneralName (CVE-2023-0286)
|
||||
o Fixed Use-after-free following BIO_new_NDEF (CVE-2023-0215)
|
||||
o Fixed Double free after calling PEM_read_bio_ex (CVE-2022-4450)
|
||||
diff --git a/doc/man3/X509_VERIFY_PARAM_set_flags.pod b/doc/man3/X509_VERIFY_PARAM_set_flags.pod
|
||||
index f6f304bf7b..aa292f9336 100644
|
||||
--- a/doc/man3/X509_VERIFY_PARAM_set_flags.pod
|
||||
+++ b/doc/man3/X509_VERIFY_PARAM_set_flags.pod
|
||||
@@ -92,8 +92,9 @@ B<trust>.
|
||||
X509_VERIFY_PARAM_set_time() sets the verification time in B<param> to
|
||||
B<t>. Normally the current time is used.
|
||||
|
||||
-X509_VERIFY_PARAM_add0_policy() enables policy checking (it is disabled
|
||||
-by default) and adds B<policy> to the acceptable policy set.
|
||||
+X509_VERIFY_PARAM_add0_policy() adds B<policy> to the acceptable policy set.
|
||||
+Contrary to preexisting documentation of this function it does not enable
|
||||
+policy checking.
|
||||
|
||||
X509_VERIFY_PARAM_set1_policies() enables policy checking (it is disabled
|
||||
by default) and sets the acceptable policy set to B<policies>. Any existing
|
||||
@@ -377,6 +378,10 @@ and has no effect.
|
||||
|
||||
The X509_VERIFY_PARAM_get_hostflags() function was added in OpenSSL 1.1.0i.
|
||||
|
||||
+The function X509_VERIFY_PARAM_add0_policy() was historically documented as
|
||||
+enabling policy checking however the implementation has never done this.
|
||||
+The documentation was changed to align with the implementation.
|
||||
+
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright 2009-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
From 9e209944b35cf82368071f160a744b6178f9b098 Mon Sep 17 00:00:00 2001
|
||||
From: Richard Levitte <levitte@openssl.org>
|
||||
Date: Fri, 12 May 2023 10:00:13 +0200
|
||||
Subject: [PATCH] Restrict the size of OBJECT IDENTIFIERs that OBJ_obj2txt will
|
||||
translate
|
||||
|
||||
OBJ_obj2txt() would translate any size OBJECT IDENTIFIER to canonical
|
||||
numeric text form. For gigantic sub-identifiers, this would take a very
|
||||
long time, the time complexity being O(n^2) where n is the size of that
|
||||
sub-identifier.
|
||||
|
||||
To mitigate this, a restriction on the size that OBJ_obj2txt() will
|
||||
translate to canonical numeric text form is added, based on RFC 2578
|
||||
(STD 58), which says this:
|
||||
|
||||
> 3.5. OBJECT IDENTIFIER values
|
||||
>
|
||||
> An OBJECT IDENTIFIER value is an ordered list of non-negative numbers.
|
||||
> For the SMIv2, each number in the list is referred to as a sub-identifier,
|
||||
> there are at most 128 sub-identifiers in a value, and each sub-identifier
|
||||
> has a maximum value of 2^32-1 (4294967295 decimal).
|
||||
|
||||
Fixes otc/security#96
|
||||
Fixes CVE-2023-2650
|
||||
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/openssl/openssl/commit/9e209944b35cf82368071f160a744b6178f9b098]
|
||||
CVE: CVE-2023-2650
|
||||
Signed-off-by: Hitendra Prajapati <hprajapati@mvista.com>
|
||||
---
|
||||
CHANGES | 28 +++++++++++++++++++++++++++-
|
||||
NEWS | 2 ++
|
||||
crypto/objects/obj_dat.c | 19 +++++++++++++++++++
|
||||
3 files changed, 48 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/CHANGES b/CHANGES
|
||||
index 1eaaf4e..f2cf38f 100644
|
||||
--- a/CHANGES
|
||||
+++ b/CHANGES
|
||||
@@ -7,7 +7,33 @@
|
||||
https://github.com/openssl/openssl/commits/ and pick the appropriate
|
||||
release branch.
|
||||
|
||||
- Changes between 1.1.1s and 1.1.1t [7 Feb 2023]
|
||||
+ Changes between 1.1.1t and 1.1.1u [xx XXX xxxx]
|
||||
+
|
||||
+ *) Mitigate for the time it takes for `OBJ_obj2txt` to translate gigantic
|
||||
+ OBJECT IDENTIFIER sub-identifiers to canonical numeric text form.
|
||||
+
|
||||
+ OBJ_obj2txt() would translate any size OBJECT IDENTIFIER to canonical
|
||||
+ numeric text form. For gigantic sub-identifiers, this would take a very
|
||||
+ long time, the time complexity being O(n^2) where n is the size of that
|
||||
+ sub-identifier. (CVE-2023-2650)
|
||||
+
|
||||
+ To mitigitate this, `OBJ_obj2txt()` will only translate an OBJECT
|
||||
+ IDENTIFIER to canonical numeric text form if the size of that OBJECT
|
||||
+ IDENTIFIER is 586 bytes or less, and fail otherwise.
|
||||
+
|
||||
+ The basis for this restriction is RFC 2578 (STD 58), section 3.5. OBJECT
|
||||
+ IDENTIFIER values, which stipulates that OBJECT IDENTIFIERS may have at
|
||||
+ most 128 sub-identifiers, and that the maximum value that each sub-
|
||||
+ identifier may have is 2^32-1 (4294967295 decimal).
|
||||
+
|
||||
+ For each byte of every sub-identifier, only the 7 lower bits are part of
|
||||
+ the value, so the maximum amount of bytes that an OBJECT IDENTIFIER with
|
||||
+ these restrictions may occupy is 32 * 128 / 7, which is approximately 586
|
||||
+ bytes.
|
||||
+
|
||||
+ Ref: https://datatracker.ietf.org/doc/html/rfc2578#section-3.5
|
||||
+
|
||||
+Changes between 1.1.1s and 1.1.1t [7 Feb 2023]
|
||||
|
||||
*) Corrected documentation of X509_VERIFY_PARAM_add0_policy() to mention
|
||||
that it does not enable policy checking. Thanks to
|
||||
diff --git a/NEWS b/NEWS
|
||||
index a86220a..41922c4 100644
|
||||
--- a/NEWS
|
||||
+++ b/NEWS
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
Major changes between OpenSSL 1.1.1s and OpenSSL 1.1.1t [7 Feb 2023]
|
||||
|
||||
+ o Mitigate for very slow `OBJ_obj2txt()` performance with gigantic
|
||||
+ OBJECT IDENTIFIER sub-identities. (CVE-2023-2650)
|
||||
o Fixed documentation of X509_VERIFY_PARAM_add0_policy() (CVE-2023-0466)
|
||||
o Fixed X.400 address type confusion in X.509 GeneralName (CVE-2023-0286)
|
||||
o Fixed Use-after-free following BIO_new_NDEF (CVE-2023-0215)
|
||||
diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c
|
||||
index 7e8de72..d699915 100644
|
||||
--- a/crypto/objects/obj_dat.c
|
||||
+++ b/crypto/objects/obj_dat.c
|
||||
@@ -428,6 +428,25 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
|
||||
first = 1;
|
||||
bl = NULL;
|
||||
|
||||
+ /*
|
||||
+ * RFC 2578 (STD 58) says this about OBJECT IDENTIFIERs:
|
||||
+ *
|
||||
+ * > 3.5. OBJECT IDENTIFIER values
|
||||
+ * >
|
||||
+ * > An OBJECT IDENTIFIER value is an ordered list of non-negative
|
||||
+ * > numbers. For the SMIv2, each number in the list is referred to as a
|
||||
+ * > sub-identifier, there are at most 128 sub-identifiers in a value,
|
||||
+ * > and each sub-identifier has a maximum value of 2^32-1 (4294967295
|
||||
+ * > decimal).
|
||||
+ *
|
||||
+ * So a legitimate OID according to this RFC is at most (32 * 128 / 7),
|
||||
+ * i.e. 586 bytes long.
|
||||
+ *
|
||||
+ * Ref: https://datatracker.ietf.org/doc/html/rfc2578#section-3.5
|
||||
+ */
|
||||
+ if (len > 586)
|
||||
+ goto err;
|
||||
+
|
||||
while (len > 0) {
|
||||
l = 0;
|
||||
use_bn = 0;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@@ -19,17 +19,14 @@ SRC_URI = "http://www.openssl.org/source/openssl-${PV}.tar.gz \
|
||||
file://reproducible.patch \
|
||||
file://reproducibility.patch \
|
||||
file://0001-Configure-add-2-missing-key-sorts.patch \
|
||||
file://CVE-2023-0464.patch \
|
||||
file://CVE-2023-0465.patch \
|
||||
file://CVE-2023-0466.patch \
|
||||
file://CVE-2023-2650.patch \
|
||||
file://0001-Configure-do-not-tweak-mips-cflags.patch \
|
||||
"
|
||||
|
||||
SRC_URI_append_class-nativesdk = " \
|
||||
file://environment.d-openssl.sh \
|
||||
"
|
||||
|
||||
SRC_URI[sha256sum] = "8dee9b24bdb1dcbf0c3d1e9b02fb8f6bf22165e807f45adeb7c9677536859d3b"
|
||||
SRC_URI[sha256sum] = "cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8"
|
||||
|
||||
inherit lib_package multilib_header multilib_script ptest
|
||||
MULTILIB_SCRIPTS = "${PN}-bin:${bindir}/c_rehash"
|
||||
82
meta/recipes-core/busybox/busybox/CVE-2022-48174.patch
Normal file
82
meta/recipes-core/busybox/busybox/CVE-2022-48174.patch
Normal file
@@ -0,0 +1,82 @@
|
||||
From c18ebf861528ef24958dd99a146482d2a40014c7 Mon Sep 17 00:00:00 2001
|
||||
From: Denys Vlasenko <vda.linux@googlemail.com>
|
||||
Date: Mon, 12 Jun 2023 17:48:47 +0200
|
||||
Subject: [PATCH] shell: avoid segfault on ${0::0/0~09J}. Closes 15216
|
||||
|
||||
function old new delta
|
||||
evaluate_string 1011 1053 +42
|
||||
|
||||
CVE: CVE-2022-48174
|
||||
Upstream-Status: Backport [d417193cf37ca1005830d7e16f5fa7e1d8a44209]
|
||||
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
|
||||
---
|
||||
shell/math.c | 39 +++++++++++++++++++++++++++++++++++----
|
||||
1 file changed, 35 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/shell/math.c b/shell/math.c
|
||||
index af1ab55c0..79824e81f 100644
|
||||
--- a/shell/math.c
|
||||
+++ b/shell/math.c
|
||||
@@ -578,6 +578,28 @@ static arith_t strto_arith_t(const char *nptr, char **endptr)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
+//TODO: much better estimation than expr_len/2? Such as:
|
||||
+//static unsigned estimate_nums_and_names(const char *expr)
|
||||
+//{
|
||||
+// unsigned count = 0;
|
||||
+// while (*(expr = skip_whitespace(expr)) != '\0') {
|
||||
+// const char *p;
|
||||
+// if (isdigit(*expr)) {
|
||||
+// while (isdigit(*++expr))
|
||||
+// continue;
|
||||
+// count++;
|
||||
+// continue;
|
||||
+// }
|
||||
+// p = endofname(expr);
|
||||
+// if (p != expr) {
|
||||
+// expr = p;
|
||||
+// count++;
|
||||
+// continue;
|
||||
+// }
|
||||
+// }
|
||||
+// return count;
|
||||
+//}
|
||||
+
|
||||
static arith_t FAST_FUNC
|
||||
evaluate_string(arith_state_t *math_state, const char *expr)
|
||||
{
|
||||
@@ -585,10 +607,12 @@ evaluate_string(arith_state_t *math_state, const char *expr)
|
||||
const char *errmsg;
|
||||
const char *start_expr = expr = skip_whitespace(expr);
|
||||
unsigned expr_len = strlen(expr) + 2;
|
||||
- /* Stack of integers */
|
||||
- /* The proof that there can be no more than strlen(startbuf)/2+1
|
||||
- * integers in any given correct or incorrect expression
|
||||
- * is left as an exercise to the reader. */
|
||||
+ /* Stack of integers/names */
|
||||
+ /* There can be no more than strlen(startbuf)/2+1
|
||||
+ * integers/names in any given correct or incorrect expression.
|
||||
+ * (modulo "09v09v09v09v09v" case,
|
||||
+ * but we have code to detect that early)
|
||||
+ */
|
||||
var_or_num_t *const numstack = alloca((expr_len / 2) * sizeof(numstack[0]));
|
||||
var_or_num_t *numstackptr = numstack;
|
||||
/* Stack of operator tokens */
|
||||
@@ -657,6 +681,13 @@ evaluate_string(arith_state_t *math_state, const char *expr)
|
||||
numstackptr->var = NULL;
|
||||
errno = 0;
|
||||
numstackptr->val = strto_arith_t(expr, (char**) &expr);
|
||||
+ /* A number can't be followed by another number, or a variable name.
|
||||
+ * We'd catch this later anyway, but this would require numstack[]
|
||||
+ * to be twice as deep to handle strings where _every_ char is
|
||||
+ * a new number or name. Example: 09v09v09v09v09v09v09v09v09v
|
||||
+ */
|
||||
+ if (isalnum(*expr) || *expr == '_')
|
||||
+ goto err;
|
||||
if (errno)
|
||||
numstackptr->val = 0; /* bash compat */
|
||||
goto num;
|
||||
--
|
||||
2.40.1
|
||||
|
||||
@@ -55,6 +55,7 @@ SRC_URI = "https://busybox.net/downloads/busybox-${PV}.tar.bz2;name=tarball \
|
||||
file://CVE-2021-42374.patch \
|
||||
file://CVE-2021-42376.patch \
|
||||
file://CVE-2021-423xx-awk.patch \
|
||||
file://CVE-2022-48174.patch \
|
||||
file://0001-libbb-sockaddr2str-ensure-only-printable-characters-.patch \
|
||||
file://0002-nslookup-sanitize-all-printed-strings-with-printable.patch \
|
||||
"
|
||||
|
||||
@@ -8,6 +8,7 @@ SRC_URI = "https://dbus.freedesktop.org/releases/dbus/dbus-${PV}.tar.gz \
|
||||
file://tmpdir.patch \
|
||||
file://dbus-1.init \
|
||||
file://clear-guid_from_server-if-send_negotiate_unix_f.patch \
|
||||
file://CVE-2023-34969.patch \
|
||||
"
|
||||
|
||||
SRC_URI[sha256sum] = "bc42d196c1756ac520d61bf3ccd6f42013617def45dd1e591a6091abf51dca38"
|
||||
@@ -31,3 +32,5 @@ PACKAGECONFIG[systemd] = "--enable-systemd --with-systemdsystemunitdir=${systemd
|
||||
PACKAGECONFIG[x11] = "--with-x --enable-x11-autolaunch,--without-x --disable-x11-autolaunch, virtual/libx11 libsm"
|
||||
PACKAGECONFIG[user-session] = "--enable-user-session --with-systemduserunitdir=${systemd_user_unitdir},--disable-user-session"
|
||||
PACKAGECONFIG[verbose-mode] = "--enable-verbose-mode,,,"
|
||||
|
||||
CVE_PRODUCT += "d-bus_project:d-bus freedesktop:dbus freedesktop:libdbus"
|
||||
|
||||
96
meta/recipes-core/dbus/dbus/CVE-2023-34969.patch
Normal file
96
meta/recipes-core/dbus/dbus/CVE-2023-34969.patch
Normal file
@@ -0,0 +1,96 @@
|
||||
From 37a4dc5835731a1f7a81f1b67c45b8dfb556dd1c Mon Sep 17 00:00:00 2001
|
||||
From: hongjinghao <q1204531485@163.com>
|
||||
Date: Mon, 5 Jun 2023 18:17:06 +0100
|
||||
Subject: [PATCH] bus: Assign a serial number for messages from the driver
|
||||
|
||||
Normally, it's enough to rely on a message being given a serial number
|
||||
by the DBusConnection just before it is actually sent. However, in the
|
||||
rare case where the policy blocks the driver from sending a message
|
||||
(due to a deny rule or the outgoing message quota being full), we need
|
||||
to get a valid serial number sooner, so that we can copy it into the
|
||||
DBUS_HEADER_FIELD_REPLY_SERIAL field (which is mandatory) in the error
|
||||
message sent to monitors. Otherwise, the dbus-daemon will crash with
|
||||
an assertion failure if at least one Monitoring client is attached,
|
||||
because zero is not a valid serial number to copy.
|
||||
|
||||
This fixes a denial-of-service vulnerability: if a privileged user is
|
||||
monitoring the well-known system bus using a Monitoring client like
|
||||
dbus-monitor or `busctl monitor`, then an unprivileged user can cause
|
||||
denial-of-service by triggering this crash. A mitigation for this
|
||||
vulnerability is to avoid attaching Monitoring clients to the system
|
||||
bus when they are not needed. If there are no Monitoring clients, then
|
||||
the vulnerable code is not reached.
|
||||
|
||||
Co-authored-by: Simon McVittie <smcv@collabora.com>
|
||||
Resolves: dbus/dbus#457
|
||||
(cherry picked from commit b159849e031000d1dbc1ab876b5fc78a3ce9b534)
|
||||
---
|
||||
bus/connection.c | 15 +++++++++++++++
|
||||
dbus/dbus-connection-internal.h | 2 ++
|
||||
dbus/dbus-connection.c | 11 ++++++++++-
|
||||
3 files changed, 27 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/bus/connection.c b/bus/connection.c
|
||||
index b3583433..215f0230 100644
|
||||
--- a/bus/connection.c
|
||||
+++ b/bus/connection.c
|
||||
@@ -2350,6 +2350,21 @@ bus_transaction_send_from_driver (BusTransaction *transaction,
|
||||
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
|
||||
return FALSE;
|
||||
|
||||
+ /* Make sure the message has a non-zero serial number, otherwise
|
||||
+ * bus_transaction_capture_error_reply() will not be able to mock up
|
||||
+ * a corresponding reply for it. Normally this would be delayed until
|
||||
+ * the first time we actually send the message out from a
|
||||
+ * connection, when the transaction is committed, but that's too late
|
||||
+ * in this case.
|
||||
+ */
|
||||
+ if (dbus_message_get_serial (message) == 0)
|
||||
+ {
|
||||
+ dbus_uint32_t next_serial;
|
||||
+
|
||||
+ next_serial = _dbus_connection_get_next_client_serial (connection);
|
||||
+ dbus_message_set_serial (message, next_serial);
|
||||
+ }
|
||||
+
|
||||
if (bus_connection_is_active (connection))
|
||||
{
|
||||
if (!dbus_message_set_destination (message,
|
||||
diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h
|
||||
index 48357321..ba79b192 100644
|
||||
--- a/dbus/dbus-connection-internal.h
|
||||
+++ b/dbus/dbus-connection-internal.h
|
||||
@@ -54,6 +54,8 @@ DBUS_PRIVATE_EXPORT
|
||||
DBusConnection * _dbus_connection_ref_unlocked (DBusConnection *connection);
|
||||
DBUS_PRIVATE_EXPORT
|
||||
void _dbus_connection_unref_unlocked (DBusConnection *connection);
|
||||
+DBUS_PRIVATE_EXPORT
|
||||
+dbus_uint32_t _dbus_connection_get_next_client_serial (DBusConnection *connection);
|
||||
void _dbus_connection_queue_received_message_link (DBusConnection *connection,
|
||||
DBusList *link);
|
||||
dbus_bool_t _dbus_connection_has_messages_to_send_unlocked (DBusConnection *connection);
|
||||
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
|
||||
index c525b6dc..09cef278 100644
|
||||
--- a/dbus/dbus-connection.c
|
||||
+++ b/dbus/dbus-connection.c
|
||||
@@ -1456,7 +1456,16 @@ _dbus_connection_unref_unlocked (DBusConnection *connection)
|
||||
_dbus_connection_last_unref (connection);
|
||||
}
|
||||
|
||||
-static dbus_uint32_t
|
||||
+/**
|
||||
+ * Allocate and return the next non-zero serial number for outgoing messages.
|
||||
+ *
|
||||
+ * This method is only valid to call from single-threaded code, such as
|
||||
+ * the dbus-daemon, or with the connection lock held.
|
||||
+ *
|
||||
+ * @param connection the connection
|
||||
+ * @returns A suitable serial number for the next message to be sent on the connection.
|
||||
+ */
|
||||
+dbus_uint32_t
|
||||
_dbus_connection_get_next_client_serial (DBusConnection *connection)
|
||||
{
|
||||
dbus_uint32_t serial;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
290
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-29499.patch
Normal file
290
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-29499.patch
Normal file
@@ -0,0 +1,290 @@
|
||||
From 5f4485c4ff57fdefb1661531788def7ca5a47328 Mon Sep 17 00:00:00 2001
|
||||
From: Philip Withnall <pwithnall@endlessos.org>
|
||||
Date: Thu, 17 Aug 2023 04:19:44 +0000
|
||||
Subject: [PATCH] gvariant-serialiser: Check offset table entry size is minimal
|
||||
|
||||
The entries in an offset table (which is used for variable sized arrays
|
||||
and tuples containing variable sized members) are sized so that they can
|
||||
address every byte in the overall variant.
|
||||
|
||||
The specification requires that for a variant to be in normal form, its
|
||||
offset table entries must be the minimum width such that they can
|
||||
address every byte in the variant.
|
||||
|
||||
That minimality requirement was not checked in
|
||||
`g_variant_is_normal_form()`, leading to two different byte arrays being
|
||||
interpreted as the normal form of a given variant tree. That kind of
|
||||
confusion could potentially be exploited, and is certainly a bug.
|
||||
|
||||
Fix it by adding the necessary checks on offset table entry width, and
|
||||
unit tests.
|
||||
|
||||
Spotted by William Manley.
|
||||
|
||||
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
||||
|
||||
Fixes: #2794
|
||||
|
||||
CVE: CVE-2023-29499
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/5f4485c4ff57fdefb1661531788def7ca5a47328]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-serialiser.c | 19 +++-
|
||||
glib/tests/gvariant.c | 176 +++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 194 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
|
||||
index 0bf7243..5aa2cbc 100644
|
||||
--- a/glib/gvariant-serialiser.c
|
||||
+++ b/glib/gvariant-serialiser.c
|
||||
@@ -694,6 +694,10 @@ gvs_variable_sized_array_get_frame_offsets (GVariantSerialised value)
|
||||
out.data_size = last_end;
|
||||
out.array = value.data + last_end;
|
||||
out.length = offsets_array_size / out.offset_size;
|
||||
+
|
||||
+ if (out.length > 0 && gvs_calculate_total_size (last_end, out.length) != value.size)
|
||||
+ return out; /* offset size not minimal */
|
||||
+
|
||||
out.is_normal = TRUE;
|
||||
|
||||
return out;
|
||||
@@ -1201,6 +1205,7 @@ gvs_tuple_is_normal (GVariantSerialised value)
|
||||
gsize length;
|
||||
gsize offset;
|
||||
gsize i;
|
||||
+ gsize offset_table_size;
|
||||
|
||||
/* as per the comment in gvs_tuple_get_child() */
|
||||
if G_UNLIKELY (value.data == NULL && value.size != 0)
|
||||
@@ -1305,7 +1310,19 @@ gvs_tuple_is_normal (GVariantSerialised value)
|
||||
}
|
||||
}
|
||||
|
||||
- return offset_ptr == offset;
|
||||
+ /* @offset_ptr has been counting backwards from the end of the variant, to
|
||||
+ * find the beginning of the offset table. @offset has been counting forwards
|
||||
+ * from the beginning of the variant to find the end of the data. They should
|
||||
+ * have met in the middle. */
|
||||
+ if (offset_ptr != offset)
|
||||
+ return FALSE;
|
||||
+
|
||||
+ offset_table_size = value.size - offset_ptr;
|
||||
+ if (value.size > 0 &&
|
||||
+ gvs_calculate_total_size (offset, offset_table_size / offset_size) != value.size)
|
||||
+ return FALSE; /* offset size not minimal */
|
||||
+
|
||||
+ return TRUE;
|
||||
}
|
||||
|
||||
/* Variants {{{2
|
||||
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
|
||||
index d640c81..4ce0e4f 100644
|
||||
--- a/glib/tests/gvariant.c
|
||||
+++ b/glib/tests/gvariant.c
|
||||
@@ -5092,6 +5092,86 @@ test_normal_checking_array_offsets2 (void)
|
||||
g_variant_unref (variant);
|
||||
}
|
||||
|
||||
+/* Test that an otherwise-valid serialised GVariant is considered non-normal if
|
||||
+ * its offset table entries are too wide.
|
||||
+ *
|
||||
+ * See §2.3.6 (Framing Offsets) of the GVariant specification. */
|
||||
+static void
|
||||
+test_normal_checking_array_offsets_minimal_sized (void)
|
||||
+{
|
||||
+ GVariantBuilder builder;
|
||||
+ gsize i;
|
||||
+ GVariant *aay_constructed = NULL;
|
||||
+ const guint8 *data = NULL;
|
||||
+ guint8 *data_owned = NULL;
|
||||
+ GVariant *aay_deserialised = NULL;
|
||||
+ GVariant *aay_normalised = NULL;
|
||||
+
|
||||
+ /* Construct an array of type aay, consisting of 128 elements which are each
|
||||
+ * an empty array, i.e. `[[] * 128]`. This is chosen because the inner
|
||||
+ * elements are variable sized (making the outer array variable sized, so it
|
||||
+ * must have an offset table), but they are also zero-sized when serialised.
|
||||
+ * So the serialised representation of @aay_constructed consists entirely of
|
||||
+ * its offset table, which is entirely zeroes.
|
||||
+ *
|
||||
+ * The array is chosen to be 128 elements long because that means offset
|
||||
+ * table entries which are 1 byte long. If the elements in the array were
|
||||
+ * non-zero-sized (to the extent that the overall array is ≥256 bytes long),
|
||||
+ * the offset table entries would end up being 2 bytes long. */
|
||||
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
|
||||
+
|
||||
+ for (i = 0; i < 128; i++)
|
||||
+ g_variant_builder_add_value (&builder, g_variant_new_array (G_VARIANT_TYPE_BYTE, NULL, 0));
|
||||
+
|
||||
+ aay_constructed = g_variant_builder_end (&builder);
|
||||
+
|
||||
+ /* Verify that the constructed array is in normal form, and its serialised
|
||||
+ * form is `b'\0' * 128`. */
|
||||
+ g_assert_true (g_variant_is_normal_form (aay_constructed));
|
||||
+ g_assert_cmpuint (g_variant_n_children (aay_constructed), ==, 128);
|
||||
+ g_assert_cmpuint (g_variant_get_size (aay_constructed), ==, 128);
|
||||
+
|
||||
+ data = g_variant_get_data (aay_constructed);
|
||||
+ for (i = 0; i < g_variant_get_size (aay_constructed); i++)
|
||||
+ g_assert_cmpuint (data[i], ==, 0);
|
||||
+
|
||||
+ /* Construct a serialised `aay` GVariant which is `b'\0' * 256`. This has to
|
||||
+ * be a non-normal form of `[[] * 128]`, with 2-byte-long offset table
|
||||
+ * entries, because each offset table entry has to be able to reference all of
|
||||
+ * the byte boundaries in the container. All the entries in the offset table
|
||||
+ * are zero, so all the elements of the array are zero-sized. */
|
||||
+ data = data_owned = g_malloc0 (256);
|
||||
+ aay_deserialised = g_variant_new_from_data (G_VARIANT_TYPE ("aay"),
|
||||
+ data,
|
||||
+ 256,
|
||||
+ FALSE,
|
||||
+ g_free,
|
||||
+ g_steal_pointer (&data_owned));
|
||||
+
|
||||
+ g_assert_false (g_variant_is_normal_form (aay_deserialised));
|
||||
+ g_assert_cmpuint (g_variant_n_children (aay_deserialised), ==, 128);
|
||||
+ g_assert_cmpuint (g_variant_get_size (aay_deserialised), ==, 256);
|
||||
+
|
||||
+ data = g_variant_get_data (aay_deserialised);
|
||||
+ for (i = 0; i < g_variant_get_size (aay_deserialised); i++)
|
||||
+ g_assert_cmpuint (data[i], ==, 0);
|
||||
+
|
||||
+ /* Get its normal form. That should change the serialised size. */
|
||||
+ aay_normalised = g_variant_get_normal_form (aay_deserialised);
|
||||
+
|
||||
+ g_assert_true (g_variant_is_normal_form (aay_normalised));
|
||||
+ g_assert_cmpuint (g_variant_n_children (aay_normalised), ==, 128);
|
||||
+ g_assert_cmpuint (g_variant_get_size (aay_normalised), ==, 128);
|
||||
+
|
||||
+ data = g_variant_get_data (aay_normalised);
|
||||
+ for (i = 0; i < g_variant_get_size (aay_normalised); i++)
|
||||
+ g_assert_cmpuint (data[i], ==, 0);
|
||||
+
|
||||
+ g_variant_unref (aay_normalised);
|
||||
+ g_variant_unref (aay_deserialised);
|
||||
+ g_variant_unref (aay_constructed);
|
||||
+}
|
||||
+
|
||||
/* Test that a tuple with invalidly large values in its offset table is
|
||||
* normalised successfully without looping infinitely. */
|
||||
static void
|
||||
@@ -5286,6 +5366,98 @@ test_normal_checking_tuple_offsets4 (void)
|
||||
g_variant_unref (variant);
|
||||
}
|
||||
|
||||
+/* Test that an otherwise-valid serialised GVariant is considered non-normal if
|
||||
+ * its offset table entries are too wide.
|
||||
+ *
|
||||
+ * See §2.3.6 (Framing Offsets) of the GVariant specification. */
|
||||
+static void
|
||||
+test_normal_checking_tuple_offsets_minimal_sized (void)
|
||||
+{
|
||||
+ GString *type_string = NULL;
|
||||
+ GVariantBuilder builder;
|
||||
+ gsize i;
|
||||
+ GVariant *ray_constructed = NULL;
|
||||
+ const guint8 *data = NULL;
|
||||
+ guint8 *data_owned = NULL;
|
||||
+ GVariant *ray_deserialised = NULL;
|
||||
+ GVariant *ray_normalised = NULL;
|
||||
+
|
||||
+ /* Construct a tuple of type (ay…ay), consisting of 129 members which are each
|
||||
+ * an empty array, i.e. `([] * 129)`. This is chosen because the inner
|
||||
+ * members are variable sized, so the outer tuple must have an offset table,
|
||||
+ * but they are also zero-sized when serialised. So the serialised
|
||||
+ * representation of @ray_constructed consists entirely of its offset table,
|
||||
+ * which is entirely zeroes.
|
||||
+ *
|
||||
+ * The tuple is chosen to be 129 members long because that means it has 128
|
||||
+ * offset table entries which are 1 byte long each. If the members in the
|
||||
+ * tuple were non-zero-sized (to the extent that the overall tuple is ≥256
|
||||
+ * bytes long), the offset table entries would end up being 2 bytes long.
|
||||
+ *
|
||||
+ * 129 members are used unlike 128 array elements in
|
||||
+ * test_normal_checking_array_offsets_minimal_sized(), because the last member
|
||||
+ * in a tuple never needs an offset table entry. */
|
||||
+ type_string = g_string_new ("");
|
||||
+ g_string_append_c (type_string, '(');
|
||||
+ for (i = 0; i < 129; i++)
|
||||
+ g_string_append (type_string, "ay");
|
||||
+ g_string_append_c (type_string, ')');
|
||||
+
|
||||
+ g_variant_builder_init (&builder, G_VARIANT_TYPE (type_string->str));
|
||||
+
|
||||
+ for (i = 0; i < 129; i++)
|
||||
+ g_variant_builder_add_value (&builder, g_variant_new_array (G_VARIANT_TYPE_BYTE, NULL, 0));
|
||||
+
|
||||
+ ray_constructed = g_variant_builder_end (&builder);
|
||||
+
|
||||
+ /* Verify that the constructed tuple is in normal form, and its serialised
|
||||
+ * form is `b'\0' * 128`. */
|
||||
+ g_assert_true (g_variant_is_normal_form (ray_constructed));
|
||||
+ g_assert_cmpuint (g_variant_n_children (ray_constructed), ==, 129);
|
||||
+ g_assert_cmpuint (g_variant_get_size (ray_constructed), ==, 128);
|
||||
+
|
||||
+ data = g_variant_get_data (ray_constructed);
|
||||
+ for (i = 0; i < g_variant_get_size (ray_constructed); i++)
|
||||
+ g_assert_cmpuint (data[i], ==, 0);
|
||||
+
|
||||
+ /* Construct a serialised `(ay…ay)` GVariant which is `b'\0' * 256`. This has
|
||||
+ * to be a non-normal form of `([] * 129)`, with 2-byte-long offset table
|
||||
+ * entries, because each offset table entry has to be able to reference all of
|
||||
+ * the byte boundaries in the container. All the entries in the offset table
|
||||
+ * are zero, so all the members of the tuple are zero-sized. */
|
||||
+ data = data_owned = g_malloc0 (256);
|
||||
+ ray_deserialised = g_variant_new_from_data (G_VARIANT_TYPE (type_string->str),
|
||||
+ data,
|
||||
+ 256,
|
||||
+ FALSE,
|
||||
+ g_free,
|
||||
+ g_steal_pointer (&data_owned));
|
||||
+
|
||||
+ g_assert_false (g_variant_is_normal_form (ray_deserialised));
|
||||
+ g_assert_cmpuint (g_variant_n_children (ray_deserialised), ==, 129);
|
||||
+ g_assert_cmpuint (g_variant_get_size (ray_deserialised), ==, 256);
|
||||
+
|
||||
+ data = g_variant_get_data (ray_deserialised);
|
||||
+ for (i = 0; i < g_variant_get_size (ray_deserialised); i++)
|
||||
+ g_assert_cmpuint (data[i], ==, 0);
|
||||
+
|
||||
+ /* Get its normal form. That should change the serialised size. */
|
||||
+ ray_normalised = g_variant_get_normal_form (ray_deserialised);
|
||||
+
|
||||
+ g_assert_true (g_variant_is_normal_form (ray_normalised));
|
||||
+ g_assert_cmpuint (g_variant_n_children (ray_normalised), ==, 129);
|
||||
+ g_assert_cmpuint (g_variant_get_size (ray_normalised), ==, 128);
|
||||
+
|
||||
+ data = g_variant_get_data (ray_normalised);
|
||||
+ for (i = 0; i < g_variant_get_size (ray_normalised); i++)
|
||||
+ g_assert_cmpuint (data[i], ==, 0);
|
||||
+
|
||||
+ g_variant_unref (ray_normalised);
|
||||
+ g_variant_unref (ray_deserialised);
|
||||
+ g_variant_unref (ray_constructed);
|
||||
+ g_string_free (type_string, TRUE);
|
||||
+}
|
||||
+
|
||||
/* Test that an empty object path is normalised successfully to the base object
|
||||
* path, ‘/’. */
|
||||
static void
|
||||
@@ -5431,6 +5603,8 @@ main (int argc, char **argv)
|
||||
test_normal_checking_array_offsets);
|
||||
g_test_add_func ("/gvariant/normal-checking/array-offsets2",
|
||||
test_normal_checking_array_offsets2);
|
||||
+ g_test_add_func ("/gvariant/normal-checking/array-offsets/minimal-sized",
|
||||
+ test_normal_checking_array_offsets_minimal_sized);
|
||||
g_test_add_func ("/gvariant/normal-checking/tuple-offsets",
|
||||
test_normal_checking_tuple_offsets);
|
||||
g_test_add_func ("/gvariant/normal-checking/tuple-offsets2",
|
||||
@@ -5439,6 +5613,8 @@ main (int argc, char **argv)
|
||||
test_normal_checking_tuple_offsets3);
|
||||
g_test_add_func ("/gvariant/normal-checking/tuple-offsets4",
|
||||
test_normal_checking_tuple_offsets4);
|
||||
+ g_test_add_func ("/gvariant/normal-checking/tuple-offsets/minimal-sized",
|
||||
+ test_normal_checking_tuple_offsets_minimal_sized);
|
||||
g_test_add_func ("/gvariant/normal-checking/empty-object-path",
|
||||
test_normal_checking_empty_object_path);
|
||||
|
||||
--
|
||||
2.24.4
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
From 1deacdd4e8e35a5cf1417918ca4f6b0afa6409b1 Mon Sep 17 00:00:00 2001
|
||||
From: William Manley <will@stb-tester.com>
|
||||
Date: Wed, 9 Aug 2023 10:04:49 +0000
|
||||
Subject: [PATCH] gvariant-core: Consolidate construction of
|
||||
`GVariantSerialised`
|
||||
|
||||
So I only need to change it in one place.
|
||||
|
||||
This introduces no functional changes.
|
||||
|
||||
Helps: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/1deacdd4e8e35a5cf1417918ca4f6b0afa6409b1]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant.c | 8 +++++---
|
||||
glib/tests/gvariant.c | 24 ++++++++++++++++++++++++
|
||||
2 files changed, 29 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant.c b/glib/gvariant.c
|
||||
index 8ba701e..4dbd9e8 100644
|
||||
--- a/glib/gvariant.c
|
||||
+++ b/glib/gvariant.c
|
||||
@@ -5952,14 +5952,16 @@ g_variant_byteswap (GVariant *value)
|
||||
g_variant_serialised_byteswap (serialised);
|
||||
|
||||
bytes = g_bytes_new_take (serialised.data, serialised.size);
|
||||
- new = g_variant_new_from_bytes (g_variant_get_type (value), bytes, TRUE);
|
||||
+ new = g_variant_ref_sink (g_variant_new_from_bytes (g_variant_get_type (value), bytes, TRUE));
|
||||
g_bytes_unref (bytes);
|
||||
}
|
||||
else
|
||||
/* contains no multi-byte data */
|
||||
- new = value;
|
||||
+ new = g_variant_get_normal_form (value);
|
||||
|
||||
- return g_variant_ref_sink (new);
|
||||
+ g_assert (g_variant_is_trusted (new));
|
||||
+
|
||||
+ return g_steal_pointer (&new);
|
||||
}
|
||||
|
||||
/**
|
||||
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
|
||||
index 4ce0e4f..3dda08e 100644
|
||||
--- a/glib/tests/gvariant.c
|
||||
+++ b/glib/tests/gvariant.c
|
||||
@@ -3834,6 +3834,29 @@ test_gv_byteswap (void)
|
||||
g_free (string);
|
||||
}
|
||||
|
||||
+static void
|
||||
+test_gv_byteswap_non_normal_non_aligned (void)
|
||||
+{
|
||||
+ const guint8 data[] = { 0x02 };
|
||||
+ GVariant *v = NULL;
|
||||
+ GVariant *v_byteswapped = NULL;
|
||||
+
|
||||
+ g_test_summary ("Test that calling g_variant_byteswap() on a variant which "
|
||||
+ "is in non-normal form and doesn’t need byteswapping returns "
|
||||
+ "the same variant in normal form.");
|
||||
+
|
||||
+ v = g_variant_new_from_data (G_VARIANT_TYPE_BOOLEAN, data, sizeof (data), FALSE, NULL, NULL);
|
||||
+ g_assert_false (g_variant_is_normal_form (v));
|
||||
+
|
||||
+ v_byteswapped = g_variant_byteswap (v);
|
||||
+ g_assert_true (g_variant_is_normal_form (v_byteswapped));
|
||||
+
|
||||
+ g_assert_cmpvariant (v, v_byteswapped);
|
||||
+
|
||||
+ g_variant_unref (v);
|
||||
+ g_variant_unref (v_byteswapped);
|
||||
+}
|
||||
+
|
||||
static void
|
||||
test_parser (void)
|
||||
{
|
||||
@@ -5570,6 +5593,7 @@ main (int argc, char **argv)
|
||||
g_test_add_func ("/gvariant/builder-memory", test_builder_memory);
|
||||
g_test_add_func ("/gvariant/hashing", test_hashing);
|
||||
g_test_add_func ("/gvariant/byteswap", test_gv_byteswap);
|
||||
+ g_test_add_func ("/gvariant/byteswap/non-normal-non-aligned", test_gv_byteswap_non_normal_non_aligned);
|
||||
g_test_add_func ("/gvariant/parser", test_parses);
|
||||
g_test_add_func ("/gvariant/parser/integer-bounds", test_parser_integer_bounds);
|
||||
g_test_add_func ("/gvariant/parser/recursion", test_parser_recursion);
|
||||
--
|
||||
2.24.4
|
||||
|
||||
255
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32611-0002.patch
Normal file
255
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32611-0002.patch
Normal file
@@ -0,0 +1,255 @@
|
||||
From 446e69f5edd72deb2196dee36bbaf8056caf6948 Mon Sep 17 00:00:00 2001
|
||||
From: William Manley <will@stb-tester.com>
|
||||
Date: Wed, 9 Aug 2023 10:39:34 +0000
|
||||
Subject: [PATCH] gvariant-serialiser: Factor out functions for dealing with
|
||||
framing offsets
|
||||
|
||||
This introduces no functional changes.
|
||||
|
||||
Helps: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/446e69f5edd72deb2196dee36bbaf8056caf6948]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant.c | 81 +++++++++++++++++++++++++++++++++----------
|
||||
glib/tests/gvariant.c | 57 ++++++++++++++++++++++++++----
|
||||
2 files changed, 112 insertions(+), 26 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant.c b/glib/gvariant.c
|
||||
index 4dbd9e8..a80c2c9 100644
|
||||
--- a/glib/gvariant.c
|
||||
+++ b/glib/gvariant.c
|
||||
@@ -5788,7 +5788,8 @@ g_variant_iter_loop (GVariantIter *iter,
|
||||
|
||||
/* Serialised data {{{1 */
|
||||
static GVariant *
|
||||
-g_variant_deep_copy (GVariant *value)
|
||||
+g_variant_deep_copy (GVariant *value,
|
||||
+ gboolean byteswap)
|
||||
{
|
||||
switch (g_variant_classify (value))
|
||||
{
|
||||
@@ -5806,7 +5807,7 @@ g_variant_deep_copy (GVariant *value)
|
||||
for (i = 0, n_children = g_variant_n_children (value); i < n_children; i++)
|
||||
{
|
||||
GVariant *child = g_variant_get_child_value (value, i);
|
||||
- g_variant_builder_add_value (&builder, g_variant_deep_copy (child));
|
||||
+ g_variant_builder_add_value (&builder, g_variant_deep_copy (child, byteswap));
|
||||
g_variant_unref (child);
|
||||
}
|
||||
|
||||
@@ -5820,28 +5821,63 @@ g_variant_deep_copy (GVariant *value)
|
||||
return g_variant_new_byte (g_variant_get_byte (value));
|
||||
|
||||
case G_VARIANT_CLASS_INT16:
|
||||
- return g_variant_new_int16 (g_variant_get_int16 (value));
|
||||
+ if (byteswap)
|
||||
+ return g_variant_new_int16 (GUINT16_SWAP_LE_BE (g_variant_get_int16 (value)));
|
||||
+ else
|
||||
+ return g_variant_new_int16 (g_variant_get_int16 (value));
|
||||
|
||||
case G_VARIANT_CLASS_UINT16:
|
||||
- return g_variant_new_uint16 (g_variant_get_uint16 (value));
|
||||
+ if (byteswap)
|
||||
+ return g_variant_new_uint16 (GUINT16_SWAP_LE_BE (g_variant_get_uint16 (value)));
|
||||
+ else
|
||||
+ return g_variant_new_uint16 (g_variant_get_uint16 (value));
|
||||
|
||||
case G_VARIANT_CLASS_INT32:
|
||||
- return g_variant_new_int32 (g_variant_get_int32 (value));
|
||||
+ if (byteswap)
|
||||
+ return g_variant_new_int32 (GUINT32_SWAP_LE_BE (g_variant_get_int32 (value)));
|
||||
+ else
|
||||
+ return g_variant_new_int32 (g_variant_get_int32 (value));
|
||||
|
||||
case G_VARIANT_CLASS_UINT32:
|
||||
- return g_variant_new_uint32 (g_variant_get_uint32 (value));
|
||||
+ if (byteswap)
|
||||
+ return g_variant_new_uint32 (GUINT32_SWAP_LE_BE (g_variant_get_uint32 (value)));
|
||||
+ else
|
||||
+ return g_variant_new_uint32 (g_variant_get_uint32 (value));
|
||||
|
||||
case G_VARIANT_CLASS_INT64:
|
||||
- return g_variant_new_int64 (g_variant_get_int64 (value));
|
||||
+ if (byteswap)
|
||||
+ return g_variant_new_int64 (GUINT64_SWAP_LE_BE (g_variant_get_int64 (value)));
|
||||
+ else
|
||||
+ return g_variant_new_int64 (g_variant_get_int64 (value));
|
||||
|
||||
case G_VARIANT_CLASS_UINT64:
|
||||
- return g_variant_new_uint64 (g_variant_get_uint64 (value));
|
||||
+ if (byteswap)
|
||||
+ return g_variant_new_uint64 (GUINT64_SWAP_LE_BE (g_variant_get_uint64 (value)));
|
||||
+ else
|
||||
+ return g_variant_new_uint64 (g_variant_get_uint64 (value));
|
||||
|
||||
case G_VARIANT_CLASS_HANDLE:
|
||||
- return g_variant_new_handle (g_variant_get_handle (value));
|
||||
+ if (byteswap)
|
||||
+ return g_variant_new_handle (GUINT32_SWAP_LE_BE (g_variant_get_handle (value)));
|
||||
+ else
|
||||
+ return g_variant_new_handle (g_variant_get_handle (value));
|
||||
|
||||
case G_VARIANT_CLASS_DOUBLE:
|
||||
- return g_variant_new_double (g_variant_get_double (value));
|
||||
+ if (byteswap)
|
||||
+ {
|
||||
+ /* We have to convert the double to a uint64 here using a union,
|
||||
+ * because a cast will round it numerically. */
|
||||
+ union
|
||||
+ {
|
||||
+ guint64 u64;
|
||||
+ gdouble dbl;
|
||||
+ } u1, u2;
|
||||
+ u1.dbl = g_variant_get_double (value);
|
||||
+ u2.u64 = GUINT64_SWAP_LE_BE (u1.u64);
|
||||
+ return g_variant_new_double (u2.dbl);
|
||||
+ }
|
||||
+ else
|
||||
+ return g_variant_new_double (g_variant_get_double (value));
|
||||
|
||||
case G_VARIANT_CLASS_STRING:
|
||||
return g_variant_new_string (g_variant_get_string (value, NULL));
|
||||
@@ -5896,7 +5932,7 @@ g_variant_get_normal_form (GVariant *value)
|
||||
if (g_variant_is_normal_form (value))
|
||||
return g_variant_ref (value);
|
||||
|
||||
- trusted = g_variant_deep_copy (value);
|
||||
+ trusted = g_variant_deep_copy (value, FALSE);
|
||||
g_assert (g_variant_is_trusted (trusted));
|
||||
|
||||
return g_variant_ref_sink (trusted);
|
||||
@@ -5916,6 +5952,11 @@ g_variant_get_normal_form (GVariant *value)
|
||||
* contain multi-byte numeric data. That include strings, booleans,
|
||||
* bytes and containers containing only these things (recursively).
|
||||
*
|
||||
+ * While this function can safely handle untrusted, non-normal data, it is
|
||||
+ * recommended to check whether the input is in normal form beforehand, using
|
||||
+ * g_variant_is_normal_form(), and to reject non-normal inputs if your
|
||||
+ * application can be strict about what inputs it rejects.
|
||||
+ *
|
||||
* The returned value is always in normal form and is marked as trusted.
|
||||
*
|
||||
* Returns: (transfer full): the byteswapped form of @value
|
||||
@@ -5933,21 +5974,20 @@ g_variant_byteswap (GVariant *value)
|
||||
|
||||
g_variant_type_info_query (type_info, &alignment, NULL);
|
||||
|
||||
- if (alignment)
|
||||
- /* (potentially) contains multi-byte numeric data */
|
||||
+ if (alignment && g_variant_is_normal_form (value))
|
||||
{
|
||||
+ /* (potentially) contains multi-byte numeric data, but is also already in
|
||||
+ * normal form so we can use a faster byteswapping codepath on the
|
||||
+ * serialised data */
|
||||
GVariantSerialised serialised = { 0, };
|
||||
- GVariant *trusted;
|
||||
GBytes *bytes;
|
||||
|
||||
- trusted = g_variant_get_normal_form (value);
|
||||
- serialised.type_info = g_variant_get_type_info (trusted);
|
||||
- serialised.size = g_variant_get_size (trusted);
|
||||
+ serialised.type_info = g_variant_get_type_info (value);
|
||||
+ serialised.size = g_variant_get_size (value);
|
||||
serialised.data = g_malloc (serialised.size);
|
||||
serialised.ordered_offsets_up_to = G_MAXSIZE; /* operating on the normal form */
|
||||
serialised.checked_offsets_up_to = G_MAXSIZE;
|
||||
- g_variant_store (trusted, serialised.data);
|
||||
- g_variant_unref (trusted);
|
||||
+ g_variant_store (value, serialised.data);
|
||||
|
||||
g_variant_serialised_byteswap (serialised);
|
||||
|
||||
@@ -5955,6 +5995,9 @@ g_variant_byteswap (GVariant *value)
|
||||
new = g_variant_ref_sink (g_variant_new_from_bytes (g_variant_get_type (value), bytes, TRUE));
|
||||
g_bytes_unref (bytes);
|
||||
}
|
||||
+ else if (alignment)
|
||||
+ /* (potentially) contains multi-byte numeric data */
|
||||
+ new = g_variant_ref_sink (g_variant_deep_copy (value, TRUE));
|
||||
else
|
||||
/* contains no multi-byte data */
|
||||
new = g_variant_get_normal_form (value);
|
||||
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
|
||||
index 3dda08e..679dd40 100644
|
||||
--- a/glib/tests/gvariant.c
|
||||
+++ b/glib/tests/gvariant.c
|
||||
@@ -2284,24 +2284,67 @@ serialise_tree (TreeInstance *tree,
|
||||
static void
|
||||
test_byteswap (void)
|
||||
{
|
||||
- GVariantSerialised one = { 0, }, two = { 0, };
|
||||
+ GVariantSerialised one = { 0, }, two = { 0, }, three = { 0, };
|
||||
TreeInstance *tree;
|
||||
-
|
||||
+ GVariant *one_variant = NULL;
|
||||
+ GVariant *two_variant = NULL;
|
||||
+ GVariant *two_byteswapped = NULL;
|
||||
+ GVariant *three_variant = NULL;
|
||||
+ GVariant *three_byteswapped = NULL;
|
||||
+ guint8 *three_data_copy = NULL;
|
||||
+ gsize three_size_copy = 0;
|
||||
+
|
||||
+ /* Write a tree out twice, once normally and once byteswapped. */
|
||||
tree = tree_instance_new (NULL, 3);
|
||||
serialise_tree (tree, &one);
|
||||
|
||||
+ one_variant = g_variant_new_from_data (G_VARIANT_TYPE (g_variant_type_info_get_type_string (one.type_info)),
|
||||
+ one.data, one.size, FALSE, NULL, NULL);
|
||||
+
|
||||
i_am_writing_byteswapped = TRUE;
|
||||
serialise_tree (tree, &two);
|
||||
+ serialise_tree (tree, &three);
|
||||
i_am_writing_byteswapped = FALSE;
|
||||
|
||||
- g_variant_serialised_byteswap (two);
|
||||
-
|
||||
- g_assert_cmpmem (one.data, one.size, two.data, two.size);
|
||||
- g_assert_cmpuint (one.depth, ==, two.depth);
|
||||
-
|
||||
+ /* Swap the first byteswapped one back using the function we want to test. */
|
||||
+ two_variant = g_variant_new_from_data (G_VARIANT_TYPE (g_variant_type_info_get_type_string (two.type_info)),
|
||||
+ two.data, two.size, FALSE, NULL, NULL);
|
||||
+ two_byteswapped = g_variant_byteswap (two_variant);
|
||||
+
|
||||
+ /* Make the second byteswapped one non-normal (hopefully), and then byteswap
|
||||
+ * it back using the function we want to test in its non-normal mode.
|
||||
+ * This might not work because it’s not necessarily possible to make an
|
||||
+ * arbitrary random variant non-normal. Adding a single zero byte to the end
|
||||
+ * often makes something non-normal but still readable. */
|
||||
+ three_size_copy = three.size + 1;
|
||||
+ three_data_copy = g_malloc (three_size_copy);
|
||||
+ memcpy (three_data_copy, three.data, three.size);
|
||||
+ three_data_copy[three.size] = '\0';
|
||||
+
|
||||
+ three_variant = g_variant_new_from_data (G_VARIANT_TYPE (g_variant_type_info_get_type_string (three.type_info)),
|
||||
+ three_data_copy, three_size_copy, FALSE, NULL, NULL);
|
||||
+ three_byteswapped = g_variant_byteswap (three_variant);
|
||||
+
|
||||
+ /* Check they’re the same. We can always compare @one_variant and
|
||||
+ * @two_byteswapped. We can only compare @two_byteswapped and
|
||||
+ * @three_byteswapped if @two_variant and @three_variant are equal: in that
|
||||
+ * case, the corruption to @three_variant was enough to make it non-normal but
|
||||
+ * not enough to change its value. */
|
||||
+ g_assert_cmpvariant (one_variant, two_byteswapped);
|
||||
+
|
||||
+ if (g_variant_equal (two_variant, three_variant))
|
||||
+ g_assert_cmpvariant (two_byteswapped, three_byteswapped);
|
||||
+
|
||||
+ g_variant_unref (three_byteswapped);
|
||||
+ g_variant_unref (three_variant);
|
||||
+ g_variant_unref (two_byteswapped);
|
||||
+ g_variant_unref (two_variant);
|
||||
+ g_variant_unref (one_variant);
|
||||
tree_instance_free (tree);
|
||||
g_free (one.data);
|
||||
g_free (two.data);
|
||||
+ g_free (three.data);
|
||||
+ g_free (three_data_copy);
|
||||
}
|
||||
|
||||
static void
|
||||
--
|
||||
2.24.4
|
||||
|
||||
49
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32636.patch
Normal file
49
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32636.patch
Normal file
@@ -0,0 +1,49 @@
|
||||
From 21a204147b16539b3eda3143b32844c49e29f4d4 Mon Sep 17 00:00:00 2001
|
||||
From: Philip Withnall <pwithnall@endlessos.org>
|
||||
Date: Thu, 17 Aug 2023 11:33:49 +0000
|
||||
Subject: [PATCH] gvariant: Propagate trust when getting a child of a
|
||||
serialised variant
|
||||
|
||||
If a variant is trusted, that means all its children are trusted, so
|
||||
ensure that their checked offsets are set as such.
|
||||
|
||||
This allows a lot of the offset table checks to be avoided when getting
|
||||
children from trusted serialised tuples, which speeds things up.
|
||||
|
||||
No unit test is included because this is just a performance fix. If
|
||||
there are other slownesses, or regressions, in serialised `GVariant`
|
||||
performance, the fuzzing setup will catch them like it did this one.
|
||||
|
||||
This change does reduce the time to run the oss-fuzz reproducer from 80s
|
||||
to about 0.7s on my machine.
|
||||
|
||||
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
||||
|
||||
Fixes: #2841
|
||||
oss-fuzz#54314
|
||||
|
||||
CVE: CVE-2023-32636
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/21a204147b16539b3eda3143b32844c49e29f4d4]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-core.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
|
||||
index 1b9d5cc..ed57c70 100644
|
||||
--- a/glib/gvariant-core.c
|
||||
+++ b/glib/gvariant-core.c
|
||||
@@ -1173,8 +1173,8 @@ g_variant_get_child_value (GVariant *value,
|
||||
child->contents.serialised.bytes =
|
||||
g_bytes_ref (value->contents.serialised.bytes);
|
||||
child->contents.serialised.data = s_child.data;
|
||||
- child->contents.serialised.ordered_offsets_up_to = s_child.ordered_offsets_up_to;
|
||||
- child->contents.serialised.checked_offsets_up_to = s_child.checked_offsets_up_to;
|
||||
+ child->contents.serialised.ordered_offsets_up_to = (value->state & STATE_TRUSTED) ? G_MAXSIZE : s_child.ordered_offsets_up_to;
|
||||
+ child->contents.serialised.checked_offsets_up_to = (value->state & STATE_TRUSTED) ? G_MAXSIZE : s_child.checked_offsets_up_to;
|
||||
|
||||
return child;
|
||||
}
|
||||
--
|
||||
2.24.4
|
||||
|
||||
154
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32643.patch
Normal file
154
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32643.patch
Normal file
@@ -0,0 +1,154 @@
|
||||
From 78da5faccb3e065116b75b3ff87ff55381da6c76 Mon Sep 17 00:00:00 2001
|
||||
From: Philip Withnall <pwithnall@endlessos.org>
|
||||
Date: Thu, 17 Aug 2023 11:24:43 +0000
|
||||
Subject: [PATCH] gvariant: Check offset table doesn't fall outside variant
|
||||
bounds
|
||||
|
||||
When dereferencing the first entry in the offset table for a tuple,
|
||||
check that it doesn’t fall outside the bounds of the variant first.
|
||||
|
||||
This prevents an out-of-bounds read from some non-normal tuples.
|
||||
|
||||
This bug was introduced in commit 73d0aa81c2575a5c9ae77d.
|
||||
|
||||
Includes a unit test, although the test will likely only catch the
|
||||
original bug if run with asan enabled.
|
||||
|
||||
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
||||
|
||||
Fixes: #2840
|
||||
oss-fuzz#54302
|
||||
|
||||
CVE: CVE-2023-32643
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/78da5faccb3e065116b75b3ff87ff55381da6c76]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-serialiser.c | 12 ++++++--
|
||||
glib/tests/gvariant.c | 63 ++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 72 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
|
||||
index 5aa2cbc..4e50ed7 100644
|
||||
--- a/glib/gvariant-serialiser.c
|
||||
+++ b/glib/gvariant-serialiser.c
|
||||
@@ -979,7 +979,8 @@ gvs_tuple_get_member_bounds (GVariantSerialised value,
|
||||
|
||||
member_info = g_variant_type_info_member_info (value.type_info, index_);
|
||||
|
||||
- if (member_info->i + 1)
|
||||
+ if (member_info->i + 1 &&
|
||||
+ offset_size * (member_info->i + 1) <= value.size)
|
||||
member_start = gvs_read_unaligned_le (value.data + value.size -
|
||||
offset_size * (member_info->i + 1),
|
||||
offset_size);
|
||||
@@ -990,7 +991,8 @@ gvs_tuple_get_member_bounds (GVariantSerialised value,
|
||||
member_start &= member_info->b;
|
||||
member_start |= member_info->c;
|
||||
|
||||
- if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_LAST)
|
||||
+ if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_LAST &&
|
||||
+ offset_size * (member_info->i + 1) <= value.size)
|
||||
member_end = value.size - offset_size * (member_info->i + 1);
|
||||
|
||||
else if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_FIXED)
|
||||
@@ -1001,11 +1003,15 @@ gvs_tuple_get_member_bounds (GVariantSerialised value,
|
||||
member_end = member_start + fixed_size;
|
||||
}
|
||||
|
||||
- else /* G_VARIANT_MEMBER_ENDING_OFFSET */
|
||||
+ else if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_OFFSET &&
|
||||
+ offset_size * (member_info->i + 2) <= value.size)
|
||||
member_end = gvs_read_unaligned_le (value.data + value.size -
|
||||
offset_size * (member_info->i + 2),
|
||||
offset_size);
|
||||
|
||||
+ else /* invalid */
|
||||
+ member_end = G_MAXSIZE;
|
||||
+
|
||||
if (out_member_start != NULL)
|
||||
*out_member_start = member_start;
|
||||
if (out_member_end != NULL)
|
||||
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
|
||||
index 679dd40..2eca8be 100644
|
||||
--- a/glib/tests/gvariant.c
|
||||
+++ b/glib/tests/gvariant.c
|
||||
@@ -5432,6 +5432,67 @@ test_normal_checking_tuple_offsets4 (void)
|
||||
g_variant_unref (variant);
|
||||
}
|
||||
|
||||
+/* This is a regression test that dereferencing the first element in the offset
|
||||
+ * table doesn’t dereference memory before the start of the GVariant. The first
|
||||
+ * element in the offset table gives the offset of the final member in the
|
||||
+ * tuple (the offset table is stored in reverse), and the position of this final
|
||||
+ * member is needed to check that none of the tuple members overlap with the
|
||||
+ * offset table
|
||||
+ *
|
||||
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/2840 */
|
||||
+static void
|
||||
+test_normal_checking_tuple_offsets5 (void)
|
||||
+{
|
||||
+ /* A tuple of type (sss) in normal form would have an offset table with two
|
||||
+ * entries:
|
||||
+ * - The first entry (lowest index in the table) gives the offset of the
|
||||
+ * third `s` in the tuple, as the offset table is reversed compared to the
|
||||
+ * tuple members.
|
||||
+ * - The second entry (highest index in the table) gives the offset of the
|
||||
+ * second `s` in the tuple.
|
||||
+ * - The offset of the first `s` in the tuple is always 0.
|
||||
+ *
|
||||
+ * See §2.5.4 (Structures) of the GVariant specification for details, noting
|
||||
+ * that the table is only layed out this way because all three members of the
|
||||
+ * tuple have non-fixed sizes.
|
||||
+ *
|
||||
+ * It’s not clear whether the 0xaa data of this variant is part of the strings
|
||||
+ * in the tuple, or part of the offset table. It doesn’t really matter. This
|
||||
+ * is a regression test to check that the code to validate the offset table
|
||||
+ * doesn’t unconditionally try to access the first entry in the offset table
|
||||
+ * by subtracting the table size from the end of the GVariant data.
|
||||
+ *
|
||||
+ * In this non-normal case, that would result in an address off the start of
|
||||
+ * the GVariant data, and an out-of-bounds read, because the GVariant is one
|
||||
+ * byte long, but the offset table is calculated as two bytes long (with 1B
|
||||
+ * sized entries) from the tuple’s type.
|
||||
+ */
|
||||
+ const GVariantType *data_type = G_VARIANT_TYPE ("(sss)");
|
||||
+ const guint8 data[] = { 0xaa };
|
||||
+ gsize size = sizeof (data);
|
||||
+ GVariant *variant = NULL;
|
||||
+ GVariant *normal_variant = NULL;
|
||||
+ GVariant *expected = NULL;
|
||||
+
|
||||
+ g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2840");
|
||||
+
|
||||
+ variant = g_variant_new_from_data (data_type, data, size, FALSE, NULL, NULL);
|
||||
+ g_assert_nonnull (variant);
|
||||
+
|
||||
+ g_assert_false (g_variant_is_normal_form (variant));
|
||||
+
|
||||
+ normal_variant = g_variant_get_normal_form (variant);
|
||||
+ g_assert_nonnull (normal_variant);
|
||||
+
|
||||
+ expected = g_variant_new_parsed ("('', '', '')");
|
||||
+ g_assert_cmpvariant (expected, variant);
|
||||
+ g_assert_cmpvariant (expected, normal_variant);
|
||||
+
|
||||
+ g_variant_unref (expected);
|
||||
+ g_variant_unref (normal_variant);
|
||||
+ g_variant_unref (variant);
|
||||
+}
|
||||
+
|
||||
/* Test that an otherwise-valid serialised GVariant is considered non-normal if
|
||||
* its offset table entries are too wide.
|
||||
*
|
||||
@@ -5680,6 +5741,8 @@ main (int argc, char **argv)
|
||||
test_normal_checking_tuple_offsets3);
|
||||
g_test_add_func ("/gvariant/normal-checking/tuple-offsets4",
|
||||
test_normal_checking_tuple_offsets4);
|
||||
+ g_test_add_func ("/gvariant/normal-checking/tuple-offsets5",
|
||||
+ test_normal_checking_tuple_offsets5);
|
||||
g_test_add_func ("/gvariant/normal-checking/tuple-offsets/minimal-sized",
|
||||
test_normal_checking_tuple_offsets_minimal_sized);
|
||||
g_test_add_func ("/gvariant/normal-checking/empty-object-path",
|
||||
--
|
||||
2.24.4
|
||||
|
||||
103
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0001.patch
Normal file
103
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0001.patch
Normal file
@@ -0,0 +1,103 @@
|
||||
From 1deacdd4e8e35a5cf1417918ca4f6b0afa6409b1 Mon Sep 17 00:00:00 2001
|
||||
From: William Manley <will@stb-tester.com>
|
||||
Date: Wed, 9 Aug 2023 10:04:49 +0000
|
||||
Subject: [PATCH] gvariant-core: Consolidate construction of
|
||||
`GVariantSerialised`
|
||||
|
||||
So I only need to change it in one place.
|
||||
|
||||
This introduces no functional changes.
|
||||
|
||||
Helps: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/1deacdd4e8e35a5cf1417918ca4f6b0afa6409b1]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-core.c | 49 ++++++++++++++++++++++----------------------
|
||||
1 file changed, 25 insertions(+), 24 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
|
||||
index 9397573..aa0e0a0 100644
|
||||
--- a/glib/gvariant-core.c
|
||||
+++ b/glib/gvariant-core.c
|
||||
@@ -349,6 +349,27 @@ g_variant_ensure_size (GVariant *value)
|
||||
}
|
||||
}
|
||||
|
||||
+/* < private >
|
||||
+ * g_variant_to_serialised:
|
||||
+ * @value: a #GVariant
|
||||
+ *
|
||||
+ * Gets a GVariantSerialised for a GVariant in state STATE_SERIALISED.
|
||||
+ */
|
||||
+inline static GVariantSerialised
|
||||
+g_variant_to_serialised (GVariant *value)
|
||||
+{
|
||||
+ g_assert (value->state & STATE_SERIALISED);
|
||||
+ {
|
||||
+ GVariantSerialised serialised = {
|
||||
+ value->type_info,
|
||||
+ (gpointer) value->contents.serialised.data,
|
||||
+ value->size,
|
||||
+ value->depth,
|
||||
+ };
|
||||
+ return serialised;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
/* < private >
|
||||
* g_variant_serialise:
|
||||
* @value: a #GVariant
|
||||
@@ -991,16 +1012,8 @@ g_variant_n_children (GVariant *value)
|
||||
g_variant_lock (value);
|
||||
|
||||
if (value->state & STATE_SERIALISED)
|
||||
- {
|
||||
- GVariantSerialised serialised = {
|
||||
- value->type_info,
|
||||
- (gpointer) value->contents.serialised.data,
|
||||
- value->size,
|
||||
- value->depth,
|
||||
- };
|
||||
-
|
||||
- n_children = g_variant_serialised_n_children (serialised);
|
||||
- }
|
||||
+ n_children = g_variant_serialised_n_children (
|
||||
+ g_variant_to_serialised (value));
|
||||
else
|
||||
n_children = value->contents.tree.n_children;
|
||||
|
||||
@@ -1061,12 +1074,7 @@ g_variant_get_child_value (GVariant *value,
|
||||
}
|
||||
|
||||
{
|
||||
- GVariantSerialised serialised = {
|
||||
- value->type_info,
|
||||
- (gpointer) value->contents.serialised.data,
|
||||
- value->size,
|
||||
- value->depth,
|
||||
- };
|
||||
+ GVariantSerialised serialised = g_variant_to_serialised (value);
|
||||
GVariantSerialised s_child;
|
||||
GVariant *child;
|
||||
|
||||
@@ -1179,14 +1187,7 @@ g_variant_is_normal_form (GVariant *value)
|
||||
|
||||
if (value->state & STATE_SERIALISED)
|
||||
{
|
||||
- GVariantSerialised serialised = {
|
||||
- value->type_info,
|
||||
- (gpointer) value->contents.serialised.data,
|
||||
- value->size,
|
||||
- value->depth
|
||||
- };
|
||||
-
|
||||
- if (g_variant_serialised_is_normal (serialised))
|
||||
+ if (g_variant_serialised_is_normal (g_variant_to_serialised (value)))
|
||||
value->state |= STATE_TRUSTED;
|
||||
}
|
||||
else
|
||||
--
|
||||
2.24.4
|
||||
|
||||
210
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0002.patch
Normal file
210
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0002.patch
Normal file
@@ -0,0 +1,210 @@
|
||||
From 446e69f5edd72deb2196dee36bbaf8056caf6948 Mon Sep 17 00:00:00 2001
|
||||
From: William Manley <will@stb-tester.com>
|
||||
Date: Wed, 9 Aug 2023 10:39:34 +0000
|
||||
Subject: [PATCH] gvariant-serialiser: Factor out functions for dealing with
|
||||
framing offsets
|
||||
|
||||
This introduces no functional changes.
|
||||
|
||||
Helps: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/446e69f5edd72deb2196dee36bbaf8056caf6948]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-serialiser.c | 108 +++++++++++++++++++------------------
|
||||
1 file changed, 57 insertions(+), 51 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
|
||||
index 83e9d85..c7c2114 100644
|
||||
--- a/glib/gvariant-serialiser.c
|
||||
+++ b/glib/gvariant-serialiser.c
|
||||
@@ -633,30 +633,62 @@ gvs_calculate_total_size (gsize body_size,
|
||||
return body_size + 8 * offsets;
|
||||
}
|
||||
|
||||
+struct Offsets
|
||||
+{
|
||||
+ gsize data_size;
|
||||
+
|
||||
+ guchar *array;
|
||||
+ gsize length;
|
||||
+ guint offset_size;
|
||||
+
|
||||
+ gboolean is_normal;
|
||||
+};
|
||||
+
|
||||
static gsize
|
||||
-gvs_variable_sized_array_n_children (GVariantSerialised value)
|
||||
+gvs_offsets_get_offset_n (struct Offsets *offsets,
|
||||
+ gsize n)
|
||||
+{
|
||||
+ return gvs_read_unaligned_le (
|
||||
+ offsets->array + (offsets->offset_size * n), offsets->offset_size);
|
||||
+}
|
||||
+
|
||||
+static struct Offsets
|
||||
+gvs_variable_sized_array_get_frame_offsets (GVariantSerialised value)
|
||||
{
|
||||
+ struct Offsets out = { 0, };
|
||||
gsize offsets_array_size;
|
||||
- gsize offset_size;
|
||||
gsize last_end;
|
||||
|
||||
if (value.size == 0)
|
||||
- return 0;
|
||||
-
|
||||
- offset_size = gvs_get_offset_size (value.size);
|
||||
+ {
|
||||
+ out.is_normal = TRUE;
|
||||
+ return out;
|
||||
+ }
|
||||
|
||||
- last_end = gvs_read_unaligned_le (value.data + value.size -
|
||||
- offset_size, offset_size);
|
||||
+ out.offset_size = gvs_get_offset_size (value.size);
|
||||
+ last_end = gvs_read_unaligned_le (value.data + value.size - out.offset_size,
|
||||
+ out.offset_size);
|
||||
|
||||
if (last_end > value.size)
|
||||
- return 0;
|
||||
+ return out; /* offsets not normal */
|
||||
|
||||
offsets_array_size = value.size - last_end;
|
||||
|
||||
- if (offsets_array_size % offset_size)
|
||||
- return 0;
|
||||
+ if (offsets_array_size % out.offset_size)
|
||||
+ return out; /* offsets not normal */
|
||||
+
|
||||
+ out.data_size = last_end;
|
||||
+ out.array = value.data + last_end;
|
||||
+ out.length = offsets_array_size / out.offset_size;
|
||||
+ out.is_normal = TRUE;
|
||||
|
||||
- return offsets_array_size / offset_size;
|
||||
+ return out;
|
||||
+}
|
||||
+
|
||||
+static gsize
|
||||
+gvs_variable_sized_array_n_children (GVariantSerialised value)
|
||||
+{
|
||||
+ return gvs_variable_sized_array_get_frame_offsets (value).length;
|
||||
}
|
||||
|
||||
static GVariantSerialised
|
||||
@@ -664,8 +696,9 @@ gvs_variable_sized_array_get_child (GVariantSerialised value,
|
||||
gsize index_)
|
||||
{
|
||||
GVariantSerialised child = { 0, };
|
||||
- gsize offset_size;
|
||||
- gsize last_end;
|
||||
+
|
||||
+ struct Offsets offsets = gvs_variable_sized_array_get_frame_offsets (value);
|
||||
+
|
||||
gsize start;
|
||||
gsize end;
|
||||
|
||||
@@ -673,18 +706,11 @@ gvs_variable_sized_array_get_child (GVariantSerialised value,
|
||||
g_variant_type_info_ref (child.type_info);
|
||||
child.depth = value.depth + 1;
|
||||
|
||||
- offset_size = gvs_get_offset_size (value.size);
|
||||
-
|
||||
- last_end = gvs_read_unaligned_le (value.data + value.size -
|
||||
- offset_size, offset_size);
|
||||
-
|
||||
if (index_ > 0)
|
||||
{
|
||||
guint alignment;
|
||||
|
||||
- start = gvs_read_unaligned_le (value.data + last_end +
|
||||
- (offset_size * (index_ - 1)),
|
||||
- offset_size);
|
||||
+ start = gvs_offsets_get_offset_n (&offsets, index_ - 1);
|
||||
|
||||
g_variant_type_info_query (child.type_info, &alignment, NULL);
|
||||
start += (-start) & alignment;
|
||||
@@ -692,11 +718,9 @@ gvs_variable_sized_array_get_child (GVariantSerialised value,
|
||||
else
|
||||
start = 0;
|
||||
|
||||
- end = gvs_read_unaligned_le (value.data + last_end +
|
||||
- (offset_size * index_),
|
||||
- offset_size);
|
||||
+ end = gvs_offsets_get_offset_n (&offsets, index_);
|
||||
|
||||
- if (start < end && end <= value.size && end <= last_end)
|
||||
+ if (start < end && end <= value.size && end <= offsets.data_size)
|
||||
{
|
||||
child.data = value.data + start;
|
||||
child.size = end - start;
|
||||
@@ -768,34 +792,16 @@ static gboolean
|
||||
gvs_variable_sized_array_is_normal (GVariantSerialised value)
|
||||
{
|
||||
GVariantSerialised child = { 0, };
|
||||
- gsize offsets_array_size;
|
||||
- guchar *offsets_array;
|
||||
- guint offset_size;
|
||||
guint alignment;
|
||||
- gsize last_end;
|
||||
- gsize length;
|
||||
gsize offset;
|
||||
gsize i;
|
||||
|
||||
- if (value.size == 0)
|
||||
- return TRUE;
|
||||
-
|
||||
- offset_size = gvs_get_offset_size (value.size);
|
||||
- last_end = gvs_read_unaligned_le (value.data + value.size -
|
||||
- offset_size, offset_size);
|
||||
+ struct Offsets offsets = gvs_variable_sized_array_get_frame_offsets (value);
|
||||
|
||||
- if (last_end > value.size)
|
||||
+ if (!offsets.is_normal)
|
||||
return FALSE;
|
||||
|
||||
- offsets_array_size = value.size - last_end;
|
||||
-
|
||||
- if (offsets_array_size % offset_size)
|
||||
- return FALSE;
|
||||
-
|
||||
- offsets_array = value.data + value.size - offsets_array_size;
|
||||
- length = offsets_array_size / offset_size;
|
||||
-
|
||||
- if (length == 0)
|
||||
+ if (value.size != 0 && offsets.length == 0)
|
||||
return FALSE;
|
||||
|
||||
child.type_info = g_variant_type_info_element (value.type_info);
|
||||
@@ -803,14 +809,14 @@ gvs_variable_sized_array_is_normal (GVariantSerialised value)
|
||||
child.depth = value.depth + 1;
|
||||
offset = 0;
|
||||
|
||||
- for (i = 0; i < length; i++)
|
||||
+ for (i = 0; i < offsets.length; i++)
|
||||
{
|
||||
gsize this_end;
|
||||
|
||||
- this_end = gvs_read_unaligned_le (offsets_array + offset_size * i,
|
||||
- offset_size);
|
||||
+ this_end = gvs_read_unaligned_le (offsets.array + offsets.offset_size * i,
|
||||
+ offsets.offset_size);
|
||||
|
||||
- if (this_end < offset || this_end > last_end)
|
||||
+ if (this_end < offset || this_end > offsets.data_size)
|
||||
return FALSE;
|
||||
|
||||
while (offset & alignment)
|
||||
@@ -832,7 +838,7 @@ gvs_variable_sized_array_is_normal (GVariantSerialised value)
|
||||
offset = this_end;
|
||||
}
|
||||
|
||||
- g_assert (offset == last_end);
|
||||
+ g_assert (offset == offsets.data_size);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
--
|
||||
2.24.4
|
||||
|
||||
417
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0003.patch
Normal file
417
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0003.patch
Normal file
@@ -0,0 +1,417 @@
|
||||
From ade71fb544391b2e33e1859645726bfee0d5eaaf Mon Sep 17 00:00:00 2001
|
||||
From: William Manley <will@stb-tester.com>
|
||||
Date: Wed, 16 Aug 2023 03:12:21 +0000
|
||||
Subject: [PATCH] gvariant: Don't allow child elements to overlap with each
|
||||
other
|
||||
|
||||
If different elements of a variable sized array can overlap with each
|
||||
other then we can cause a `GVariant` to normalise to a much larger type.
|
||||
|
||||
This commit changes the behaviour of `GVariant` with non-normal form data. If
|
||||
an invalid frame offset is found all subsequent elements are given their
|
||||
default value.
|
||||
|
||||
When retrieving an element at index `n` we scan the frame offsets up to index
|
||||
`n` and if they are not in order we return an element with the default value
|
||||
for that type. This guarantees that elements don't overlap with each
|
||||
other. We remember the offset we've scanned up to so we don't need to
|
||||
repeat this work on subsequent accesses. We skip these checks for trusted
|
||||
data.
|
||||
|
||||
Unfortunately this makes random access of untrusted data O(n) — at least
|
||||
on first access. It doesn't affect the algorithmic complexity of accessing
|
||||
elements in order, such as when using the `GVariantIter` interface. Also:
|
||||
the cost of validation will be amortised as the `GVariant` instance is
|
||||
continued to be used.
|
||||
|
||||
I've implemented this with 4 different functions, 1 for each element size,
|
||||
rather than looping calling `gvs_read_unaligned_le` in the hope that the
|
||||
compiler will find it easy to optimise and should produce fairly tight
|
||||
code.
|
||||
|
||||
Fixes: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/ade71fb544391b2e33e1859645726bfee0d5eaaf]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-core.c | 35 ++++++++++++++++
|
||||
glib/gvariant-serialiser.c | 86 ++++++++++++++++++++++++++++++++++++--
|
||||
glib/gvariant-serialiser.h | 8 ++++
|
||||
glib/tests/gvariant.c | 45 ++++++++++++++++++++
|
||||
4 files changed, 171 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
|
||||
index aa0e0a0..9b51e15 100644
|
||||
--- a/glib/gvariant-core.c
|
||||
+++ b/glib/gvariant-core.c
|
||||
@@ -65,6 +65,7 @@ struct _GVariant
|
||||
{
|
||||
GBytes *bytes;
|
||||
gconstpointer data;
|
||||
+ gsize ordered_offsets_up_to;
|
||||
} serialised;
|
||||
|
||||
struct
|
||||
@@ -162,6 +163,24 @@ struct _GVariant
|
||||
* if .data pointed to the appropriate number of nul
|
||||
* bytes.
|
||||
*
|
||||
+ * .ordered_offsets_up_to: If ordered_offsets_up_to == n this means that all
|
||||
+ * the frame offsets up to and including the frame
|
||||
+ * offset determining the end of element n are in
|
||||
+ * order. This guarantees that the bytes of element
|
||||
+ * n don't overlap with any previous element.
|
||||
+ *
|
||||
+ * For trusted data this is set to G_MAXSIZE and we
|
||||
+ * don't check that the frame offsets are in order.
|
||||
+ *
|
||||
+ * Note: This doesn't imply the offsets are good in
|
||||
+ * any way apart from their ordering. In particular
|
||||
+ * offsets may be out of bounds for this value or
|
||||
+ * may imply that the data overlaps the frame
|
||||
+ * offsets themselves.
|
||||
+ *
|
||||
+ * This field is only relevant for arrays of non
|
||||
+ * fixed width types.
|
||||
+ *
|
||||
* .tree: Only valid when the instance is in tree form.
|
||||
*
|
||||
* Note that accesses from other threads could result in
|
||||
@@ -365,6 +384,7 @@ g_variant_to_serialised (GVariant *value)
|
||||
(gpointer) value->contents.serialised.data,
|
||||
value->size,
|
||||
value->depth,
|
||||
+ value->contents.serialised.ordered_offsets_up_to,
|
||||
};
|
||||
return serialised;
|
||||
}
|
||||
@@ -396,6 +416,7 @@ g_variant_serialise (GVariant *value,
|
||||
serialised.size = value->size;
|
||||
serialised.data = data;
|
||||
serialised.depth = value->depth;
|
||||
+ serialised.ordered_offsets_up_to = 0;
|
||||
|
||||
children = (gpointer *) value->contents.tree.children;
|
||||
n_children = value->contents.tree.n_children;
|
||||
@@ -439,6 +460,15 @@ g_variant_fill_gvs (GVariantSerialised *serialised,
|
||||
g_assert (serialised->size == value->size);
|
||||
serialised->depth = value->depth;
|
||||
|
||||
+ if (value->state & STATE_SERIALISED)
|
||||
+ {
|
||||
+ serialised->ordered_offsets_up_to = value->contents.serialised.ordered_offsets_up_to;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ serialised->ordered_offsets_up_to = 0;
|
||||
+ }
|
||||
+
|
||||
if (serialised->data)
|
||||
/* g_variant_store() is a public API, so it
|
||||
* it will reacquire the lock if it needs to.
|
||||
@@ -481,6 +511,7 @@ g_variant_ensure_serialised (GVariant *value)
|
||||
bytes = g_bytes_new_take (data, value->size);
|
||||
value->contents.serialised.data = g_bytes_get_data (bytes, NULL);
|
||||
value->contents.serialised.bytes = bytes;
|
||||
+ value->contents.serialised.ordered_offsets_up_to = G_MAXSIZE;
|
||||
value->state |= STATE_SERIALISED;
|
||||
}
|
||||
}
|
||||
@@ -561,6 +592,7 @@ g_variant_new_from_bytes (const GVariantType *type,
|
||||
serialised.type_info = value->type_info;
|
||||
serialised.data = (guchar *) g_bytes_get_data (bytes, &serialised.size);
|
||||
serialised.depth = 0;
|
||||
+ serialised.ordered_offsets_up_to = trusted ? G_MAXSIZE : 0;
|
||||
|
||||
if (!g_variant_serialised_check (serialised))
|
||||
{
|
||||
@@ -610,6 +642,8 @@ g_variant_new_from_bytes (const GVariantType *type,
|
||||
value->contents.serialised.data = g_bytes_get_data (bytes, &value->size);
|
||||
}
|
||||
|
||||
+ value->contents.serialised.ordered_offsets_up_to = trusted ? G_MAXSIZE : 0;
|
||||
+
|
||||
g_clear_pointer (&owned_bytes, g_bytes_unref);
|
||||
|
||||
return value;
|
||||
@@ -1108,6 +1142,7 @@ g_variant_get_child_value (GVariant *value,
|
||||
child->contents.serialised.bytes =
|
||||
g_bytes_ref (value->contents.serialised.bytes);
|
||||
child->contents.serialised.data = s_child.data;
|
||||
+ child->contents.serialised.ordered_offsets_up_to = s_child.ordered_offsets_up_to;
|
||||
|
||||
return child;
|
||||
}
|
||||
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
|
||||
index c7c2114..fe0b1a4 100644
|
||||
--- a/glib/gvariant-serialiser.c
|
||||
+++ b/glib/gvariant-serialiser.c
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright © 2007, 2008 Ryan Lortie
|
||||
* Copyright © 2010 Codethink Limited
|
||||
+ * Copyright © 2020 William Manley
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -264,6 +265,7 @@ gvs_fixed_sized_maybe_get_child (GVariantSerialised value,
|
||||
value.type_info = g_variant_type_info_element (value.type_info);
|
||||
g_variant_type_info_ref (value.type_info);
|
||||
value.depth++;
|
||||
+ value.ordered_offsets_up_to = 0;
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -295,7 +297,7 @@ gvs_fixed_sized_maybe_serialise (GVariantSerialised value,
|
||||
{
|
||||
if (n_children)
|
||||
{
|
||||
- GVariantSerialised child = { NULL, value.data, value.size, value.depth + 1 };
|
||||
+ GVariantSerialised child = { NULL, value.data, value.size, value.depth + 1, 0 };
|
||||
|
||||
gvs_filler (&child, children[0]);
|
||||
}
|
||||
@@ -317,6 +319,7 @@ gvs_fixed_sized_maybe_is_normal (GVariantSerialised value)
|
||||
/* proper element size: "Just". recurse to the child. */
|
||||
value.type_info = g_variant_type_info_element (value.type_info);
|
||||
value.depth++;
|
||||
+ value.ordered_offsets_up_to = 0;
|
||||
|
||||
return g_variant_serialised_is_normal (value);
|
||||
}
|
||||
@@ -358,6 +361,7 @@ gvs_variable_sized_maybe_get_child (GVariantSerialised value,
|
||||
value.data = NULL;
|
||||
|
||||
value.depth++;
|
||||
+ value.ordered_offsets_up_to = 0;
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -388,7 +392,7 @@ gvs_variable_sized_maybe_serialise (GVariantSerialised value,
|
||||
{
|
||||
if (n_children)
|
||||
{
|
||||
- GVariantSerialised child = { NULL, value.data, value.size - 1, value.depth + 1 };
|
||||
+ GVariantSerialised child = { NULL, value.data, value.size - 1, value.depth + 1, 0 };
|
||||
|
||||
/* write the data for the child. */
|
||||
gvs_filler (&child, children[0]);
|
||||
@@ -408,6 +412,7 @@ gvs_variable_sized_maybe_is_normal (GVariantSerialised value)
|
||||
value.type_info = g_variant_type_info_element (value.type_info);
|
||||
value.size--;
|
||||
value.depth++;
|
||||
+ value.ordered_offsets_up_to = 0;
|
||||
|
||||
return g_variant_serialised_is_normal (value);
|
||||
}
|
||||
@@ -691,6 +696,32 @@ gvs_variable_sized_array_n_children (GVariantSerialised value)
|
||||
return gvs_variable_sized_array_get_frame_offsets (value).length;
|
||||
}
|
||||
|
||||
+/* Find the index of the first out-of-order element in @data, assuming that
|
||||
+ * @data is an array of elements of given @type, starting at index @start and
|
||||
+ * containing a further @len-@start elements. */
|
||||
+#define DEFINE_FIND_UNORDERED(type) \
|
||||
+ static gsize \
|
||||
+ find_unordered_##type (const guint8 *data, gsize start, gsize len) \
|
||||
+ { \
|
||||
+ gsize off; \
|
||||
+ type current, previous; \
|
||||
+ \
|
||||
+ memcpy (&previous, data + start * sizeof (current), sizeof (current)); \
|
||||
+ for (off = (start + 1) * sizeof (current); off < len * sizeof (current); off += sizeof (current)) \
|
||||
+ { \
|
||||
+ memcpy (¤t, data + off, sizeof (current)); \
|
||||
+ if (current < previous) \
|
||||
+ break; \
|
||||
+ previous = current; \
|
||||
+ } \
|
||||
+ return off / sizeof (current) - 1; \
|
||||
+ }
|
||||
+
|
||||
+DEFINE_FIND_UNORDERED (guint8);
|
||||
+DEFINE_FIND_UNORDERED (guint16);
|
||||
+DEFINE_FIND_UNORDERED (guint32);
|
||||
+DEFINE_FIND_UNORDERED (guint64);
|
||||
+
|
||||
static GVariantSerialised
|
||||
gvs_variable_sized_array_get_child (GVariantSerialised value,
|
||||
gsize index_)
|
||||
@@ -706,6 +737,49 @@ gvs_variable_sized_array_get_child (GVariantSerialised value,
|
||||
g_variant_type_info_ref (child.type_info);
|
||||
child.depth = value.depth + 1;
|
||||
|
||||
+ /* If the requested @index_ is beyond the set of indices whose framing offsets
|
||||
+ * have been checked, check the remaining offsets to see whether they’re
|
||||
+ * normal (in order, no overlapping array elements). */
|
||||
+ if (index_ > value.ordered_offsets_up_to)
|
||||
+ {
|
||||
+ switch (offsets.offset_size)
|
||||
+ {
|
||||
+ case 1:
|
||||
+ {
|
||||
+ value.ordered_offsets_up_to = find_unordered_guint8 (
|
||||
+ offsets.array, value.ordered_offsets_up_to, index_ + 1);
|
||||
+ break;
|
||||
+ }
|
||||
+ case 2:
|
||||
+ {
|
||||
+ value.ordered_offsets_up_to = find_unordered_guint16 (
|
||||
+ offsets.array, value.ordered_offsets_up_to, index_ + 1);
|
||||
+ break;
|
||||
+ }
|
||||
+ case 4:
|
||||
+ {
|
||||
+ value.ordered_offsets_up_to = find_unordered_guint32 (
|
||||
+ offsets.array, value.ordered_offsets_up_to, index_ + 1);
|
||||
+ break;
|
||||
+ }
|
||||
+ case 8:
|
||||
+ {
|
||||
+ value.ordered_offsets_up_to = find_unordered_guint64 (
|
||||
+ offsets.array, value.ordered_offsets_up_to, index_ + 1);
|
||||
+ break;
|
||||
+ }
|
||||
+ default:
|
||||
+ /* gvs_get_offset_size() only returns maximum 8 */
|
||||
+ g_assert_not_reached ();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (index_ > value.ordered_offsets_up_to)
|
||||
+ {
|
||||
+ /* Offsets are invalid somewhere, so return an empty child. */
|
||||
+ return child;
|
||||
+ }
|
||||
+
|
||||
if (index_ > 0)
|
||||
{
|
||||
guint alignment;
|
||||
@@ -840,6 +914,9 @@ gvs_variable_sized_array_is_normal (GVariantSerialised value)
|
||||
|
||||
g_assert (offset == offsets.data_size);
|
||||
|
||||
+ /* All offsets have now been checked. */
|
||||
+ value.ordered_offsets_up_to = G_MAXSIZE;
|
||||
+
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -1072,7 +1149,7 @@ gvs_tuple_is_normal (GVariantSerialised value)
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
const GVariantMemberInfo *member_info;
|
||||
- GVariantSerialised child;
|
||||
+ GVariantSerialised child = { 0, };
|
||||
gsize fixed_size;
|
||||
guint alignment;
|
||||
gsize end;
|
||||
@@ -1132,6 +1209,9 @@ gvs_tuple_is_normal (GVariantSerialised value)
|
||||
offset = end;
|
||||
}
|
||||
|
||||
+ /* All element bounds have been checked above. */
|
||||
+ value.ordered_offsets_up_to = G_MAXSIZE;
|
||||
+
|
||||
{
|
||||
gsize fixed_size;
|
||||
guint alignment;
|
||||
diff --git a/glib/gvariant-serialiser.h b/glib/gvariant-serialiser.h
|
||||
index 81343e9..99d18ef 100644
|
||||
--- a/glib/gvariant-serialiser.h
|
||||
+++ b/glib/gvariant-serialiser.h
|
||||
@@ -29,6 +29,14 @@ typedef struct
|
||||
guchar *data;
|
||||
gsize size;
|
||||
gsize depth; /* same semantics as GVariant.depth */
|
||||
+ /* If ordered_offsets_up_to == n this means that all the frame offsets up to and
|
||||
+ * including the frame offset determining the end of element n are in order.
|
||||
+ * This guarantees that the bytes of element n don't overlap with any previous
|
||||
+ * element.
|
||||
+ *
|
||||
+ * This is both read and set by g_variant_serialised_get_child for arrays of
|
||||
+ * non-fixed-width types */
|
||||
+ gsize ordered_offsets_up_to;
|
||||
} GVariantSerialised;
|
||||
|
||||
/* deserialisation */
|
||||
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
|
||||
index 0e5ec8e..967e9a1 100644
|
||||
--- a/glib/tests/gvariant.c
|
||||
+++ b/glib/tests/gvariant.c
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright © 2010 Codethink Limited
|
||||
+ * Copyright © 2020 William Manley
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -1283,6 +1284,7 @@ random_instance_filler (GVariantSerialised *serialised,
|
||||
serialised->size = instance->size;
|
||||
|
||||
serialised->depth = 0;
|
||||
+ serialised->ordered_offsets_up_to = 0;
|
||||
|
||||
g_assert_true (serialised->type_info == instance->type_info);
|
||||
g_assert_cmpuint (serialised->size, ==, instance->size);
|
||||
@@ -5039,6 +5041,47 @@ test_normal_checking_array_offsets (void)
|
||||
g_variant_unref (variant);
|
||||
}
|
||||
|
||||
+/* This is a regression test that we can't have non-normal values that take up
|
||||
+ * significantly more space than the normal equivalent, by specifying the
|
||||
+ * offset table entries so that array elements overlap.
|
||||
+ *
|
||||
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/2121#note_832242 */
|
||||
+static void
|
||||
+test_normal_checking_array_offsets2 (void)
|
||||
+{
|
||||
+ const guint8 data[] = {
|
||||
+ 'h', 'i', '\0',
|
||||
+ 0x03, 0x00, 0x03,
|
||||
+ 0x06, 0x00, 0x06,
|
||||
+ 0x09, 0x00, 0x09,
|
||||
+ 0x0c, 0x00, 0x0c,
|
||||
+ 0x0f, 0x00, 0x0f,
|
||||
+ 0x12, 0x00, 0x12,
|
||||
+ 0x15, 0x00, 0x15,
|
||||
+ };
|
||||
+ gsize size = sizeof (data);
|
||||
+ const GVariantType *aaaaaaas = G_VARIANT_TYPE ("aaaaaaas");
|
||||
+ GVariant *variant = NULL;
|
||||
+ GVariant *normal_variant = NULL;
|
||||
+ GVariant *expected = NULL;
|
||||
+
|
||||
+ variant = g_variant_new_from_data (aaaaaaas, data, size, FALSE, NULL, NULL);
|
||||
+ g_assert_nonnull (variant);
|
||||
+
|
||||
+ normal_variant = g_variant_get_normal_form (variant);
|
||||
+ g_assert_nonnull (normal_variant);
|
||||
+ g_assert_cmpuint (g_variant_get_size (normal_variant), <=, size * 2);
|
||||
+
|
||||
+ expected = g_variant_new_parsed (
|
||||
+ "[[[[[[['hi', '', ''], [], []], [], []], [], []], [], []], [], []], [], []]");
|
||||
+ g_assert_cmpvariant (expected, variant);
|
||||
+ g_assert_cmpvariant (expected, normal_variant);
|
||||
+
|
||||
+ g_variant_unref (expected);
|
||||
+ g_variant_unref (normal_variant);
|
||||
+ g_variant_unref (variant);
|
||||
+}
|
||||
+
|
||||
/* Test that a tuple with invalidly large values in its offset table is
|
||||
* normalised successfully without looping infinitely. */
|
||||
static void
|
||||
@@ -5206,6 +5249,8 @@ main (int argc, char **argv)
|
||||
test_normal_checking_tuples);
|
||||
g_test_add_func ("/gvariant/normal-checking/array-offsets",
|
||||
test_normal_checking_array_offsets);
|
||||
+ g_test_add_func ("/gvariant/normal-checking/array-offsets2",
|
||||
+ test_normal_checking_array_offsets2);
|
||||
g_test_add_func ("/gvariant/normal-checking/tuple-offsets",
|
||||
test_normal_checking_tuple_offsets);
|
||||
g_test_add_func ("/gvariant/normal-checking/empty-object-path",
|
||||
--
|
||||
2.24.4
|
||||
|
||||
113
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0004.patch
Normal file
113
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0004.patch
Normal file
@@ -0,0 +1,113 @@
|
||||
From 345cae9c1aa7bf6752039225ef4c8d8d69fa8d76 Sep 17 00:00:00 2001
|
||||
From: Philip Withnall <pwithnall@endlessos.org>
|
||||
Date: Fri, 11 Aug 2023 04:09:12 +0000
|
||||
Subject: [PATCH] gvariant-serialiser: Factor out code to get bounds of a tuple
|
||||
member
|
||||
|
||||
This introduces no functional changes.
|
||||
|
||||
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
||||
|
||||
Helps: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/345cae9c1aa7bf6752039225ef4c8d8d69fa8d76]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-serialiser.c | 73 ++++++++++++++++++++++++--------------
|
||||
1 file changed, 46 insertions(+), 27 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
|
||||
index fe0b1a4..6f9b366 100644
|
||||
--- a/glib/gvariant-serialiser.c
|
||||
+++ b/glib/gvariant-serialiser.c
|
||||
@@ -942,6 +942,51 @@ gvs_variable_sized_array_is_normal (GVariantSerialised value)
|
||||
* for the tuple. See the notes in gvarianttypeinfo.h.
|
||||
*/
|
||||
|
||||
+static void
|
||||
+gvs_tuple_get_member_bounds (GVariantSerialised value,
|
||||
+ gsize index_,
|
||||
+ gsize offset_size,
|
||||
+ gsize *out_member_start,
|
||||
+ gsize *out_member_end)
|
||||
+{
|
||||
+ const GVariantMemberInfo *member_info;
|
||||
+ gsize member_start, member_end;
|
||||
+
|
||||
+ member_info = g_variant_type_info_member_info (value.type_info, index_);
|
||||
+
|
||||
+ if (member_info->i + 1)
|
||||
+ member_start = gvs_read_unaligned_le (value.data + value.size -
|
||||
+ offset_size * (member_info->i + 1),
|
||||
+ offset_size);
|
||||
+ else
|
||||
+ member_start = 0;
|
||||
+
|
||||
+ member_start += member_info->a;
|
||||
+ member_start &= member_info->b;
|
||||
+ member_start |= member_info->c;
|
||||
+
|
||||
+ if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_LAST)
|
||||
+ member_end = value.size - offset_size * (member_info->i + 1);
|
||||
+
|
||||
+ else if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_FIXED)
|
||||
+ {
|
||||
+ gsize fixed_size;
|
||||
+
|
||||
+ g_variant_type_info_query (member_info->type_info, NULL, &fixed_size);
|
||||
+ member_end = member_start + fixed_size;
|
||||
+ }
|
||||
+
|
||||
+ else /* G_VARIANT_MEMBER_ENDING_OFFSET */
|
||||
+ member_end = gvs_read_unaligned_le (value.data + value.size -
|
||||
+ offset_size * (member_info->i + 2),
|
||||
+ offset_size);
|
||||
+
|
||||
+ if (out_member_start != NULL)
|
||||
+ *out_member_start = member_start;
|
||||
+ if (out_member_end != NULL)
|
||||
+ *out_member_end = member_end;
|
||||
+}
|
||||
+
|
||||
static gsize
|
||||
gvs_tuple_n_children (GVariantSerialised value)
|
||||
{
|
||||
@@ -997,33 +1042,7 @@ gvs_tuple_get_child (GVariantSerialised value,
|
||||
}
|
||||
}
|
||||
|
||||
- if (member_info->i + 1)
|
||||
- start = gvs_read_unaligned_le (value.data + value.size -
|
||||
- offset_size * (member_info->i + 1),
|
||||
- offset_size);
|
||||
- else
|
||||
- start = 0;
|
||||
-
|
||||
- start += member_info->a;
|
||||
- start &= member_info->b;
|
||||
- start |= member_info->c;
|
||||
-
|
||||
- if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_LAST)
|
||||
- end = value.size - offset_size * (member_info->i + 1);
|
||||
-
|
||||
- else if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_FIXED)
|
||||
- {
|
||||
- gsize fixed_size;
|
||||
-
|
||||
- g_variant_type_info_query (child.type_info, NULL, &fixed_size);
|
||||
- end = start + fixed_size;
|
||||
- child.size = fixed_size;
|
||||
- }
|
||||
-
|
||||
- else /* G_VARIANT_MEMBER_ENDING_OFFSET */
|
||||
- end = gvs_read_unaligned_le (value.data + value.size -
|
||||
- offset_size * (member_info->i + 2),
|
||||
- offset_size);
|
||||
+ gvs_tuple_get_member_bounds (value, index_, offset_size, &start, &end);
|
||||
|
||||
/* The child should not extend into the offset table. */
|
||||
if (index_ != g_variant_type_info_n_members (value.type_info) - 1)
|
||||
--
|
||||
2.24.4
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
From 73d0aa81c2575a5c9ae77dcb94da919579014fc0 Mon Sep 17 00:00:00 2001
|
||||
From: Philip Withnall <pwithnall@endlessos.org>
|
||||
Date: Fri, 11 Aug 2023 04:13:02 +0000
|
||||
Subject: [PATCH] gvariant-serialiser: Rework child size calculation
|
||||
|
||||
This reduces a few duplicate calls to `g_variant_type_info_query()` and
|
||||
explains why they’re needed.
|
||||
|
||||
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
||||
|
||||
Helps: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/73d0aa81c2575a5c9ae77dcb94da919579014fc0]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-serialiser.c | 31 +++++++++----------------------
|
||||
1 file changed, 9 insertions(+), 22 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
|
||||
index 6f9b366..fb75923 100644
|
||||
--- a/glib/gvariant-serialiser.c
|
||||
+++ b/glib/gvariant-serialiser.c
|
||||
@@ -1007,14 +1007,18 @@ gvs_tuple_get_child (GVariantSerialised value,
|
||||
child.depth = value.depth + 1;
|
||||
offset_size = gvs_get_offset_size (value.size);
|
||||
|
||||
+ /* Ensure the size is set for fixed-sized children, or
|
||||
+ * g_variant_serialised_check() will fail, even if we return
|
||||
+ * (child.data == NULL) to indicate an error. */
|
||||
+ if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_FIXED)
|
||||
+ g_variant_type_info_query (child.type_info, NULL, &child.size);
|
||||
+
|
||||
/* tuples are the only (potentially) fixed-sized containers, so the
|
||||
* only ones that have to deal with the possibility of having %NULL
|
||||
* data with a non-zero %size if errors occurred elsewhere.
|
||||
*/
|
||||
if G_UNLIKELY (value.data == NULL && value.size != 0)
|
||||
{
|
||||
- g_variant_type_info_query (child.type_info, NULL, &child.size);
|
||||
-
|
||||
/* this can only happen in fixed-sized tuples,
|
||||
* so the child must also be fixed sized.
|
||||
*/
|
||||
@@ -1032,29 +1036,12 @@ gvs_tuple_get_child (GVariantSerialised value,
|
||||
else
|
||||
{
|
||||
if (offset_size * (member_info->i + 1) > value.size)
|
||||
- {
|
||||
- /* if the child is fixed size, return its size.
|
||||
- * if child is not fixed-sized, return size = 0.
|
||||
- */
|
||||
- g_variant_type_info_query (child.type_info, NULL, &child.size);
|
||||
-
|
||||
- return child;
|
||||
- }
|
||||
+ return child;
|
||||
}
|
||||
|
||||
- gvs_tuple_get_member_bounds (value, index_, offset_size, &start, &end);
|
||||
-
|
||||
/* The child should not extend into the offset table. */
|
||||
- if (index_ != g_variant_type_info_n_members (value.type_info) - 1)
|
||||
- {
|
||||
- GVariantSerialised last_child;
|
||||
- last_child = gvs_tuple_get_child (value,
|
||||
- g_variant_type_info_n_members (value.type_info) - 1);
|
||||
- last_end = last_child.data + last_child.size - value.data;
|
||||
- g_variant_type_info_unref (last_child.type_info);
|
||||
- }
|
||||
- else
|
||||
- last_end = end;
|
||||
+ gvs_tuple_get_member_bounds (value, index_, offset_size, &start, &end);
|
||||
+ gvs_tuple_get_member_bounds (value, g_variant_type_info_n_members (value.type_info) - 1, offset_size, NULL, &last_end);
|
||||
|
||||
if (start < end && end <= value.size && end <= last_end)
|
||||
{
|
||||
--
|
||||
2.24.4
|
||||
|
||||
396
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0006.patch
Normal file
396
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0006.patch
Normal file
@@ -0,0 +1,396 @@
|
||||
From 7cf6f5b69146d20948d42f0c476688fe17fef787 Mon Sep 17 00:00:00 2001
|
||||
From: Philip Withnall <pwithnall@endlessos.org>
|
||||
Date: Wed, 16 Aug 2023 12:09:06 +0000
|
||||
Subject: [PATCH] gvariant: Don't allow child elements of a tuple to overlap
|
||||
each other
|
||||
|
||||
This is similar to the earlier commit which prevents child elements of a
|
||||
variable-sized array from overlapping each other, but this time for
|
||||
tuples. It is based heavily on ideas by William Manley.
|
||||
|
||||
Tuples are slightly different from variable-sized arrays in that they
|
||||
contain a mixture of fixed and variable sized elements. All but one of
|
||||
the variable sized elements have an entry in the frame offsets table.
|
||||
This means that if we were to just check the ordering of the frame
|
||||
offsets table, the variable sized elements could still overlap
|
||||
interleaving fixed sized elements, which would be bad.
|
||||
|
||||
Therefore we have to check the elements rather than the frame offsets.
|
||||
|
||||
The logic of checking the elements up to the index currently being
|
||||
requested, and caching the result in `ordered_offsets_up_to`, means that
|
||||
the algorithmic cost implications are the same for this commit as for
|
||||
variable-sized arrays: an O(N) cost for these checks is amortised out
|
||||
over N accesses to O(1) per access.
|
||||
|
||||
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
||||
|
||||
Fixes: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/7cf6f5b69146d20948d42f0c476688fe17fef787]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-core.c | 6 +-
|
||||
glib/gvariant-serialiser.c | 40 ++++++++
|
||||
glib/gvariant-serialiser.h | 7 +-
|
||||
glib/gvariant.c | 1 +
|
||||
glib/tests/gvariant.c | 181 +++++++++++++++++++++++++++++++++++++
|
||||
5 files changed, 232 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
|
||||
index 9b51e15..b951cd9 100644
|
||||
--- a/glib/gvariant-core.c
|
||||
+++ b/glib/gvariant-core.c
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright © 2007, 2008 Ryan Lortie
|
||||
* Copyright © 2010 Codethink Limited
|
||||
+ * Copyright © 2022 Endless OS Foundation, LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -179,7 +180,7 @@ struct _GVariant
|
||||
* offsets themselves.
|
||||
*
|
||||
* This field is only relevant for arrays of non
|
||||
- * fixed width types.
|
||||
+ * fixed width types and for tuples.
|
||||
*
|
||||
* .tree: Only valid when the instance is in tree form.
|
||||
*
|
||||
@@ -1117,6 +1118,9 @@ g_variant_get_child_value (GVariant *value,
|
||||
*/
|
||||
s_child = g_variant_serialised_get_child (serialised, index_);
|
||||
|
||||
+ /* Update the cached ordered_offsets_up_to, since @serialised will be thrown away when this function exits */
|
||||
+ value->contents.serialised.ordered_offsets_up_to = MAX (value->contents.serialised.ordered_offsets_up_to, serialised.ordered_offsets_up_to);
|
||||
+
|
||||
/* Check whether this would cause nesting too deep. If so, return a fake
|
||||
* child. The only situation we expect this to happen in is with a variant,
|
||||
* as all other deeply-nested types have a static type, and hence should
|
||||
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
|
||||
index fb75923..cd4a3e6 100644
|
||||
--- a/glib/gvariant-serialiser.c
|
||||
+++ b/glib/gvariant-serialiser.c
|
||||
@@ -942,6 +942,10 @@ gvs_variable_sized_array_is_normal (GVariantSerialised value)
|
||||
* for the tuple. See the notes in gvarianttypeinfo.h.
|
||||
*/
|
||||
|
||||
+/* Note: This doesn’t guarantee that @out_member_end >= @out_member_start; that
|
||||
+ * condition may not hold true for invalid serialised variants. The caller is
|
||||
+ * responsible for checking the returned values and handling invalid ones
|
||||
+ * appropriately. */
|
||||
static void
|
||||
gvs_tuple_get_member_bounds (GVariantSerialised value,
|
||||
gsize index_,
|
||||
@@ -1028,6 +1032,42 @@ gvs_tuple_get_child (GVariantSerialised value,
|
||||
return child;
|
||||
}
|
||||
|
||||
+ /* If the requested @index_ is beyond the set of indices whose framing offsets
|
||||
+ * have been checked, check the remaining offsets to see whether they’re
|
||||
+ * normal (in order, no overlapping tuple elements).
|
||||
+ *
|
||||
+ * Unlike the checks in gvs_variable_sized_array_get_child(), we have to check
|
||||
+ * all the tuple *elements* here, not just all the framing offsets, since
|
||||
+ * tuples contain a mix of elements which use framing offsets and ones which
|
||||
+ * don’t. None of them are allowed to overlap. */
|
||||
+ if (index_ > value.ordered_offsets_up_to)
|
||||
+ {
|
||||
+ gsize i, prev_i_end = 0;
|
||||
+
|
||||
+ if (value.ordered_offsets_up_to > 0)
|
||||
+ gvs_tuple_get_member_bounds (value, value.ordered_offsets_up_to - 1, offset_size, NULL, &prev_i_end);
|
||||
+
|
||||
+ for (i = value.ordered_offsets_up_to; i <= index_; i++)
|
||||
+ {
|
||||
+ gsize i_start, i_end;
|
||||
+
|
||||
+ gvs_tuple_get_member_bounds (value, i, offset_size, &i_start, &i_end);
|
||||
+
|
||||
+ if (i_start > i_end || i_start < prev_i_end || i_end > value.size)
|
||||
+ break;
|
||||
+
|
||||
+ prev_i_end = i_end;
|
||||
+ }
|
||||
+
|
||||
+ value.ordered_offsets_up_to = i - 1;
|
||||
+ }
|
||||
+
|
||||
+ if (index_ > value.ordered_offsets_up_to)
|
||||
+ {
|
||||
+ /* Offsets are invalid somewhere, so return an empty child. */
|
||||
+ return child;
|
||||
+ }
|
||||
+
|
||||
if (member_info->ending_type == G_VARIANT_MEMBER_ENDING_OFFSET)
|
||||
{
|
||||
if (offset_size * (member_info->i + 2) > value.size)
|
||||
diff --git a/glib/gvariant-serialiser.h b/glib/gvariant-serialiser.h
|
||||
index 99d18ef..144aec8 100644
|
||||
--- a/glib/gvariant-serialiser.h
|
||||
+++ b/glib/gvariant-serialiser.h
|
||||
@@ -34,8 +34,11 @@ typedef struct
|
||||
* This guarantees that the bytes of element n don't overlap with any previous
|
||||
* element.
|
||||
*
|
||||
- * This is both read and set by g_variant_serialised_get_child for arrays of
|
||||
- * non-fixed-width types */
|
||||
+ * This is both read and set by g_variant_serialised_get_child() for arrays of
|
||||
+ * non-fixed-width types, and for tuples.
|
||||
+ *
|
||||
+ * Even when dealing with tuples, @ordered_offsets_up_to is an element index,
|
||||
+ * rather than an index into the frame offsets. */
|
||||
gsize ordered_offsets_up_to;
|
||||
} GVariantSerialised;
|
||||
|
||||
diff --git a/glib/gvariant.c b/glib/gvariant.c
|
||||
index d6f68a9..cdb428e 100644
|
||||
--- a/glib/gvariant.c
|
||||
+++ b/glib/gvariant.c
|
||||
@@ -5945,6 +5945,7 @@ g_variant_byteswap (GVariant *value)
|
||||
serialised.type_info = g_variant_get_type_info (trusted);
|
||||
serialised.size = g_variant_get_size (trusted);
|
||||
serialised.data = g_malloc (serialised.size);
|
||||
+ serialised.ordered_offsets_up_to = G_MAXSIZE; /* operating on the normal form */
|
||||
g_variant_store (trusted, serialised.data);
|
||||
g_variant_unref (trusted);
|
||||
|
||||
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
|
||||
index 967e9a1..a84b02e 100644
|
||||
--- a/glib/tests/gvariant.c
|
||||
+++ b/glib/tests/gvariant.c
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright © 2010 Codethink Limited
|
||||
* Copyright © 2020 William Manley
|
||||
+ * Copyright © 2022 Endless OS Foundation, LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -1451,6 +1452,7 @@ test_maybe (void)
|
||||
serialised.data = flavoured_malloc (needed_size, flavour);
|
||||
serialised.size = needed_size;
|
||||
serialised.depth = 0;
|
||||
+ serialised.ordered_offsets_up_to = 0;
|
||||
|
||||
g_variant_serialiser_serialise (serialised,
|
||||
random_instance_filler,
|
||||
@@ -1574,6 +1576,7 @@ test_array (void)
|
||||
serialised.data = flavoured_malloc (needed_size, flavour);
|
||||
serialised.size = needed_size;
|
||||
serialised.depth = 0;
|
||||
+ serialised.ordered_offsets_up_to = 0;
|
||||
|
||||
g_variant_serialiser_serialise (serialised, random_instance_filler,
|
||||
(gpointer *) instances, n_children);
|
||||
@@ -1738,6 +1741,7 @@ test_tuple (void)
|
||||
serialised.data = flavoured_malloc (needed_size, flavour);
|
||||
serialised.size = needed_size;
|
||||
serialised.depth = 0;
|
||||
+ serialised.ordered_offsets_up_to = 0;
|
||||
|
||||
g_variant_serialiser_serialise (serialised, random_instance_filler,
|
||||
(gpointer *) instances, n_children);
|
||||
@@ -1834,6 +1838,7 @@ test_variant (void)
|
||||
serialised.data = flavoured_malloc (needed_size, flavour);
|
||||
serialised.size = needed_size;
|
||||
serialised.depth = 0;
|
||||
+ serialised.ordered_offsets_up_to = 0;
|
||||
|
||||
g_variant_serialiser_serialise (serialised, random_instance_filler,
|
||||
(gpointer *) &instance, 1);
|
||||
@@ -5106,6 +5111,176 @@ test_normal_checking_tuple_offsets (void)
|
||||
g_variant_unref (variant);
|
||||
}
|
||||
|
||||
+/* This is a regression test that we can't have non-normal values that take up
|
||||
+ * significantly more space than the normal equivalent, by specifying the
|
||||
+ * offset table entries so that tuple elements overlap.
|
||||
+ *
|
||||
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/2121#note_838503 and
|
||||
+ * https://gitlab.gnome.org/GNOME/glib/-/issues/2121#note_838513 */
|
||||
+static void
|
||||
+test_normal_checking_tuple_offsets2 (void)
|
||||
+{
|
||||
+ const GVariantType *data_type = G_VARIANT_TYPE ("(yyaiyyaiyy)");
|
||||
+ const guint8 data[] = {
|
||||
+ 0x12, 0x34, 0x56, 0x78, 0x01,
|
||||
+ /*
|
||||
+ ^───────────────────┘
|
||||
+
|
||||
+ ^^^^^^^^^^ 1st yy
|
||||
+ ^^^^^^^^^^ 2nd yy
|
||||
+ ^^^^^^^^^^ 3rd yy
|
||||
+ ^^^^ Framing offsets
|
||||
+ */
|
||||
+
|
||||
+ /* If this variant was encoded normally, it would be something like this:
|
||||
+ * 0x12, 0x34, pad, pad, [array bytes], 0x56, 0x78, pad, pad, [array bytes], 0x9A, 0xBC, 0xXX
|
||||
+ * ^─────────────────────────────────────────────────────┘
|
||||
+ *
|
||||
+ * ^^^^^^^^^^ 1st yy
|
||||
+ * ^^^^^^^^^^ 2nd yy
|
||||
+ * ^^^^^^^^^^ 3rd yy
|
||||
+ * ^^^^ Framing offsets
|
||||
+ */
|
||||
+ };
|
||||
+ gsize size = sizeof (data);
|
||||
+ GVariant *variant = NULL;
|
||||
+ GVariant *normal_variant = NULL;
|
||||
+ GVariant *expected = NULL;
|
||||
+
|
||||
+ variant = g_variant_new_from_data (data_type, data, size, FALSE, NULL, NULL);
|
||||
+ g_assert_nonnull (variant);
|
||||
+
|
||||
+ normal_variant = g_variant_get_normal_form (variant);
|
||||
+ g_assert_nonnull (normal_variant);
|
||||
+ g_assert_cmpuint (g_variant_get_size (normal_variant), <=, size * 3);
|
||||
+
|
||||
+ expected = g_variant_new_parsed (
|
||||
+ "@(yyaiyyaiyy) (0x12, 0x34, [], 0x00, 0x00, [], 0x00, 0x00)");
|
||||
+ g_assert_cmpvariant (expected, variant);
|
||||
+ g_assert_cmpvariant (expected, normal_variant);
|
||||
+
|
||||
+ g_variant_unref (expected);
|
||||
+ g_variant_unref (normal_variant);
|
||||
+ g_variant_unref (variant);
|
||||
+}
|
||||
+
|
||||
+/* This is a regression test that overlapping entries in the offset table are
|
||||
+ * decoded consistently, even though they’re non-normal.
|
||||
+ *
|
||||
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/2121#note_910935 */
|
||||
+static void
|
||||
+test_normal_checking_tuple_offsets3 (void)
|
||||
+{
|
||||
+ /* The expected decoding of this non-normal byte stream is complex. See
|
||||
+ * section 2.7.3 (Handling Non-Normal Serialised Data) of the GVariant
|
||||
+ * specification.
|
||||
+ *
|
||||
+ * The rule “Child Values Overlapping Framing Offsets” from the specification
|
||||
+ * says that the first `ay` must be decoded as `[0x01]` even though it
|
||||
+ * overlaps the first byte of the offset table. However, since commit
|
||||
+ * 7eedcd76f7d5b8c98fa60013e1fe6e960bf19df3, GLib explicitly doesn’t allow
|
||||
+ * this as it’s exploitable. So the first `ay` must be given a default value.
|
||||
+ *
|
||||
+ * The second and third `ay`s must be given default values because of rule
|
||||
+ * “End Boundary Precedes Start Boundary”.
|
||||
+ *
|
||||
+ * The `i` must be given a default value because of rule “Start or End
|
||||
+ * Boundary of a Child Falls Outside the Container”.
|
||||
+ */
|
||||
+ const GVariantType *data_type = G_VARIANT_TYPE ("(ayayiay)");
|
||||
+ const guint8 data[] = {
|
||||
+ 0x01, 0x00, 0x02,
|
||||
+ /*
|
||||
+ ^──┘
|
||||
+
|
||||
+ ^^^^^^^^^^ 1st ay, bytes 0-2 (but given a default value anyway, see above)
|
||||
+ 2nd ay, bytes 2-0
|
||||
+ i, bytes 0-4
|
||||
+ 3rd ay, bytes 4-1
|
||||
+ ^^^^^^^^^^ Framing offsets
|
||||
+ */
|
||||
+ };
|
||||
+ gsize size = sizeof (data);
|
||||
+ GVariant *variant = NULL;
|
||||
+ GVariant *normal_variant = NULL;
|
||||
+ GVariant *expected = NULL;
|
||||
+
|
||||
+ variant = g_variant_new_from_data (data_type, data, size, FALSE, NULL, NULL);
|
||||
+ g_assert_nonnull (variant);
|
||||
+
|
||||
+ g_assert_false (g_variant_is_normal_form (variant));
|
||||
+
|
||||
+ normal_variant = g_variant_get_normal_form (variant);
|
||||
+ g_assert_nonnull (normal_variant);
|
||||
+ g_assert_cmpuint (g_variant_get_size (normal_variant), <=, size * 3);
|
||||
+
|
||||
+ expected = g_variant_new_parsed ("@(ayayiay) ([], [], 0, [])");
|
||||
+ g_assert_cmpvariant (expected, variant);
|
||||
+ g_assert_cmpvariant (expected, normal_variant);
|
||||
+
|
||||
+ g_variant_unref (expected);
|
||||
+ g_variant_unref (normal_variant);
|
||||
+ g_variant_unref (variant);
|
||||
+}
|
||||
+
|
||||
+/* This is a regression test that overlapping entries in the offset table are
|
||||
+ * decoded consistently, even though they’re non-normal.
|
||||
+ *
|
||||
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/2121#note_910935 */
|
||||
+static void
|
||||
+test_normal_checking_tuple_offsets4 (void)
|
||||
+{
|
||||
+ /* The expected decoding of this non-normal byte stream is complex. See
|
||||
+ * section 2.7.3 (Handling Non-Normal Serialised Data) of the GVariant
|
||||
+ * specification.
|
||||
+ *
|
||||
+ * The rule “Child Values Overlapping Framing Offsets” from the specification
|
||||
+ * says that the first `ay` must be decoded as `[0x01]` even though it
|
||||
+ * overlaps the first byte of the offset table. However, since commit
|
||||
+ * 7eedcd76f7d5b8c98fa60013e1fe6e960bf19df3, GLib explicitly doesn’t allow
|
||||
+ * this as it’s exploitable. So the first `ay` must be given a default value.
|
||||
+ *
|
||||
+ * The second `ay` must be given a default value because of rule “End Boundary
|
||||
+ * Precedes Start Boundary”.
|
||||
+ *
|
||||
+ * The third `ay` must be given a default value because its framing offsets
|
||||
+ * overlap that of the first `ay`.
|
||||
+ */
|
||||
+ const GVariantType *data_type = G_VARIANT_TYPE ("(ayayay)");
|
||||
+ const guint8 data[] = {
|
||||
+ 0x01, 0x00, 0x02,
|
||||
+ /*
|
||||
+ ^──┘
|
||||
+
|
||||
+ ^^^^^^^^^^ 1st ay, bytes 0-2 (but given a default value anyway, see above)
|
||||
+ 2nd ay, bytes 2-0
|
||||
+ 3rd ay, bytes 0-1
|
||||
+ ^^^^^^^^^^ Framing offsets
|
||||
+ */
|
||||
+ };
|
||||
+ gsize size = sizeof (data);
|
||||
+ GVariant *variant = NULL;
|
||||
+ GVariant *normal_variant = NULL;
|
||||
+ GVariant *expected = NULL;
|
||||
+
|
||||
+ variant = g_variant_new_from_data (data_type, data, size, FALSE, NULL, NULL);
|
||||
+ g_assert_nonnull (variant);
|
||||
+
|
||||
+ g_assert_false (g_variant_is_normal_form (variant));
|
||||
+
|
||||
+ normal_variant = g_variant_get_normal_form (variant);
|
||||
+ g_assert_nonnull (normal_variant);
|
||||
+ g_assert_cmpuint (g_variant_get_size (normal_variant), <=, size * 3);
|
||||
+
|
||||
+ expected = g_variant_new_parsed ("@(ayayay) ([], [], [])");
|
||||
+ g_assert_cmpvariant (expected, variant);
|
||||
+ g_assert_cmpvariant (expected, normal_variant);
|
||||
+
|
||||
+ g_variant_unref (expected);
|
||||
+ g_variant_unref (normal_variant);
|
||||
+ g_variant_unref (variant);
|
||||
+}
|
||||
+
|
||||
/* Test that an empty object path is normalised successfully to the base object
|
||||
* path, ‘/’. */
|
||||
static void
|
||||
@@ -5253,6 +5428,12 @@ main (int argc, char **argv)
|
||||
test_normal_checking_array_offsets2);
|
||||
g_test_add_func ("/gvariant/normal-checking/tuple-offsets",
|
||||
test_normal_checking_tuple_offsets);
|
||||
+ g_test_add_func ("/gvariant/normal-checking/tuple-offsets2",
|
||||
+ test_normal_checking_tuple_offsets2);
|
||||
+ g_test_add_func ("/gvariant/normal-checking/tuple-offsets3",
|
||||
+ test_normal_checking_tuple_offsets3);
|
||||
+ g_test_add_func ("/gvariant/normal-checking/tuple-offsets4",
|
||||
+ test_normal_checking_tuple_offsets4);
|
||||
g_test_add_func ("/gvariant/normal-checking/empty-object-path",
|
||||
test_normal_checking_empty_object_path);
|
||||
|
||||
--
|
||||
2.24.4
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
From e6490c84e84ba9f182fbd83b51ff4f9f5a0a1793 Mon Sep 17 00:00:00 2001
|
||||
From: Philip Withnall <pwithnall@endlessos.org>
|
||||
Date: Wed, 16 Aug 2023 03:42:47 +0000
|
||||
Subject: [PATCH] gvariant: Port g_variant_deep_copy() to count its iterations
|
||||
directly
|
||||
|
||||
This is equivalent to what `GVariantIter` does, but it means that
|
||||
`g_variant_deep_copy()` is making its own `g_variant_get_child_value()`
|
||||
calls.
|
||||
|
||||
This will be useful in an upcoming commit, where those child values will
|
||||
be inspected a little more deeply.
|
||||
|
||||
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
||||
|
||||
Helps: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/e6490c84e84ba9f182fbd83b51ff4f9f5a0a1793]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant.c | 7 +++----
|
||||
1 file changed, 3 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant.c b/glib/gvariant.c
|
||||
index cdb428e..fdd36be 100644
|
||||
--- a/glib/gvariant.c
|
||||
+++ b/glib/gvariant.c
|
||||
@@ -5799,14 +5799,13 @@ g_variant_deep_copy (GVariant *value)
|
||||
case G_VARIANT_CLASS_VARIANT:
|
||||
{
|
||||
GVariantBuilder builder;
|
||||
- GVariantIter iter;
|
||||
- GVariant *child;
|
||||
+ gsize i, n_children;
|
||||
|
||||
g_variant_builder_init (&builder, g_variant_get_type (value));
|
||||
- g_variant_iter_init (&iter, value);
|
||||
|
||||
- while ((child = g_variant_iter_next_value (&iter)))
|
||||
+ for (i = 0, n_children = g_variant_n_children (value); i < n_children; i++)
|
||||
{
|
||||
+ GVariant *child = g_variant_get_child_value (value, i);
|
||||
g_variant_builder_add_value (&builder, g_variant_deep_copy (child));
|
||||
g_variant_unref (child);
|
||||
}
|
||||
--
|
||||
2.24.4
|
||||
|
||||
394
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0008.patch
Normal file
394
meta/recipes-core/glib-2.0/glib-2.0/CVE-2023-32665-0008.patch
Normal file
@@ -0,0 +1,394 @@
|
||||
From d1a293c4e29880b8d17bb826c9a426a440ca4a91 Mon Sep 17 00:00:00 2001
|
||||
From: Philip Withnall <pwithnall@endlessos.org>
|
||||
Date: Thu, 17 Aug 2023 01:30:38 +0000
|
||||
Subject: [PATCH] gvariant: Track checked and ordered offsets independently
|
||||
|
||||
The past few commits introduced the concept of known-good offsets in the
|
||||
offset table (which is used for variable-width arrays and tuples).
|
||||
Good offsets are ones which are non-overlapping with all the previous
|
||||
offsets in the table.
|
||||
|
||||
If a bad offset is encountered when indexing into the array or tuple,
|
||||
the cached known-good offset index will not be increased. In this way,
|
||||
all child variants at and beyond the first bad offset can be returned as
|
||||
default values rather than dereferencing potentially invalid data.
|
||||
|
||||
In this case, there was no information about the fact that the indexes
|
||||
between the highest known-good index and the requested one had been
|
||||
checked already. That could lead to a pathological case where an offset
|
||||
table with an invalid first offset is repeatedly checked in full when
|
||||
trying to access higher-indexed children.
|
||||
|
||||
Avoid that by storing the index of the highest checked offset in the
|
||||
table, as well as the index of the highest good/ordered offset.
|
||||
|
||||
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
||||
|
||||
Helps: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/d1a293c4e29880b8d17bb826c9a426a440ca4a91]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant-core.c | 28 ++++++++++++++++++++++++
|
||||
glib/gvariant-serialiser.c | 44 +++++++++++++++++++++++++++-----------
|
||||
glib/gvariant-serialiser.h | 9 ++++++++
|
||||
glib/gvariant.c | 1 +
|
||||
glib/tests/gvariant.c | 5 +++++
|
||||
5 files changed, 75 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
|
||||
index b951cd9..1b9d5cc 100644
|
||||
--- a/glib/gvariant-core.c
|
||||
+++ b/glib/gvariant-core.c
|
||||
@@ -67,6 +67,7 @@ struct _GVariant
|
||||
GBytes *bytes;
|
||||
gconstpointer data;
|
||||
gsize ordered_offsets_up_to;
|
||||
+ gsize checked_offsets_up_to;
|
||||
} serialised;
|
||||
|
||||
struct
|
||||
@@ -182,6 +183,24 @@ struct _GVariant
|
||||
* This field is only relevant for arrays of non
|
||||
* fixed width types and for tuples.
|
||||
*
|
||||
+ * .checked_offsets_up_to: Similarly to .ordered_offsets_up_to, this stores
|
||||
+ * the index of the highest element, n, whose frame
|
||||
+ * offsets (and all the preceding frame offsets)
|
||||
+ * have been checked for validity.
|
||||
+ *
|
||||
+ * It is always the case that
|
||||
+ * .checked_offsets_up_to ≥ .ordered_offsets_up_to.
|
||||
+ *
|
||||
+ * If .checked_offsets_up_to == .ordered_offsets_up_to,
|
||||
+ * then a bad offset has not been found so far.
|
||||
+ *
|
||||
+ * If .checked_offsets_up_to > .ordered_offsets_up_to,
|
||||
+ * then a bad offset has been found at
|
||||
+ * (.ordered_offsets_up_to + 1).
|
||||
+ *
|
||||
+ * This field is only relevant for arrays of non
|
||||
+ * fixed width types and for tuples.
|
||||
+ *
|
||||
* .tree: Only valid when the instance is in tree form.
|
||||
*
|
||||
* Note that accesses from other threads could result in
|
||||
@@ -386,6 +405,7 @@ g_variant_to_serialised (GVariant *value)
|
||||
value->size,
|
||||
value->depth,
|
||||
value->contents.serialised.ordered_offsets_up_to,
|
||||
+ value->contents.serialised.checked_offsets_up_to,
|
||||
};
|
||||
return serialised;
|
||||
}
|
||||
@@ -418,6 +438,7 @@ g_variant_serialise (GVariant *value,
|
||||
serialised.data = data;
|
||||
serialised.depth = value->depth;
|
||||
serialised.ordered_offsets_up_to = 0;
|
||||
+ serialised.checked_offsets_up_to = 0;
|
||||
|
||||
children = (gpointer *) value->contents.tree.children;
|
||||
n_children = value->contents.tree.n_children;
|
||||
@@ -464,10 +485,12 @@ g_variant_fill_gvs (GVariantSerialised *serialised,
|
||||
if (value->state & STATE_SERIALISED)
|
||||
{
|
||||
serialised->ordered_offsets_up_to = value->contents.serialised.ordered_offsets_up_to;
|
||||
+ serialised->checked_offsets_up_to = value->contents.serialised.checked_offsets_up_to;
|
||||
}
|
||||
else
|
||||
{
|
||||
serialised->ordered_offsets_up_to = 0;
|
||||
+ serialised->checked_offsets_up_to = 0;
|
||||
}
|
||||
|
||||
if (serialised->data)
|
||||
@@ -513,6 +536,7 @@ g_variant_ensure_serialised (GVariant *value)
|
||||
value->contents.serialised.data = g_bytes_get_data (bytes, NULL);
|
||||
value->contents.serialised.bytes = bytes;
|
||||
value->contents.serialised.ordered_offsets_up_to = G_MAXSIZE;
|
||||
+ value->contents.serialised.checked_offsets_up_to = G_MAXSIZE;
|
||||
value->state |= STATE_SERIALISED;
|
||||
}
|
||||
}
|
||||
@@ -594,6 +618,7 @@ g_variant_new_from_bytes (const GVariantType *type,
|
||||
serialised.data = (guchar *) g_bytes_get_data (bytes, &serialised.size);
|
||||
serialised.depth = 0;
|
||||
serialised.ordered_offsets_up_to = trusted ? G_MAXSIZE : 0;
|
||||
+ serialised.checked_offsets_up_to = trusted ? G_MAXSIZE : 0;
|
||||
|
||||
if (!g_variant_serialised_check (serialised))
|
||||
{
|
||||
@@ -644,6 +669,7 @@ g_variant_new_from_bytes (const GVariantType *type,
|
||||
}
|
||||
|
||||
value->contents.serialised.ordered_offsets_up_to = trusted ? G_MAXSIZE : 0;
|
||||
+ value->contents.serialised.checked_offsets_up_to = trusted ? G_MAXSIZE : 0;
|
||||
|
||||
g_clear_pointer (&owned_bytes, g_bytes_unref);
|
||||
|
||||
@@ -1120,6 +1146,7 @@ g_variant_get_child_value (GVariant *value,
|
||||
|
||||
/* Update the cached ordered_offsets_up_to, since @serialised will be thrown away when this function exits */
|
||||
value->contents.serialised.ordered_offsets_up_to = MAX (value->contents.serialised.ordered_offsets_up_to, serialised.ordered_offsets_up_to);
|
||||
+ value->contents.serialised.checked_offsets_up_to = MAX (value->contents.serialised.checked_offsets_up_to, serialised.checked_offsets_up_to);
|
||||
|
||||
/* Check whether this would cause nesting too deep. If so, return a fake
|
||||
* child. The only situation we expect this to happen in is with a variant,
|
||||
@@ -1147,6 +1174,7 @@ g_variant_get_child_value (GVariant *value,
|
||||
g_bytes_ref (value->contents.serialised.bytes);
|
||||
child->contents.serialised.data = s_child.data;
|
||||
child->contents.serialised.ordered_offsets_up_to = s_child.ordered_offsets_up_to;
|
||||
+ child->contents.serialised.checked_offsets_up_to = s_child.checked_offsets_up_to;
|
||||
|
||||
return child;
|
||||
}
|
||||
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
|
||||
index cd4a3e6..0bf7243 100644
|
||||
--- a/glib/gvariant-serialiser.c
|
||||
+++ b/glib/gvariant-serialiser.c
|
||||
@@ -120,6 +120,8 @@
|
||||
*
|
||||
* @depth has no restrictions; the depth of a top-level serialised #GVariant is
|
||||
* zero, and it increases for each level of nested child.
|
||||
+ *
|
||||
+ * @checked_offsets_up_to is always ≥ @ordered_offsets_up_to
|
||||
*/
|
||||
|
||||
/* < private >
|
||||
@@ -147,6 +149,9 @@ g_variant_serialised_check (GVariantSerialised serialised)
|
||||
!(serialised.size == 0 || serialised.data != NULL))
|
||||
return FALSE;
|
||||
|
||||
+ if (serialised.ordered_offsets_up_to > serialised.checked_offsets_up_to)
|
||||
+ return FALSE;
|
||||
+
|
||||
/* Depending on the native alignment requirements of the machine, the
|
||||
* compiler will insert either 3 or 7 padding bytes after the char.
|
||||
* This will result in the sizeof() the struct being 12 or 16.
|
||||
@@ -266,6 +271,7 @@ gvs_fixed_sized_maybe_get_child (GVariantSerialised value,
|
||||
g_variant_type_info_ref (value.type_info);
|
||||
value.depth++;
|
||||
value.ordered_offsets_up_to = 0;
|
||||
+ value.checked_offsets_up_to = 0;
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -297,7 +303,7 @@ gvs_fixed_sized_maybe_serialise (GVariantSerialised value,
|
||||
{
|
||||
if (n_children)
|
||||
{
|
||||
- GVariantSerialised child = { NULL, value.data, value.size, value.depth + 1, 0 };
|
||||
+ GVariantSerialised child = { NULL, value.data, value.size, value.depth + 1, 0, 0 };
|
||||
|
||||
gvs_filler (&child, children[0]);
|
||||
}
|
||||
@@ -320,6 +326,7 @@ gvs_fixed_sized_maybe_is_normal (GVariantSerialised value)
|
||||
value.type_info = g_variant_type_info_element (value.type_info);
|
||||
value.depth++;
|
||||
value.ordered_offsets_up_to = 0;
|
||||
+ value.checked_offsets_up_to = 0;
|
||||
|
||||
return g_variant_serialised_is_normal (value);
|
||||
}
|
||||
@@ -362,6 +369,7 @@ gvs_variable_sized_maybe_get_child (GVariantSerialised value,
|
||||
|
||||
value.depth++;
|
||||
value.ordered_offsets_up_to = 0;
|
||||
+ value.checked_offsets_up_to = 0;
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -392,7 +400,7 @@ gvs_variable_sized_maybe_serialise (GVariantSerialised value,
|
||||
{
|
||||
if (n_children)
|
||||
{
|
||||
- GVariantSerialised child = { NULL, value.data, value.size - 1, value.depth + 1, 0 };
|
||||
+ GVariantSerialised child = { NULL, value.data, value.size - 1, value.depth + 1, 0, 0 };
|
||||
|
||||
/* write the data for the child. */
|
||||
gvs_filler (&child, children[0]);
|
||||
@@ -413,6 +421,7 @@ gvs_variable_sized_maybe_is_normal (GVariantSerialised value)
|
||||
value.size--;
|
||||
value.depth++;
|
||||
value.ordered_offsets_up_to = 0;
|
||||
+ value.checked_offsets_up_to = 0;
|
||||
|
||||
return g_variant_serialised_is_normal (value);
|
||||
}
|
||||
@@ -739,39 +748,46 @@ gvs_variable_sized_array_get_child (GVariantSerialised value,
|
||||
|
||||
/* If the requested @index_ is beyond the set of indices whose framing offsets
|
||||
* have been checked, check the remaining offsets to see whether they’re
|
||||
- * normal (in order, no overlapping array elements). */
|
||||
- if (index_ > value.ordered_offsets_up_to)
|
||||
+ * normal (in order, no overlapping array elements).
|
||||
+ *
|
||||
+ * Don’t bother checking if the highest known-good offset is lower than the
|
||||
+ * highest checked offset, as that means there’s an invalid element at that
|
||||
+ * index, so there’s no need to check further. */
|
||||
+ if (index_ > value.checked_offsets_up_to &&
|
||||
+ value.ordered_offsets_up_to == value.checked_offsets_up_to)
|
||||
{
|
||||
switch (offsets.offset_size)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
value.ordered_offsets_up_to = find_unordered_guint8 (
|
||||
- offsets.array, value.ordered_offsets_up_to, index_ + 1);
|
||||
+ offsets.array, value.checked_offsets_up_to, index_ + 1);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
value.ordered_offsets_up_to = find_unordered_guint16 (
|
||||
- offsets.array, value.ordered_offsets_up_to, index_ + 1);
|
||||
+ offsets.array, value.checked_offsets_up_to, index_ + 1);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
value.ordered_offsets_up_to = find_unordered_guint32 (
|
||||
- offsets.array, value.ordered_offsets_up_to, index_ + 1);
|
||||
+ offsets.array, value.checked_offsets_up_to, index_ + 1);
|
||||
break;
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
value.ordered_offsets_up_to = find_unordered_guint64 (
|
||||
- offsets.array, value.ordered_offsets_up_to, index_ + 1);
|
||||
+ offsets.array, value.checked_offsets_up_to, index_ + 1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* gvs_get_offset_size() only returns maximum 8 */
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
+
|
||||
+ value.checked_offsets_up_to = index_;
|
||||
}
|
||||
|
||||
if (index_ > value.ordered_offsets_up_to)
|
||||
@@ -916,6 +932,7 @@ gvs_variable_sized_array_is_normal (GVariantSerialised value)
|
||||
|
||||
/* All offsets have now been checked. */
|
||||
value.ordered_offsets_up_to = G_MAXSIZE;
|
||||
+ value.checked_offsets_up_to = G_MAXSIZE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1040,14 +1057,15 @@ gvs_tuple_get_child (GVariantSerialised value,
|
||||
* all the tuple *elements* here, not just all the framing offsets, since
|
||||
* tuples contain a mix of elements which use framing offsets and ones which
|
||||
* don’t. None of them are allowed to overlap. */
|
||||
- if (index_ > value.ordered_offsets_up_to)
|
||||
+ if (index_ > value.checked_offsets_up_to &&
|
||||
+ value.ordered_offsets_up_to == value.checked_offsets_up_to)
|
||||
{
|
||||
gsize i, prev_i_end = 0;
|
||||
|
||||
- if (value.ordered_offsets_up_to > 0)
|
||||
- gvs_tuple_get_member_bounds (value, value.ordered_offsets_up_to - 1, offset_size, NULL, &prev_i_end);
|
||||
+ if (value.checked_offsets_up_to > 0)
|
||||
+ gvs_tuple_get_member_bounds (value, value.checked_offsets_up_to - 1, offset_size, NULL, &prev_i_end);
|
||||
|
||||
- for (i = value.ordered_offsets_up_to; i <= index_; i++)
|
||||
+ for (i = value.checked_offsets_up_to; i <= index_; i++)
|
||||
{
|
||||
gsize i_start, i_end;
|
||||
|
||||
@@ -1060,6 +1078,7 @@ gvs_tuple_get_child (GVariantSerialised value,
|
||||
}
|
||||
|
||||
value.ordered_offsets_up_to = i - 1;
|
||||
+ value.checked_offsets_up_to = index_;
|
||||
}
|
||||
|
||||
if (index_ > value.ordered_offsets_up_to)
|
||||
@@ -1257,6 +1276,7 @@ gvs_tuple_is_normal (GVariantSerialised value)
|
||||
|
||||
/* All element bounds have been checked above. */
|
||||
value.ordered_offsets_up_to = G_MAXSIZE;
|
||||
+ value.checked_offsets_up_to = G_MAXSIZE;
|
||||
|
||||
{
|
||||
gsize fixed_size;
|
||||
diff --git a/glib/gvariant-serialiser.h b/glib/gvariant-serialiser.h
|
||||
index 144aec8..e132451 100644
|
||||
--- a/glib/gvariant-serialiser.h
|
||||
+++ b/glib/gvariant-serialiser.h
|
||||
@@ -40,6 +40,15 @@ typedef struct
|
||||
* Even when dealing with tuples, @ordered_offsets_up_to is an element index,
|
||||
* rather than an index into the frame offsets. */
|
||||
gsize ordered_offsets_up_to;
|
||||
+
|
||||
+ /* Similar to @ordered_offsets_up_to. This gives the index of the child element
|
||||
+ * whose frame offset is the highest in the offset table which has been
|
||||
+ * checked so far.
|
||||
+ *
|
||||
+ * This is always ≥ @ordered_offsets_up_to. It is always an element index.
|
||||
+ *
|
||||
+ * See documentation in gvariant-core.c for `struct GVariant` for details. */
|
||||
+ gsize checked_offsets_up_to;
|
||||
} GVariantSerialised;
|
||||
|
||||
/* deserialisation */
|
||||
diff --git a/glib/gvariant.c b/glib/gvariant.c
|
||||
index fdd36be..f910bd4 100644
|
||||
--- a/glib/gvariant.c
|
||||
+++ b/glib/gvariant.c
|
||||
@@ -5945,6 +5945,7 @@ g_variant_byteswap (GVariant *value)
|
||||
serialised.size = g_variant_get_size (trusted);
|
||||
serialised.data = g_malloc (serialised.size);
|
||||
serialised.ordered_offsets_up_to = G_MAXSIZE; /* operating on the normal form */
|
||||
+ serialised.checked_offsets_up_to = G_MAXSIZE;
|
||||
g_variant_store (trusted, serialised.data);
|
||||
g_variant_unref (trusted);
|
||||
|
||||
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
|
||||
index a84b02e..640f3c0 100644
|
||||
--- a/glib/tests/gvariant.c
|
||||
+++ b/glib/tests/gvariant.c
|
||||
@@ -1286,6 +1286,7 @@ random_instance_filler (GVariantSerialised *serialised,
|
||||
|
||||
serialised->depth = 0;
|
||||
serialised->ordered_offsets_up_to = 0;
|
||||
+ serialised->checked_offsets_up_to = 0;
|
||||
|
||||
g_assert_true (serialised->type_info == instance->type_info);
|
||||
g_assert_cmpuint (serialised->size, ==, instance->size);
|
||||
@@ -1453,6 +1454,7 @@ test_maybe (void)
|
||||
serialised.size = needed_size;
|
||||
serialised.depth = 0;
|
||||
serialised.ordered_offsets_up_to = 0;
|
||||
+ serialised.checked_offsets_up_to = 0;
|
||||
|
||||
g_variant_serialiser_serialise (serialised,
|
||||
random_instance_filler,
|
||||
@@ -1577,6 +1579,7 @@ test_array (void)
|
||||
serialised.size = needed_size;
|
||||
serialised.depth = 0;
|
||||
serialised.ordered_offsets_up_to = 0;
|
||||
+ serialised.checked_offsets_up_to = 0;
|
||||
|
||||
g_variant_serialiser_serialise (serialised, random_instance_filler,
|
||||
(gpointer *) instances, n_children);
|
||||
@@ -1742,6 +1745,7 @@ test_tuple (void)
|
||||
serialised.size = needed_size;
|
||||
serialised.depth = 0;
|
||||
serialised.ordered_offsets_up_to = 0;
|
||||
+ serialised.checked_offsets_up_to = 0;
|
||||
|
||||
g_variant_serialiser_serialise (serialised, random_instance_filler,
|
||||
(gpointer *) instances, n_children);
|
||||
@@ -1839,6 +1843,7 @@ test_variant (void)
|
||||
serialised.size = needed_size;
|
||||
serialised.depth = 0;
|
||||
serialised.ordered_offsets_up_to = 0;
|
||||
+ serialised.checked_offsets_up_to = 0;
|
||||
|
||||
g_variant_serialiser_serialise (serialised, random_instance_filler,
|
||||
(gpointer *) &instance, 1);
|
||||
--
|
||||
2.24.4
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
From 298a537d5f6783e55d87e40011ee3fd3b22b72f9 Mon Sep 17 00:00:00 2001
|
||||
From: Philip Withnall <pwithnall@endlessos.org>
|
||||
Date: Thu, 17 Aug 2023 01:39:01 +0000
|
||||
Subject: [PATCH] gvariant: Zero-initialise various GVariantSerialised objects
|
||||
|
||||
The following few commits will add a couple of new fields to
|
||||
`GVariantSerialised`, and they should be zero-filled by default.
|
||||
|
||||
Try and pre-empt that a bit by zero-filling `GVariantSerialised` by
|
||||
default in a few places.
|
||||
|
||||
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
||||
|
||||
Helps: #2121
|
||||
|
||||
CVE: CVE-2023-32665
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/glib/-/commit/298a537d5f6783e55d87e40011ee3fd3b22b72f9]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
glib/gvariant.c | 2 +-
|
||||
glib/tests/gvariant.c | 12 ++++++------
|
||||
2 files changed, 7 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/glib/gvariant.c b/glib/gvariant.c
|
||||
index f910bd4..8ba701e 100644
|
||||
--- a/glib/gvariant.c
|
||||
+++ b/glib/gvariant.c
|
||||
@@ -5936,7 +5936,7 @@ g_variant_byteswap (GVariant *value)
|
||||
if (alignment)
|
||||
/* (potentially) contains multi-byte numeric data */
|
||||
{
|
||||
- GVariantSerialised serialised;
|
||||
+ GVariantSerialised serialised = { 0, };
|
||||
GVariant *trusted;
|
||||
GBytes *bytes;
|
||||
|
||||
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
|
||||
index 640f3c0..d640c81 100644
|
||||
--- a/glib/tests/gvariant.c
|
||||
+++ b/glib/tests/gvariant.c
|
||||
@@ -1446,7 +1446,7 @@ test_maybe (void)
|
||||
|
||||
for (flavour = 0; flavour < 8; flavour += alignment)
|
||||
{
|
||||
- GVariantSerialised serialised;
|
||||
+ GVariantSerialised serialised = { 0, };
|
||||
GVariantSerialised child;
|
||||
|
||||
serialised.type_info = type_info;
|
||||
@@ -1572,7 +1572,7 @@ test_array (void)
|
||||
|
||||
for (flavour = 0; flavour < 8; flavour += alignment)
|
||||
{
|
||||
- GVariantSerialised serialised;
|
||||
+ GVariantSerialised serialised = { 0, };
|
||||
|
||||
serialised.type_info = array_info;
|
||||
serialised.data = flavoured_malloc (needed_size, flavour);
|
||||
@@ -1738,7 +1738,7 @@ test_tuple (void)
|
||||
|
||||
for (flavour = 0; flavour < 8; flavour += alignment)
|
||||
{
|
||||
- GVariantSerialised serialised;
|
||||
+ GVariantSerialised serialised = { 0, };
|
||||
|
||||
serialised.type_info = type_info;
|
||||
serialised.data = flavoured_malloc (needed_size, flavour);
|
||||
@@ -1835,7 +1835,7 @@ test_variant (void)
|
||||
|
||||
for (flavour = 0; flavour < 8; flavour += alignment)
|
||||
{
|
||||
- GVariantSerialised serialised;
|
||||
+ GVariantSerialised serialised = { 0, };
|
||||
GVariantSerialised child;
|
||||
|
||||
serialised.type_info = type_info;
|
||||
@@ -2284,7 +2284,7 @@ serialise_tree (TreeInstance *tree,
|
||||
static void
|
||||
test_byteswap (void)
|
||||
{
|
||||
- GVariantSerialised one, two;
|
||||
+ GVariantSerialised one = { 0, }, two = { 0, };
|
||||
TreeInstance *tree;
|
||||
|
||||
tree = tree_instance_new (NULL, 3);
|
||||
@@ -2358,7 +2358,7 @@ test_serialiser_children (void)
|
||||
static void
|
||||
test_fuzz (gdouble *fuzziness)
|
||||
{
|
||||
- GVariantSerialised serialised;
|
||||
+ GVariantSerialised serialised = { 0, };
|
||||
TreeInstance *tree;
|
||||
|
||||
/* make an instance */
|
||||
--
|
||||
2.24.4
|
||||
|
||||
@@ -42,6 +42,20 @@ SRC_URI = "${GNOME_MIRROR}/glib/${SHRT_VER}/glib-${PV}.tar.xz \
|
||||
file://CVE-2021-28153-3.patch \
|
||||
file://CVE-2021-28153-4.patch \
|
||||
file://CVE-2021-28153-5.patch \
|
||||
file://CVE-2023-32665-0001.patch \
|
||||
file://CVE-2023-32665-0002.patch \
|
||||
file://CVE-2023-32665-0003.patch \
|
||||
file://CVE-2023-32665-0004.patch \
|
||||
file://CVE-2023-32665-0005.patch \
|
||||
file://CVE-2023-32665-0006.patch \
|
||||
file://CVE-2023-32665-0007.patch \
|
||||
file://CVE-2023-32665-0008.patch \
|
||||
file://CVE-2023-32665-0009.patch \
|
||||
file://CVE-2023-29499.patch \
|
||||
file://CVE-2023-32611-0001.patch \
|
||||
file://CVE-2023-32611-0002.patch \
|
||||
file://CVE-2023-32643.patch \
|
||||
file://CVE-2023-32636.patch \
|
||||
"
|
||||
|
||||
SRC_URI_append_class-native = " file://relocate-modules.patch"
|
||||
|
||||
63
meta/recipes-core/glibc/glibc/CVE-2023-4911.patch
Normal file
63
meta/recipes-core/glibc/glibc/CVE-2023-4911.patch
Normal file
@@ -0,0 +1,63 @@
|
||||
From d2b77337f734fcacdfc8e0ddec14cf31a746c7be Mon Sep 17 00:00:00 2001
|
||||
From: Siddhesh Poyarekar <siddhesh@redhat.com>
|
||||
Date: Mon, 11 Sep 2023 18:53:15 -0400
|
||||
Subject: [PATCH v2] tunables: Terminate immediately if end of input is reached
|
||||
|
||||
The string parsing routine may end up writing beyond bounds of tunestr
|
||||
if the input tunable string is malformed, of the form name=name=val.
|
||||
This gets processed twice, first as name=name=val and next as name=val,
|
||||
resulting in tunestr being name=name=val:name=val, thus overflowing
|
||||
tunestr.
|
||||
|
||||
Terminate the parsing loop at the first instance itself so that tunestr
|
||||
does not overflow.
|
||||
---
|
||||
Changes from v1:
|
||||
|
||||
- Also null-terminate tunestr before exiting.
|
||||
|
||||
elf/dl-tunables.c | 17 ++++++++++-------
|
||||
1 file changed, 10 insertions(+), 7 deletions(-)
|
||||
|
||||
Upstream-Status: Backport [git://sourceware.org/git/glibc.git]
|
||||
CVE: CVE-2023-4911
|
||||
|
||||
diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
|
||||
index 8e7ee9df10..76cf8b9da3 100644
|
||||
--- a/elf/dl-tunables.c
|
||||
+++ b/elf/dl-tunables.c
|
||||
@@ -187,11 +187,7 @@ parse_tunables (char *tunestr, char *valstring)
|
||||
/* If we reach the end of the string before getting a valid name-value
|
||||
pair, bail out. */
|
||||
if (p[len] == '\0')
|
||||
- {
|
||||
- if (__libc_enable_secure)
|
||||
- tunestr[off] = '\0';
|
||||
- return;
|
||||
- }
|
||||
+ break;
|
||||
|
||||
/* We did not find a valid name-value pair before encountering the
|
||||
colon. */
|
||||
@@ -251,9 +247,16 @@ parse_tunables (char *tunestr, char *valstring)
|
||||
}
|
||||
}
|
||||
|
||||
- if (p[len] != '\0')
|
||||
- p += len + 1;
|
||||
+ /* We reached the end while processing the tunable string. */
|
||||
+ if (p[len] == '\0')
|
||||
+ break;
|
||||
+
|
||||
+ p += len + 1;
|
||||
}
|
||||
+
|
||||
+ /* Terminate tunestr before we leave. */
|
||||
+ if (__libc_enable_secure)
|
||||
+ tunestr[off] = '\0';
|
||||
}
|
||||
#endif
|
||||
|
||||
--
|
||||
2.41.0
|
||||
|
||||
@@ -58,7 +58,7 @@ elif targettype == "ssh":
|
||||
user = os.environ.get("SSH_HOST_USER", None)
|
||||
port = os.environ.get("SSH_HOST_PORT", None)
|
||||
|
||||
command = ["ssh", "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no"]
|
||||
command = ["ssh", "-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no", "-o", "LogLevel=quiet"]
|
||||
if port:
|
||||
command += ["-p", str(port)]
|
||||
if not host:
|
||||
|
||||
@@ -80,6 +80,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
|
||||
file://0036-i386-Avoid-lazy-relocation-of-tlsdesc-BZ-27137.patch \
|
||||
file://0037-Avoid-deadlock-between-pthread_create-and-ctors.patch \
|
||||
file://CVE-2023-0687.patch \
|
||||
file://CVE-2023-4911.patch \
|
||||
"
|
||||
S = "${WORKDIR}/git"
|
||||
B = "${WORKDIR}/build-${TARGET_SYS}"
|
||||
|
||||
@@ -24,7 +24,7 @@ IMAGE_FSTYPES = "wic.vmdk"
|
||||
|
||||
inherit core-image setuptools3
|
||||
|
||||
SRCREV ?= "88bec50206d02fef3cdc3eaabb638963144eb63b"
|
||||
SRCREV ?= "9a045bde41e8edf3b17c73526d8b3c151e0bb242"
|
||||
SRC_URI = "git://git.yoctoproject.org/poky;branch=dunfell \
|
||||
file://Yocto_Build_Appliance.vmx \
|
||||
file://Yocto_Build_Appliance.vmxf \
|
||||
|
||||
36
meta/recipes-core/libxml/libxml2/CVE-2023-39615-0001.patch
Normal file
36
meta/recipes-core/libxml/libxml2/CVE-2023-39615-0001.patch
Normal file
@@ -0,0 +1,36 @@
|
||||
From d0c3f01e110d54415611c5fa0040cdf4a56053f9 Mon Sep 17 00:00:00 2001
|
||||
From: Nick Wellnhofer <wellnhofer@aevum.de>
|
||||
Date: Sat, 6 May 2023 17:47:37 +0200
|
||||
Subject: [PATCH] parser: Fix old SAX1 parser with custom callbacks
|
||||
|
||||
For some reason, xmlCtxtUseOptionsInternal set the start and end element
|
||||
SAX handlers to the internal DOM builder functions when XML_PARSE_SAX1
|
||||
was specified. This means that custom SAX handlers could never work with
|
||||
that flag because these functions would receive the wrong user data
|
||||
argument and crash immediately.
|
||||
|
||||
Fixes #535.
|
||||
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/libxml2/-/commit/d0c3f01e110d54415611c5fa0040cdf4a56053f9]
|
||||
CVE: CVE-2023-39615
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
parser.c | 2 --
|
||||
1 file changed, 2 deletions(-)
|
||||
|
||||
diff --git a/parser.c b/parser.c
|
||||
index 6e09208..7814e6e 100644
|
||||
--- a/parser.c
|
||||
+++ b/parser.c
|
||||
@@ -15156,8 +15156,6 @@ xmlCtxtUseOptionsInternal(xmlParserCtxtPtr ctxt, int options, const char *encodi
|
||||
}
|
||||
#ifdef LIBXML_SAX1_ENABLED
|
||||
if (options & XML_PARSE_SAX1) {
|
||||
- ctxt->sax->startElement = xmlSAX2StartElement;
|
||||
- ctxt->sax->endElement = xmlSAX2EndElement;
|
||||
ctxt->sax->startElementNs = NULL;
|
||||
ctxt->sax->endElementNs = NULL;
|
||||
ctxt->sax->initialized = 1;
|
||||
--
|
||||
2.24.4
|
||||
|
||||
71
meta/recipes-core/libxml/libxml2/CVE-2023-39615-0002.patch
Normal file
71
meta/recipes-core/libxml/libxml2/CVE-2023-39615-0002.patch
Normal file
@@ -0,0 +1,71 @@
|
||||
From 235b15a590eecf97b09e87bdb7e4f8333e9de129 Mon Sep 17 00:00:00 2001
|
||||
From: Nick Wellnhofer <wellnhofer@aevum.de>
|
||||
Date: Mon, 8 May 2023 17:58:02 +0200
|
||||
Subject: [PATCH] SAX: Always initialize SAX1 element handlers
|
||||
|
||||
Follow-up to commit d0c3f01e. A parser context will be initialized to
|
||||
SAX version 2, but this can be overridden with XML_PARSE_SAX1 later,
|
||||
so we must initialize the SAX1 element handlers as well.
|
||||
|
||||
Change the check in xmlDetectSAX2 to only look for XML_SAX2_MAGIC, so
|
||||
we don't switch to SAX1 if the SAX2 element handlers are NULL.
|
||||
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/libxml2/-/commit/235b15a590eecf97b09e87bdb7e4f8333e9de129]
|
||||
CVE: CVE-2023-39615
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
SAX2.c | 11 +++++++----
|
||||
parser.c | 5 +----
|
||||
2 files changed, 8 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/SAX2.c b/SAX2.c
|
||||
index 5f141f9..902d34d 100644
|
||||
--- a/SAX2.c
|
||||
+++ b/SAX2.c
|
||||
@@ -2869,20 +2869,23 @@ xmlSAXVersion(xmlSAXHandler *hdlr, int version)
|
||||
{
|
||||
if (hdlr == NULL) return(-1);
|
||||
if (version == 2) {
|
||||
- hdlr->startElement = NULL;
|
||||
- hdlr->endElement = NULL;
|
||||
hdlr->startElementNs = xmlSAX2StartElementNs;
|
||||
hdlr->endElementNs = xmlSAX2EndElementNs;
|
||||
hdlr->serror = NULL;
|
||||
hdlr->initialized = XML_SAX2_MAGIC;
|
||||
#ifdef LIBXML_SAX1_ENABLED
|
||||
} else if (version == 1) {
|
||||
- hdlr->startElement = xmlSAX2StartElement;
|
||||
- hdlr->endElement = xmlSAX2EndElement;
|
||||
hdlr->initialized = 1;
|
||||
#endif /* LIBXML_SAX1_ENABLED */
|
||||
} else
|
||||
return(-1);
|
||||
+#ifdef LIBXML_SAX1_ENABLED
|
||||
+ hdlr->startElement = xmlSAX2StartElement;
|
||||
+ hdlr->endElement = xmlSAX2EndElement;
|
||||
+#else
|
||||
+ hdlr->startElement = NULL;
|
||||
+ hdlr->endElement = NULL;
|
||||
+#endif /* LIBXML_SAX1_ENABLED */
|
||||
hdlr->internalSubset = xmlSAX2InternalSubset;
|
||||
hdlr->externalSubset = xmlSAX2ExternalSubset;
|
||||
hdlr->isStandalone = xmlSAX2IsStandalone;
|
||||
diff --git a/parser.c b/parser.c
|
||||
index 7814e6e..cf0fb38 100644
|
||||
--- a/parser.c
|
||||
+++ b/parser.c
|
||||
@@ -1102,10 +1102,7 @@ xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
|
||||
if (ctxt == NULL) return;
|
||||
sax = ctxt->sax;
|
||||
#ifdef LIBXML_SAX1_ENABLED
|
||||
- if ((sax) && (sax->initialized == XML_SAX2_MAGIC) &&
|
||||
- ((sax->startElementNs != NULL) ||
|
||||
- (sax->endElementNs != NULL) ||
|
||||
- ((sax->startElement == NULL) && (sax->endElement == NULL))))
|
||||
+ if ((sax) && (sax->initialized == XML_SAX2_MAGIC))
|
||||
ctxt->sax2 = 1;
|
||||
#else
|
||||
ctxt->sax2 = 1;
|
||||
--
|
||||
2.24.4
|
||||
|
||||
44
meta/recipes-core/libxml/libxml2/CVE-2023-39615-pre.patch
Normal file
44
meta/recipes-core/libxml/libxml2/CVE-2023-39615-pre.patch
Normal file
@@ -0,0 +1,44 @@
|
||||
From 99fc048d7f7292c5ee18e44c400bd73bc63a47ed Mon Sep 17 00:00:00 2001
|
||||
From: Nick Wellnhofer <wellnhofer@aevum.de>
|
||||
Date: Fri, 14 Aug 2020 14:18:50 +0200
|
||||
Subject: [PATCH] Don't use SAX1 if all element handlers are NULL
|
||||
|
||||
Running xmllint with "--sax --noout" installs a SAX2 handler with all
|
||||
callbacks set to NULL. In this case or similar situations, we don't want
|
||||
to switch to SAX1 parsing.
|
||||
|
||||
Note: This patch is needed for "CVE-2023-39615-0002" patch to apply.
|
||||
Without this patch the build will fail with undefined sax error.
|
||||
|
||||
Upstream-Status: Backport from [https://gitlab.gnome.org/GNOME/libxml2/-/commit/99fc048d7f7292c5ee18e44c400bd73bc63a47ed]
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
parser.c | 10 +++++++---
|
||||
1 file changed, 7 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/parser.c b/parser.c
|
||||
index bb677b0..6e09208 100644
|
||||
--- a/parser.c
|
||||
+++ b/parser.c
|
||||
@@ -1098,11 +1098,15 @@ xmlHasFeature(xmlFeature feature)
|
||||
*/
|
||||
static void
|
||||
xmlDetectSAX2(xmlParserCtxtPtr ctxt) {
|
||||
+ xmlSAXHandlerPtr sax;
|
||||
if (ctxt == NULL) return;
|
||||
+ sax = ctxt->sax;
|
||||
#ifdef LIBXML_SAX1_ENABLED
|
||||
- if ((ctxt->sax) && (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
|
||||
- ((ctxt->sax->startElementNs != NULL) ||
|
||||
- (ctxt->sax->endElementNs != NULL))) ctxt->sax2 = 1;
|
||||
+ if ((sax) && (sax->initialized == XML_SAX2_MAGIC) &&
|
||||
+ ((sax->startElementNs != NULL) ||
|
||||
+ (sax->endElementNs != NULL) ||
|
||||
+ ((sax->startElement == NULL) && (sax->endElement == NULL))))
|
||||
+ ctxt->sax2 = 1;
|
||||
#else
|
||||
ctxt->sax2 = 1;
|
||||
#endif /* LIBXML_SAX1_ENABLED */
|
||||
--
|
||||
2.24.4
|
||||
|
||||
@@ -38,6 +38,9 @@ SRC_URI += "http://www.w3.org/XML/Test/xmlts20080827.tar.gz;subdir=${BP};name=te
|
||||
file://CVE-2022-40304.patch \
|
||||
file://CVE-2023-28484.patch \
|
||||
file://CVE-2023-29469.patch \
|
||||
file://CVE-2023-39615-pre.patch \
|
||||
file://CVE-2023-39615-0001.patch \
|
||||
file://CVE-2023-39615-0002.patch \
|
||||
"
|
||||
|
||||
SRC_URI[archive.sha256sum] = "593b7b751dd18c2d6abcd0c4bcb29efc203d0b4373a6df98e3a455ea74ae2813"
|
||||
|
||||
@@ -136,7 +136,7 @@ def nvd_request_next(url, api_key, args):
|
||||
|
||||
if (r.headers['content-encoding'] == 'gzip'):
|
||||
buf = r.read()
|
||||
raw_data = gzip.decompress(buf)
|
||||
raw_data = gzip.decompress(buf).decode("utf-8")
|
||||
else:
|
||||
raw_data = r.read().decode("utf-8")
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ class SystemdUnit():
|
||||
try:
|
||||
for dependent in config.get('Install', prop):
|
||||
# expand any %i to instance (ignoring escape sequence %%)
|
||||
dependent = re.sub("([^%](%%)*)%i", "\\1{}".format(instance), dependent)
|
||||
dependent = re.sub("([^%](%%)*)%i", "\\g<1>{}".format(instance), dependent)
|
||||
wants = systemdir / "{}.{}".format(dependent, dirstem) / service
|
||||
add_link(wants, target)
|
||||
|
||||
|
||||
120
meta/recipes-core/systemd/systemd/CVE-2018-21029.patch
Normal file
120
meta/recipes-core/systemd/systemd/CVE-2018-21029.patch
Normal file
@@ -0,0 +1,120 @@
|
||||
From 3f9d9289ee8730a81a0464539f4e1ba2d23d0ce9 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
|
||||
Date: Tue, 3 Mar 2020 23:31:25 +0000
|
||||
Subject: [PATCH] systemd-resolved: use hostname for certificate validation in
|
||||
DoT
|
||||
|
||||
Widely accepted certificates for IP addresses are expensive and only
|
||||
affordable for larger organizations. Therefore if the user provides
|
||||
the hostname in the DNS= option, we should use it instead of the IP
|
||||
address.
|
||||
|
||||
(cherry picked from commit eec394f10bbfcc3d2fc8504ad8ff5be44231abd5)
|
||||
|
||||
CVE: CVE-2018-21029
|
||||
Upstream-Status: Backport [ff26d281aec0877b43269f18c6282cd79a7f5529]
|
||||
Signed-off-by: Marek Vasut <marex@denx.de>
|
||||
---
|
||||
man/resolved.conf.xml | 16 +++++++++++-----
|
||||
src/resolve/resolved-dnstls-gnutls.c | 20 ++++++++++++--------
|
||||
src/resolve/resolved-dnstls-openssl.c | 15 +++++++++++----
|
||||
3 files changed, 34 insertions(+), 17 deletions(-)
|
||||
|
||||
diff --git a/man/resolved.conf.xml b/man/resolved.conf.xml
|
||||
index 818000145b..37161ebcbc 100644
|
||||
--- a/man/resolved.conf.xml
|
||||
+++ b/man/resolved.conf.xml
|
||||
@@ -193,11 +193,17 @@
|
||||
<varlistentry>
|
||||
<term><varname>DNSOverTLS=</varname></term>
|
||||
<listitem>
|
||||
- <para>Takes a boolean argument or <literal>opportunistic</literal>.
|
||||
- If true all connections to the server will be encrypted. Note that
|
||||
- this mode requires a DNS server that supports DNS-over-TLS and has
|
||||
- a valid certificate for it's IP. If the DNS server does not support
|
||||
- DNS-over-TLS all DNS requests will fail. When set to <literal>opportunistic</literal>
|
||||
+ <para>Takes a boolean argument or <literal>opportunistic</literal>. If
|
||||
+ true all connections to the server will be encrypted. Note that this
|
||||
+ mode requires a DNS server that supports DNS-over-TLS and has a valid
|
||||
+ certificate. If the hostname was specified in <varname>DNS=</varname>
|
||||
+ by using the format format <literal>address#server_name</literal> it
|
||||
+ is used to validate its certificate and also to enable Server Name
|
||||
+ Indication (SNI) when opening a TLS connection. Otherwise
|
||||
+ the certificate is checked against the server's IP.
|
||||
+ If the DNS server does not support DNS-over-TLS all DNS requests will fail.</para>
|
||||
+
|
||||
+ <para>When set to <literal>opportunistic</literal>
|
||||
DNS request are attempted to send encrypted with DNS-over-TLS.
|
||||
If the DNS server does not support TLS, DNS-over-TLS is disabled.
|
||||
Note that this mode makes DNS-over-TLS vulnerable to "downgrade"
|
||||
diff --git a/src/resolve/resolved-dnstls-gnutls.c b/src/resolve/resolved-dnstls-gnutls.c
|
||||
index ed0a31e8bf..c7215723a7 100644
|
||||
--- a/src/resolve/resolved-dnstls-gnutls.c
|
||||
+++ b/src/resolve/resolved-dnstls-gnutls.c
|
||||
@@ -56,15 +56,19 @@ int dnstls_stream_connect_tls(DnsStream *stream, DnsServer *server) {
|
||||
}
|
||||
|
||||
if (server->manager->dns_over_tls_mode == DNS_OVER_TLS_YES) {
|
||||
- stream->dnstls_data.validation.type = GNUTLS_DT_IP_ADDRESS;
|
||||
- if (server->family == AF_INET) {
|
||||
- stream->dnstls_data.validation.data = (unsigned char*) &server->address.in.s_addr;
|
||||
- stream->dnstls_data.validation.size = 4;
|
||||
- } else {
|
||||
- stream->dnstls_data.validation.data = server->address.in6.s6_addr;
|
||||
- stream->dnstls_data.validation.size = 16;
|
||||
+ if (server->server_name)
|
||||
+ gnutls_session_set_verify_cert(gs, server->server_name, 0);
|
||||
+ else {
|
||||
+ stream->dnstls_data.validation.type = GNUTLS_DT_IP_ADDRESS;
|
||||
+ if (server->family == AF_INET) {
|
||||
+ stream->dnstls_data.validation.data = (unsigned char*) &server->address.in.s_addr;
|
||||
+ stream->dnstls_data.validation.size = 4;
|
||||
+ } else {
|
||||
+ stream->dnstls_data.validation.data = server->address.in6.s6_addr;
|
||||
+ stream->dnstls_data.validation.size = 16;
|
||||
+ }
|
||||
+ gnutls_session_set_verify_cert2(gs, &stream->dnstls_data.validation, 1, 0);
|
||||
}
|
||||
- gnutls_session_set_verify_cert2(gs, &stream->dnstls_data.validation, 1, 0);
|
||||
}
|
||||
|
||||
gnutls_handshake_set_timeout(gs, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT);
|
||||
diff --git a/src/resolve/resolved-dnstls-openssl.c b/src/resolve/resolved-dnstls-openssl.c
|
||||
index 85e202ff74..007aedaa5b 100644
|
||||
--- a/src/resolve/resolved-dnstls-openssl.c
|
||||
+++ b/src/resolve/resolved-dnstls-openssl.c
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
+#include <openssl/x509v3.h>
|
||||
|
||||
#include "io-util.h"
|
||||
#include "resolved-dns-stream.h"
|
||||
@@ -78,13 +79,19 @@ int dnstls_stream_connect_tls(DnsStream *stream, DnsServer *server) {
|
||||
|
||||
if (server->manager->dns_over_tls_mode == DNS_OVER_TLS_YES) {
|
||||
X509_VERIFY_PARAM *v;
|
||||
- const unsigned char *ip;
|
||||
|
||||
SSL_set_verify(s, SSL_VERIFY_PEER, NULL);
|
||||
v = SSL_get0_param(s);
|
||||
- ip = server->family == AF_INET ? (const unsigned char*) &server->address.in.s_addr : server->address.in6.s6_addr;
|
||||
- if (!X509_VERIFY_PARAM_set1_ip(v, ip, FAMILY_ADDRESS_SIZE(server->family)))
|
||||
- return -ECONNREFUSED;
|
||||
+ if (server->server_name) {
|
||||
+ X509_VERIFY_PARAM_set_hostflags(v, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
|
||||
+ if (X509_VERIFY_PARAM_set1_host(v, server->server_name, 0) == 0)
|
||||
+ return -ECONNREFUSED;
|
||||
+ } else {
|
||||
+ const unsigned char *ip;
|
||||
+ ip = server->family == AF_INET ? (const unsigned char*) &server->address.in.s_addr : server->address.in6.s6_addr;
|
||||
+ if (X509_VERIFY_PARAM_set1_ip(v, ip, FAMILY_ADDRESS_SIZE(server->family)) == 0)
|
||||
+ return -ECONNREFUSED;
|
||||
+ }
|
||||
}
|
||||
|
||||
ERR_clear_error();
|
||||
--
|
||||
2.40.1
|
||||
|
||||
@@ -31,6 +31,7 @@ SRC_URI += "file://touchscreen.rules \
|
||||
file://network-fix-Link-reference-counter-issue.patch \
|
||||
file://rm-rf-refactor-rm-rf-children-split-out-body-of-directory.patch \
|
||||
file://rm-rf-optionally-fsync-after-removing-directory-tree.patch \
|
||||
file://CVE-2018-21029.patch \
|
||||
file://CVE-2021-3997-1.patch \
|
||||
file://CVE-2021-3997-2.patch \
|
||||
file://CVE-2021-3997-3.patch \
|
||||
|
||||
@@ -53,5 +53,6 @@ SRC_URI = "\
|
||||
file://CVE-2020-16593.patch \
|
||||
file://0001-CVE-2021-45078.patch \
|
||||
file://CVE-2022-38533.patch \
|
||||
file://CVE-2023-25588.patch \
|
||||
"
|
||||
S = "${WORKDIR}/git"
|
||||
|
||||
146
meta/recipes-devtools/binutils/binutils/CVE-2023-25588.patch
Normal file
146
meta/recipes-devtools/binutils/binutils/CVE-2023-25588.patch
Normal file
@@ -0,0 +1,146 @@
|
||||
From d12f8998d2d086f0a6606589e5aedb7147e6f2f1 Mon Sep 17 00:00:00 2001
|
||||
From: Alan Modra <amodra@gmail.com>
|
||||
Date: Fri, 14 Oct 2022 10:30:21 +1030
|
||||
Subject: [PATCH] PR29677, Field `the_bfd` of `asymbol` is uninitialised
|
||||
|
||||
Besides not initialising the_bfd of synthetic symbols, counting
|
||||
symbols when sizing didn't match symbols created if there were any
|
||||
dynsyms named "". We don't want synthetic symbols without names
|
||||
anyway, so get rid of them. Also, simplify and correct sanity checks.
|
||||
|
||||
PR 29677
|
||||
* mach-o.c (bfd_mach_o_get_synthetic_symtab): Rewrite.
|
||||
---
|
||||
Upstream-Status: Backport from [https://sourceware.org/git/?p=binutils-gdb.git;a=patch;h=d12f8998d2d086f0a6606589e5aedb7147e6f2f1]
|
||||
CVE: CVE-2023-25588
|
||||
Signed-off-by: Ashish Sharma <asharma@mvista.com>
|
||||
|
||||
bfd/mach-o.c | 72 ++++++++++++++++++++++------------------------------
|
||||
1 file changed, 31 insertions(+), 41 deletions(-)
|
||||
|
||||
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
|
||||
index acb35e7f0c6..5279343768c 100644
|
||||
--- a/bfd/mach-o.c
|
||||
+++ b/bfd/mach-o.c
|
||||
@@ -938,11 +938,9 @@ bfd_mach_o_get_synthetic_symtab (bfd *abfd,
|
||||
bfd_mach_o_symtab_command *symtab = mdata->symtab;
|
||||
asymbol *s;
|
||||
char * s_start;
|
||||
- char * s_end;
|
||||
unsigned long count, i, j, n;
|
||||
size_t size;
|
||||
char *names;
|
||||
- char *nul_name;
|
||||
const char stub [] = "$stub";
|
||||
|
||||
*ret = NULL;
|
||||
@@ -955,27 +953,27 @@ bfd_mach_o_get_synthetic_symtab (bfd *abfd,
|
||||
/* We need to allocate a bfd symbol for every indirect symbol and to
|
||||
allocate the memory for its name. */
|
||||
count = dysymtab->nindirectsyms;
|
||||
- size = count * sizeof (asymbol) + 1;
|
||||
-
|
||||
+ size = 0;
|
||||
for (j = 0; j < count; j++)
|
||||
{
|
||||
- const char * strng;
|
||||
unsigned int isym = dysymtab->indirect_syms[j];
|
||||
+ const char *str;
|
||||
|
||||
/* Some indirect symbols are anonymous. */
|
||||
- if (isym < symtab->nsyms && (strng = symtab->symbols[isym].symbol.name))
|
||||
- /* PR 17512: file: f5b8eeba. */
|
||||
- size += strnlen (strng, symtab->strsize - (strng - symtab->strtab)) + sizeof (stub);
|
||||
+ if (isym < symtab->nsyms
|
||||
+ && (str = symtab->symbols[isym].symbol.name) != NULL)
|
||||
+ {
|
||||
+ /* PR 17512: file: f5b8eeba. */
|
||||
+ size += strnlen (str, symtab->strsize - (str - symtab->strtab));
|
||||
+ size += sizeof (stub);
|
||||
+ }
|
||||
}
|
||||
|
||||
- s_start = bfd_malloc (size);
|
||||
+ s_start = bfd_malloc (size + count * sizeof (asymbol));
|
||||
s = *ret = (asymbol *) s_start;
|
||||
if (s == NULL)
|
||||
return -1;
|
||||
names = (char *) (s + count);
|
||||
- nul_name = names;
|
||||
- *names++ = 0;
|
||||
- s_end = s_start + size;
|
||||
|
||||
n = 0;
|
||||
for (i = 0; i < mdata->nsects; i++)
|
||||
@@ -997,47 +995,39 @@ bfd_mach_o_get_synthetic_symtab (bfd *abfd,
|
||||
entry_size = bfd_mach_o_section_get_entry_size (abfd, sec);
|
||||
|
||||
/* PR 17512: file: 08e15eec. */
|
||||
- if (first >= count || last >= count || first > last)
|
||||
+ if (first >= count || last > count || first > last)
|
||||
goto fail;
|
||||
|
||||
for (j = first; j < last; j++)
|
||||
{
|
||||
unsigned int isym = dysymtab->indirect_syms[j];
|
||||
-
|
||||
- /* PR 17512: file: 04d64d9b. */
|
||||
- if (((char *) s) + sizeof (* s) > s_end)
|
||||
- goto fail;
|
||||
-
|
||||
- s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
|
||||
- s->section = sec->bfdsection;
|
||||
- s->value = addr - sec->addr;
|
||||
- s->udata.p = NULL;
|
||||
+ const char *str;
|
||||
+ size_t len;
|
||||
|
||||
if (isym < symtab->nsyms
|
||||
- && symtab->symbols[isym].symbol.name)
|
||||
+ && (str = symtab->symbols[isym].symbol.name) != NULL)
|
||||
{
|
||||
- const char *sym = symtab->symbols[isym].symbol.name;
|
||||
- size_t len;
|
||||
-
|
||||
- s->name = names;
|
||||
- len = strlen (sym);
|
||||
- /* PR 17512: file: 47dfd4d2. */
|
||||
- if (names + len >= s_end)
|
||||
+ /* PR 17512: file: 04d64d9b. */
|
||||
+ if (n >= count)
|
||||
goto fail;
|
||||
- memcpy (names, sym, len);
|
||||
- names += len;
|
||||
- /* PR 17512: file: 18f340a4. */
|
||||
- if (names + sizeof (stub) >= s_end)
|
||||
+ len = strnlen (str, symtab->strsize - (str - symtab->strtab));
|
||||
+ /* PR 17512: file: 47dfd4d2, 18f340a4. */
|
||||
+ if (size < len + sizeof (stub))
|
||||
goto fail;
|
||||
- memcpy (names, stub, sizeof (stub));
|
||||
- names += sizeof (stub);
|
||||
+ memcpy (names, str, len);
|
||||
+ memcpy (names + len, stub, sizeof (stub));
|
||||
+ s->name = names;
|
||||
+ names += len + sizeof (stub);
|
||||
+ size -= len + sizeof (stub);
|
||||
+ s->the_bfd = symtab->symbols[isym].symbol.the_bfd;
|
||||
+ s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
|
||||
+ s->section = sec->bfdsection;
|
||||
+ s->value = addr - sec->addr;
|
||||
+ s->udata.p = NULL;
|
||||
+ s++;
|
||||
+ n++;
|
||||
}
|
||||
- else
|
||||
- s->name = nul_name;
|
||||
-
|
||||
addr += entry_size;
|
||||
- s++;
|
||||
- n++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
--
|
||||
2.39.3
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
From 24def311c6168d0dfb7c5f0f183b72b709c49265 Mon Sep 17 00:00:00 2001
|
||||
From: Jean Delvare <jdelvare@suse.de>
|
||||
Date: Mon, 20 Feb 2023 14:53:21 +0100
|
||||
Subject: [PATCH] dmidecode: Split table fetching from decoding
|
||||
|
||||
Clean up function dmi_table so that it does only one thing:
|
||||
* dmi_table() is renamed to dmi_table_get(). It now retrieves the
|
||||
DMI table, but does not process it any longer.
|
||||
* Decoding or dumping the table is now done in smbios3_decode(),
|
||||
smbios_decode() and legacy_decode().
|
||||
No functional change.
|
||||
|
||||
A side effect of this change is that writing the header and body of
|
||||
dump files is now done in a single location. This is required to
|
||||
further consolidate the writing of dump files.
|
||||
|
||||
CVE-ID: CVE-2023-30630
|
||||
Upstream-Status: Backport [https://git.savannah.nongnu.org/cgit/dmidecode.git/commit/?id=39b2dd7b6ab7]
|
||||
|
||||
Backport Changes:
|
||||
- In the file dmidecode.c, the commit [dd593d2] in v3.3 introduces
|
||||
pr_info(). This is backported to printf() as per v3.2.
|
||||
|
||||
Signed-off-by: Jean Delvare <jdelvare@suse.de>
|
||||
Reviewed-by: Jerry Hoemann <jerry.hoemann@hpe.com>
|
||||
(cherry picked from commit 39b2dd7b6ab719b920e96ed832cfb4bdd664e808)
|
||||
Signed-off-by: Dhairya Nagodra <dnagodra@cisco.com>
|
||||
---
|
||||
dmidecode.c | 86 ++++++++++++++++++++++++++++++++++++++---------------
|
||||
1 file changed, 62 insertions(+), 24 deletions(-)
|
||||
|
||||
diff --git a/dmidecode.c b/dmidecode.c
|
||||
index a3e9d6c..d6eedd1 100644
|
||||
--- a/dmidecode.c
|
||||
+++ b/dmidecode.c
|
||||
@@ -5211,8 +5211,9 @@ static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
|
||||
}
|
||||
}
|
||||
|
||||
-static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
|
||||
- u32 flags)
|
||||
+/* Allocates a buffer for the table, must be freed by the caller */
|
||||
+static u8 *dmi_table_get(off_t base, u32 *len, u16 num, u32 ver,
|
||||
+ const char *devmem, u32 flags)
|
||||
{
|
||||
u8 *buf;
|
||||
|
||||
@@ -5231,7 +5232,7 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
|
||||
{
|
||||
if (num)
|
||||
printf("%u structures occupying %u bytes.\n",
|
||||
- num, len);
|
||||
+ num, *len);
|
||||
if (!(opt.flags & FLAG_FROM_DUMP))
|
||||
printf("Table at 0x%08llX.\n",
|
||||
(unsigned long long)base);
|
||||
@@ -5249,19 +5250,19 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
|
||||
* would be the result of the kernel truncating the table on
|
||||
* parse error.
|
||||
*/
|
||||
- size_t size = len;
|
||||
+ size_t size = *len;
|
||||
buf = read_file(flags & FLAG_NO_FILE_OFFSET ? 0 : base,
|
||||
&size, devmem);
|
||||
- if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)len)
|
||||
+ if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)*len)
|
||||
{
|
||||
fprintf(stderr, "Wrong DMI structures length: %u bytes "
|
||||
"announced, only %lu bytes available.\n",
|
||||
- len, (unsigned long)size);
|
||||
+ *len, (unsigned long)size);
|
||||
}
|
||||
- len = size;
|
||||
+ *len = size;
|
||||
}
|
||||
else
|
||||
- buf = mem_chunk(base, len, devmem);
|
||||
+ buf = mem_chunk(base, *len, devmem);
|
||||
|
||||
if (buf == NULL)
|
||||
{
|
||||
@@ -5271,15 +5272,9 @@ static void dmi_table(off_t base, u32 len, u16 num, u32 ver, const char *devmem,
|
||||
fprintf(stderr,
|
||||
"Try compiling dmidecode with -DUSE_MMAP.\n");
|
||||
#endif
|
||||
- return;
|
||||
}
|
||||
|
||||
- if (opt.flags & FLAG_DUMP_BIN)
|
||||
- dmi_table_dump(buf, len);
|
||||
- else
|
||||
- dmi_table_decode(buf, len, num, ver >> 8, flags);
|
||||
-
|
||||
- free(buf);
|
||||
+ return buf;
|
||||
}
|
||||
|
||||
|
||||
@@ -5314,8 +5309,9 @@ static void overwrite_smbios3_address(u8 *buf)
|
||||
|
||||
static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
{
|
||||
- u32 ver;
|
||||
+ u32 ver, len;
|
||||
u64 offset;
|
||||
+ u8 *table;
|
||||
|
||||
/* Don't let checksum run beyond the buffer */
|
||||
if (buf[0x06] > 0x20)
|
||||
@@ -5341,8 +5337,12 @@ static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
- dmi_table(((off_t)offset.h << 32) | offset.l,
|
||||
- DWORD(buf + 0x0C), 0, ver, devmem, flags | FLAG_STOP_AT_EOT);
|
||||
+ /* Maximum length, may get trimmed */
|
||||
+ len = DWORD(buf + 0x0C);
|
||||
+ table = dmi_table_get(((off_t)offset.h << 32) | offset.l, &len, 0, ver,
|
||||
+ devmem, flags | FLAG_STOP_AT_EOT);
|
||||
+ if (table == NULL)
|
||||
+ return 1;
|
||||
|
||||
if (opt.flags & FLAG_DUMP_BIN)
|
||||
{
|
||||
@@ -5351,18 +5351,28 @@ static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
memcpy(crafted, buf, 32);
|
||||
overwrite_smbios3_address(crafted);
|
||||
|
||||
+ dmi_table_dump(table, len);
|
||||
if (!(opt.flags & FLAG_QUIET))
|
||||
printf("# Writing %d bytes to %s.\n", crafted[0x06],
|
||||
opt.dumpfile);
|
||||
write_dump(0, crafted[0x06], crafted, opt.dumpfile, 1);
|
||||
}
|
||||
+ else
|
||||
+ {
|
||||
+ dmi_table_decode(table, len, 0, ver >> 8,
|
||||
+ flags | FLAG_STOP_AT_EOT);
|
||||
+ }
|
||||
+
|
||||
+ free(table);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
{
|
||||
- u16 ver;
|
||||
+ u16 ver, num;
|
||||
+ u32 len;
|
||||
+ u8 *table;
|
||||
|
||||
/* Don't let checksum run beyond the buffer */
|
||||
if (buf[0x05] > 0x20)
|
||||
@@ -5402,8 +5412,13 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
printf("SMBIOS %u.%u present.\n",
|
||||
ver >> 8, ver & 0xFF);
|
||||
|
||||
- dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C),
|
||||
- ver << 8, devmem, flags);
|
||||
+ /* Maximum length, may get trimmed */
|
||||
+ len = WORD(buf + 0x16);
|
||||
+ num = WORD(buf + 0x1C);
|
||||
+ table = dmi_table_get(DWORD(buf + 0x18), &len, num, ver << 8,
|
||||
+ devmem, flags);
|
||||
+ if (table == NULL)
|
||||
+ return 1;
|
||||
|
||||
if (opt.flags & FLAG_DUMP_BIN)
|
||||
{
|
||||
@@ -5412,27 +5427,43 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
memcpy(crafted, buf, 32);
|
||||
overwrite_dmi_address(crafted + 0x10);
|
||||
|
||||
+ dmi_table_dump(table, len);
|
||||
if (!(opt.flags & FLAG_QUIET))
|
||||
printf("# Writing %d bytes to %s.\n", crafted[0x05],
|
||||
opt.dumpfile);
|
||||
write_dump(0, crafted[0x05], crafted, opt.dumpfile, 1);
|
||||
}
|
||||
+ else
|
||||
+ {
|
||||
+ dmi_table_decode(table, len, num, ver, flags);
|
||||
+ }
|
||||
+
|
||||
+ free(table);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int legacy_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
{
|
||||
+ u16 ver, num;
|
||||
+ u32 len;
|
||||
+ u8 *table;
|
||||
+
|
||||
if (!checksum(buf, 0x0F))
|
||||
return 0;
|
||||
|
||||
+ ver = ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F);
|
||||
if (!(opt.flags & FLAG_QUIET))
|
||||
printf("Legacy DMI %u.%u present.\n",
|
||||
buf[0x0E] >> 4, buf[0x0E] & 0x0F);
|
||||
|
||||
- dmi_table(DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C),
|
||||
- ((buf[0x0E] & 0xF0) << 12) + ((buf[0x0E] & 0x0F) << 8),
|
||||
- devmem, flags);
|
||||
+ /* Maximum length, may get trimmed */
|
||||
+ len = WORD(buf + 0x06);
|
||||
+ num = WORD(buf + 0x0C);
|
||||
+ table = dmi_table_get(DWORD(buf + 0x08), &len, num, ver << 8,
|
||||
+ devmem, flags);
|
||||
+ if (table == NULL)
|
||||
+ return 1;
|
||||
|
||||
if (opt.flags & FLAG_DUMP_BIN)
|
||||
{
|
||||
@@ -5441,11 +5472,18 @@ static int legacy_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
memcpy(crafted, buf, 16);
|
||||
overwrite_dmi_address(crafted);
|
||||
|
||||
+ dmi_table_dump(table, len);
|
||||
if (!(opt.flags & FLAG_QUIET))
|
||||
printf("# Writing %d bytes to %s.\n", 0x0F,
|
||||
opt.dumpfile);
|
||||
write_dump(0, 0x0F, crafted, opt.dumpfile, 1);
|
||||
}
|
||||
+ else
|
||||
+ {
|
||||
+ dmi_table_decode(table, len, num, ver, flags);
|
||||
+ }
|
||||
+
|
||||
+ free(table);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
From 58e8a07b1aef0e53af1642b30248255e53e42790 Mon Sep 17 00:00:00 2001
|
||||
From: Jean Delvare <jdelvare@suse.de>
|
||||
Date: Mon, 20 Feb 2023 14:53:25 +0100
|
||||
Subject: [PATCH] dmidecode: Write the whole dump file at once
|
||||
|
||||
When option --dump-bin is used, write the whole dump file at once,
|
||||
instead of opening and closing the file separately for the table
|
||||
and then for the entry point.
|
||||
|
||||
As the file writing function is no longer generic, it gets moved
|
||||
from util.c to dmidecode.c.
|
||||
|
||||
One minor functional change resulting from the new implementation is
|
||||
that the entry point is written first now, so the messages printed
|
||||
are swapped.
|
||||
|
||||
CVE: CVE-2023-30630
|
||||
Upstream-Status: Backport [https://git.savannah.nongnu.org/cgit/dmidecode.git/commit/?id=d8cfbc808f38]
|
||||
|
||||
Backport Changes:
|
||||
- In the file dmidecode.c, the commit [2241f1d] in v3.3 introduces
|
||||
pr_info(). This is backported to printf() as per v3.2.
|
||||
|
||||
Signed-off-by: Jean Delvare <jdelvare@suse.de>
|
||||
Reviewed-by: Jerry Hoemann <jerry.hoemann@hpe.com>
|
||||
(cherry picked from commit d8cfbc808f387e87091c25e7d5b8c2bb348bb206)
|
||||
Signed-off-by: Dhairya Nagodra <dnagodra@cisco.com>
|
||||
|
||||
---
|
||||
dmidecode.c | 69 +++++++++++++++++++++++++++++++++++++++--------------
|
||||
util.c | 40 -------------------------------
|
||||
util.h | 1 -
|
||||
3 files changed, 51 insertions(+), 59 deletions(-)
|
||||
|
||||
diff --git a/dmidecode.c b/dmidecode.c
|
||||
index d6eedd1..b91e53b 100644
|
||||
--- a/dmidecode.c
|
||||
+++ b/dmidecode.c
|
||||
@@ -5094,11 +5094,56 @@ static void dmi_table_string(const struct dmi_header *h, const u8 *data, u16 ver
|
||||
}
|
||||
}
|
||||
|
||||
-static void dmi_table_dump(const u8 *buf, u32 len)
|
||||
+static int dmi_table_dump(const u8 *ep, u32 ep_len, const u8 *table,
|
||||
+ u32 table_len)
|
||||
{
|
||||
+ FILE *f;
|
||||
+
|
||||
+ f = fopen(opt.dumpfile, "wb");
|
||||
+ if (!f)
|
||||
+ {
|
||||
+ fprintf(stderr, "%s: ", opt.dumpfile);
|
||||
+ perror("fopen");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (!(opt.flags & FLAG_QUIET))
|
||||
+ printf("# Writing %d bytes to %s.\n", ep_len, opt.dumpfile);
|
||||
+ if (fwrite(ep, ep_len, 1, f) != 1)
|
||||
+ {
|
||||
+ fprintf(stderr, "%s: ", opt.dumpfile);
|
||||
+ perror("fwrite");
|
||||
+ goto err_close;
|
||||
+ }
|
||||
+
|
||||
+ if (fseek(f, 32, SEEK_SET) != 0)
|
||||
+ {
|
||||
+ fprintf(stderr, "%s: ", opt.dumpfile);
|
||||
+ perror("fseek");
|
||||
+ goto err_close;
|
||||
+ }
|
||||
+
|
||||
if (!(opt.flags & FLAG_QUIET))
|
||||
- printf("# Writing %d bytes to %s.\n", len, opt.dumpfile);
|
||||
- write_dump(32, len, buf, opt.dumpfile, 0);
|
||||
+ printf("# Writing %d bytes to %s.\n", table_len, opt.dumpfile);
|
||||
+ if (fwrite(table, table_len, 1, f) != 1)
|
||||
+ {
|
||||
+ fprintf(stderr, "%s: ", opt.dumpfile);
|
||||
+ perror("fwrite");
|
||||
+ goto err_close;
|
||||
+ }
|
||||
+
|
||||
+ if (fclose(f))
|
||||
+ {
|
||||
+ fprintf(stderr, "%s: ", opt.dumpfile);
|
||||
+ perror("fclose");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+
|
||||
+err_close:
|
||||
+ fclose(f);
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
|
||||
@@ -5351,11 +5396,7 @@ static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
memcpy(crafted, buf, 32);
|
||||
overwrite_smbios3_address(crafted);
|
||||
|
||||
- dmi_table_dump(table, len);
|
||||
- if (!(opt.flags & FLAG_QUIET))
|
||||
- printf("# Writing %d bytes to %s.\n", crafted[0x06],
|
||||
- opt.dumpfile);
|
||||
- write_dump(0, crafted[0x06], crafted, opt.dumpfile, 1);
|
||||
+ dmi_table_dump(crafted, crafted[0x06], table, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -5427,11 +5468,7 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
memcpy(crafted, buf, 32);
|
||||
overwrite_dmi_address(crafted + 0x10);
|
||||
|
||||
- dmi_table_dump(table, len);
|
||||
- if (!(opt.flags & FLAG_QUIET))
|
||||
- printf("# Writing %d bytes to %s.\n", crafted[0x05],
|
||||
- opt.dumpfile);
|
||||
- write_dump(0, crafted[0x05], crafted, opt.dumpfile, 1);
|
||||
+ dmi_table_dump(crafted, crafted[0x05], table, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -5472,11 +5509,7 @@ static int legacy_decode(u8 *buf, const char *devmem, u32 flags)
|
||||
memcpy(crafted, buf, 16);
|
||||
overwrite_dmi_address(crafted);
|
||||
|
||||
- dmi_table_dump(table, len);
|
||||
- if (!(opt.flags & FLAG_QUIET))
|
||||
- printf("# Writing %d bytes to %s.\n", 0x0F,
|
||||
- opt.dumpfile);
|
||||
- write_dump(0, 0x0F, crafted, opt.dumpfile, 1);
|
||||
+ dmi_table_dump(crafted, 0x0F, table, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
diff --git a/util.c b/util.c
|
||||
index eeffdae..2e1931c 100644
|
||||
--- a/util.c
|
||||
+++ b/util.c
|
||||
@@ -247,46 +247,6 @@ out:
|
||||
return p;
|
||||
}
|
||||
|
||||
-int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add)
|
||||
-{
|
||||
- FILE *f;
|
||||
-
|
||||
- f = fopen(dumpfile, add ? "r+b" : "wb");
|
||||
- if (!f)
|
||||
- {
|
||||
- fprintf(stderr, "%s: ", dumpfile);
|
||||
- perror("fopen");
|
||||
- return -1;
|
||||
- }
|
||||
-
|
||||
- if (fseek(f, base, SEEK_SET) != 0)
|
||||
- {
|
||||
- fprintf(stderr, "%s: ", dumpfile);
|
||||
- perror("fseek");
|
||||
- goto err_close;
|
||||
- }
|
||||
-
|
||||
- if (fwrite(data, len, 1, f) != 1)
|
||||
- {
|
||||
- fprintf(stderr, "%s: ", dumpfile);
|
||||
- perror("fwrite");
|
||||
- goto err_close;
|
||||
- }
|
||||
-
|
||||
- if (fclose(f))
|
||||
- {
|
||||
- fprintf(stderr, "%s: ", dumpfile);
|
||||
- perror("fclose");
|
||||
- return -1;
|
||||
- }
|
||||
-
|
||||
- return 0;
|
||||
-
|
||||
-err_close:
|
||||
- fclose(f);
|
||||
- return -1;
|
||||
-}
|
||||
-
|
||||
/* Returns end - start + 1, assuming start < end */
|
||||
u64 u64_range(u64 start, u64 end)
|
||||
{
|
||||
diff --git a/util.h b/util.h
|
||||
index 3094cf8..ef24eb9 100644
|
||||
--- a/util.h
|
||||
+++ b/util.h
|
||||
@@ -27,5 +27,4 @@
|
||||
int checksum(const u8 *buf, size_t len);
|
||||
void *read_file(off_t base, size_t *len, const char *filename);
|
||||
void *mem_chunk(off_t base, size_t len, const char *devmem);
|
||||
-int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add);
|
||||
u64 u64_range(u64 start, u64 end);
|
||||
@@ -0,0 +1,62 @@
|
||||
From b7dacccff32294ea522df32a9391d0218e7600ea Mon Sep 17 00:00:00 2001
|
||||
From: Jean Delvare <jdelvare@suse.de>
|
||||
Date: Mon, 20 Feb 2023 14:53:31 +0100
|
||||
Subject: [PATCH] dmidecode: Do not let --dump-bin overwrite an existing file
|
||||
|
||||
Make sure that the file passed to option --dump-bin does not already
|
||||
exist. In practice, it is rather unlikely that an honest user would
|
||||
want to overwrite an existing dump file, while this possibility
|
||||
could be used by a rogue user to corrupt a system file.
|
||||
|
||||
CVE: CVE-2023-30630
|
||||
Upstream-Status: Backport [https://git.savannah.nongnu.org/cgit/dmidecode.git/commit/?id=6ca381c1247c]
|
||||
|
||||
Backport Changes:
|
||||
- Ignored changes in man/dmidecode.8 file.
|
||||
|
||||
Signed-off-by: Jean Delvare <jdelvare@suse.de>
|
||||
Reviewed-by: Jerry Hoemann <jerry.hoemann@hpe.com>
|
||||
(cherry picked from commit 6ca381c1247c81f74e1ca4e7706f70bdda72e6f2)
|
||||
Signed-off-by: Dhairya Nagodra <dnagodra@cisco.com>
|
||||
|
||||
---
|
||||
dmidecode.c | 14 ++++++++++++--
|
||||
1 file changed, 12 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/dmidecode.c b/dmidecode.c
|
||||
index b91e53b..846d9a1 100644
|
||||
--- a/dmidecode.c
|
||||
+++ b/dmidecode.c
|
||||
@@ -60,6 +60,7 @@
|
||||
* https://www.dmtf.org/sites/default/files/DSP0270_1.0.1.pdf
|
||||
*/
|
||||
|
||||
+#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
@@ -5097,13 +5098,22 @@ static void dmi_table_string(const struct dmi_header *h, const u8 *data, u16 ver
|
||||
static int dmi_table_dump(const u8 *ep, u32 ep_len, const u8 *table,
|
||||
u32 table_len)
|
||||
{
|
||||
+ int fd;
|
||||
FILE *f;
|
||||
|
||||
- f = fopen(opt.dumpfile, "wb");
|
||||
+ fd = open(opt.dumpfile, O_WRONLY|O_CREAT|O_EXCL, 0666);
|
||||
+ if (fd == -1)
|
||||
+ {
|
||||
+ fprintf(stderr, "%s: ", opt.dumpfile);
|
||||
+ perror("open");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ f = fdopen(fd, "wb");
|
||||
if (!f)
|
||||
{
|
||||
fprintf(stderr, "%s: ", opt.dumpfile);
|
||||
- perror("fopen");
|
||||
+ perror("fdopen");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=b234ee4d69f5fce4486a80fdaf4a4263"
|
||||
|
||||
SRC_URI = "${SAVANNAH_NONGNU_MIRROR}/dmidecode/${BP}.tar.xz \
|
||||
file://0001-Committing-changes-from-do_unpack_extra.patch \
|
||||
file://CVE-2023-30630-dependent_p1.patch \
|
||||
file://CVE-2023-30630-dependent_p2.patch \
|
||||
file://CVE-2023-30630.patch \
|
||||
"
|
||||
|
||||
COMPATIBLE_HOST = "(i.86|x86_64|aarch64|arm|powerpc|powerpc64).*-linux"
|
||||
|
||||
@@ -34,6 +34,7 @@ SRC_URI = "https://sourceware.org/elfutils/ftp/${PV}/${BP}.tar.bz2 \
|
||||
file://0001-ppc_initreg.c-Incliude-asm-ptrace.h-for-pt_regs-defi.patch \
|
||||
file://run-ptest \
|
||||
file://ptest.patch \
|
||||
file://CVE-2021-33294.patch \
|
||||
"
|
||||
SRC_URI_append_libc-musl = " \
|
||||
file://0001-musl-obstack-fts.patch \
|
||||
|
||||
72
meta/recipes-devtools/elfutils/files/CVE-2021-33294.patch
Normal file
72
meta/recipes-devtools/elfutils/files/CVE-2021-33294.patch
Normal file
@@ -0,0 +1,72 @@
|
||||
From 480b6fa3662ba8ffeee274bf0d37423413c01e55 Mon Sep 17 00:00:00 2001
|
||||
From: Mark Wielaard <mark@klomp.org>
|
||||
Date: Wed, 3 Mar 2021 21:40:53 +0100
|
||||
Subject: [PATCH] readelf: Sanity check verneed and verdef offsets in handle_symtab.
|
||||
|
||||
We are going through vna_next, vn_next and vd_next in a while loop.
|
||||
Make sure that all offsets are sane. We don't want things to wrap
|
||||
around so we go in cycles.
|
||||
|
||||
https://sourceware.org/bugzilla/show_bug.cgi?id=27501
|
||||
|
||||
Signed-off-by: Mark Wielaard <mark@klomp.org>
|
||||
|
||||
Upstream-Status: Backport [https://sourceware.org/git/?p=elfutils.git;a=commit;h=480b6fa3662ba8ffeee274bf0d37423413c01e55]
|
||||
CVE: CVE-2021-33294
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/ChangeLog | 5 +++++
|
||||
src/readelf.c | 10 +++++++++-
|
||||
2 files changed, 14 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/ChangeLog b/src/ChangeLog
|
||||
index 6af977e..f0d9e39 100644
|
||||
--- a/src/ChangeLog
|
||||
+++ b/src/ChangeLog
|
||||
@@ -1,3 +1,8 @@
|
||||
+2021-03-03 Mark Wielaard <mark@klomp.org>
|
||||
+
|
||||
+ * readelf.c (handle_symtab): Sanity check verneed vna_next,
|
||||
+ vn_next and verdef vd_next offsets.
|
||||
+
|
||||
2019-11-26 Mark Wielaard <mark@klomp.org>
|
||||
|
||||
* Makefile.am (BUILD_STATIC): Add libraries needed for libdw.
|
||||
diff --git a/src/readelf.c b/src/readelf.c
|
||||
index 5994615..ab7a1c1 100644
|
||||
--- a/src/readelf.c
|
||||
+++ b/src/readelf.c
|
||||
@@ -2550,7 +2550,9 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
|
||||
&vernaux_mem);
|
||||
while (vernaux != NULL
|
||||
&& vernaux->vna_other != *versym
|
||||
- && vernaux->vna_next != 0)
|
||||
+ && vernaux->vna_next != 0
|
||||
+ && (verneed_data->d_size - vna_offset
|
||||
+ >= vernaux->vna_next))
|
||||
{
|
||||
/* Update the offset. */
|
||||
vna_offset += vernaux->vna_next;
|
||||
@@ -2567,6 +2569,9 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
|
||||
/* Found it. */
|
||||
break;
|
||||
|
||||
+ if (verneed_data->d_size - vn_offset < verneed->vn_next)
|
||||
+ break;
|
||||
+
|
||||
vn_offset += verneed->vn_next;
|
||||
verneed = (verneed->vn_next == 0
|
||||
? NULL
|
||||
@@ -2602,6 +2607,9 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
|
||||
/* Found the definition. */
|
||||
break;
|
||||
|
||||
+ if (verdef_data->d_size - vd_offset < verdef->vd_next)
|
||||
+ break;
|
||||
+
|
||||
vd_offset += verdef->vd_next;
|
||||
verdef = (verdef->vd_next == 0
|
||||
? NULL
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@@ -70,6 +70,7 @@ SRC_URI = "\
|
||||
file://0038-gentypes-genmodes-Do-not-use-__LINE__-for-maintainin.patch \
|
||||
file://0039-process_alt_operands-Don-t-match-user-defined-regs-o.patch \
|
||||
file://0002-libstdc-Fix-inconsistent-noexcept-specific-for-valar.patch \
|
||||
file://CVE-2023-4039.patch \
|
||||
"
|
||||
S = "${TMPDIR}/work-shared/gcc-${PV}-${PR}/gcc-${PV}"
|
||||
SRC_URI[sha256sum] = "27769f64ef1d4cd5e2be8682c0c93f9887983e6cfd1a927ce5a0a2915a95cf8f"
|
||||
|
||||
1506
meta/recipes-devtools/gcc/gcc-9.5/CVE-2023-4039.patch
Normal file
1506
meta/recipes-devtools/gcc/gcc-9.5/CVE-2023-4039.patch
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,7 @@ SRC_URI = "${GNU_MIRROR}/gdb/gdb-${PV}.tar.xz \
|
||||
file://0009-resolve-restrict-keyword-conflict.patch \
|
||||
file://0010-Fix-invalid-sigprocmask-call.patch \
|
||||
file://0011-gdbserver-ctrl-c-handling.patch \
|
||||
file://0012-CVE-2023-39128.patch \
|
||||
"
|
||||
SRC_URI[md5sum] = "f7e9f6236c425097d9e5f18a6ac40655"
|
||||
SRC_URI[sha256sum] = "699e0ec832fdd2f21c8266171ea5bf44024bd05164fdf064e4d10cc4cf0d1737"
|
||||
|
||||
75
meta/recipes-devtools/gdb/gdb/0012-CVE-2023-39128.patch
Normal file
75
meta/recipes-devtools/gdb/gdb/0012-CVE-2023-39128.patch
Normal file
@@ -0,0 +1,75 @@
|
||||
From 033bc52bb6190393c8eed80925fa78cc35b40c6d Mon Sep 17 00:00:00 2001
|
||||
From: Tom Tromey <tromey@adacore.com>
|
||||
Date: Wed, 16 Aug 2023 11:29:19 -0600
|
||||
Subject: [PATCH] Avoid buffer overflow in ada_decode
|
||||
|
||||
A bug report pointed out a buffer overflow in ada_decode, which Keith
|
||||
helpfully analyzed. ada_decode had a logic error when the input was
|
||||
all digits. While this isn't valid -- and would probably only appear
|
||||
in fuzzer tests -- it still should be handled properly.
|
||||
|
||||
This patch adds a missing bounds check. Tested with the self-tests in
|
||||
an asan build.
|
||||
|
||||
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30639
|
||||
Reviewed-by: Keith Seitz <keiths@redhat.com>
|
||||
|
||||
Upstream-Status: Backport from [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=033bc52bb6190393c8eed80925fa78cc35b40c6d]
|
||||
CVE: CVE-2023-39128
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
gdb/ada-lang.c | 19 ++++++++++++++++++-
|
||||
1 file changed, 18 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
|
||||
index 0c2d4fc..40852b6 100644
|
||||
--- a/gdb/ada-lang.c
|
||||
+++ b/gdb/ada-lang.c
|
||||
@@ -56,6 +56,7 @@
|
||||
#include "cli/cli-utils.h"
|
||||
#include "gdbsupport/function-view.h"
|
||||
#include "gdbsupport/byte-vector.h"
|
||||
+#include "gdbsupport/selftest.h"
|
||||
#include <algorithm>
|
||||
|
||||
/* Define whether or not the C operator '/' truncates towards zero for
|
||||
@@ -1184,7 +1185,7 @@ ada_decode (const char *encoded)
|
||||
i -= 1;
|
||||
if (i > 1 && encoded[i] == '_' && encoded[i - 1] == '_')
|
||||
len0 = i - 1;
|
||||
- else if (encoded[i] == '$')
|
||||
+ else if (i >= 0 && encoded[i] == '$')
|
||||
len0 = i;
|
||||
}
|
||||
|
||||
@@ -1350,6 +1351,18 @@ Suppress:
|
||||
|
||||
}
|
||||
|
||||
+#ifdef GDB_SELF_TEST
|
||||
+
|
||||
+static void
|
||||
+ada_decode_tests ()
|
||||
+{
|
||||
+ /* This isn't valid, but used to cause a crash. PR gdb/30639. The
|
||||
+ result does not really matter very much. */
|
||||
+ SELF_CHECK (ada_decode ("44") == "44");
|
||||
+}
|
||||
+
|
||||
+#endif
|
||||
+
|
||||
/* Table for keeping permanent unique copies of decoded names. Once
|
||||
allocated, names in this table are never released. While this is a
|
||||
storage leak, it should not be significant unless there are massive
|
||||
@@ -14345,4 +14358,8 @@ DWARF attribute."),
|
||||
gdb::observers::new_objfile.attach (ada_new_objfile_observer);
|
||||
gdb::observers::free_objfile.attach (ada_free_objfile_observer);
|
||||
gdb::observers::inferior_exit.attach (ada_inferior_exit);
|
||||
+
|
||||
+#ifdef GDB_SELF_TEST
|
||||
+ selftests::register_test ("ada-decode", ada_decode_tests);
|
||||
+#endif
|
||||
}
|
||||
--
|
||||
2.24.4
|
||||
|
||||
@@ -60,7 +60,10 @@ SRC_URI += "\
|
||||
file://CVE-2023-24534.patch \
|
||||
file://CVE-2023-24538-1.patch \
|
||||
file://CVE-2023-24538-2.patch \
|
||||
file://CVE-2023-24538-3.patch \
|
||||
file://CVE-2023-24538_3.patch \
|
||||
file://CVE-2023-24538_4.patch \
|
||||
file://CVE-2023-24538_5.patch \
|
||||
file://CVE-2023-24538_6.patch \
|
||||
file://CVE-2023-24539.patch \
|
||||
file://CVE-2023-24540.patch \
|
||||
file://CVE-2023-29405-1.patch \
|
||||
@@ -68,6 +71,17 @@ SRC_URI += "\
|
||||
file://CVE-2023-29402.patch \
|
||||
file://CVE-2023-29404.patch \
|
||||
file://CVE-2023-29400.patch \
|
||||
file://CVE-2023-29406.patch \
|
||||
file://CVE-2023-29409.patch \
|
||||
file://CVE-2022-41725-pre1.patch \
|
||||
file://CVE-2022-41725-pre2.patch \
|
||||
file://CVE-2022-41725-pre3.patch \
|
||||
file://CVE-2022-41725.patch \
|
||||
file://CVE-2023-24536_1.patch \
|
||||
file://CVE-2023-24536_2.patch \
|
||||
file://CVE-2023-24536_3.patch \
|
||||
file://CVE-2023-39318.patch \
|
||||
file://CVE-2023-39319.patch \
|
||||
"
|
||||
|
||||
SRC_URI_append_libc-musl = " file://0009-ld-replace-glibc-dynamic-linker-with-musl.patch"
|
||||
|
||||
85
meta/recipes-devtools/go/go-1.14/CVE-2022-41725-pre1.patch
Normal file
85
meta/recipes-devtools/go/go-1.14/CVE-2022-41725-pre1.patch
Normal file
@@ -0,0 +1,85 @@
|
||||
From 874b3132a84cf76da6a48978826c04c380a37a50 Mon Sep 17 00:00:00 2001
|
||||
From: avivklas <avivklas@gmail.com>
|
||||
Date: Fri, 7 Aug 2020 21:50:12 +0300
|
||||
Subject: [PATCH] mime/multipart: return overflow errors in Reader.ReadForm
|
||||
|
||||
Updates Reader.ReadForm to check for overflow errors that may
|
||||
result from a leeway addition of 10MiB to the input argument
|
||||
maxMemory.
|
||||
|
||||
Fixes #40430
|
||||
|
||||
Change-Id: I510b8966c95c51d04695ba9d08fcfe005fd11a5d
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/247477
|
||||
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
|
||||
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
|
||||
Trust: Emmanuel Odeke <emm.odeke@gmail.com>
|
||||
TryBot-Result: Go Bot <gobot@golang.org>
|
||||
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/874b3132a84cf76da6a48978826c04c380a37a50]
|
||||
CVE: CVE-2022-41725 #Dependency Patch1
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/mime/multipart/formdata.go | 4 ++++
|
||||
src/mime/multipart/formdata_test.go | 18 ++++++++++++++++++
|
||||
2 files changed, 22 insertions(+)
|
||||
|
||||
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go
|
||||
index 832d0ad693666..4eb31012941ac 100644
|
||||
--- a/src/mime/multipart/formdata.go
|
||||
+++ b/src/mime/multipart/formdata.go
|
||||
@@ -7,6 +7,7 @@ package multipart
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
+ "fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/textproto"
|
||||
@@ -41,6 +42,9 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
|
||||
// Reserve an additional 10 MB for non-file parts.
|
||||
maxValueBytes := maxMemory + int64(10<<20)
|
||||
+ if maxValueBytes <= 0 {
|
||||
+ return nil, fmt.Errorf("multipart: integer overflow from maxMemory(%d) + 10MiB for non-file parts", maxMemory)
|
||||
+ }
|
||||
for {
|
||||
p, err := r.NextPart()
|
||||
if err == io.EOF {
|
||||
diff --git a/src/mime/multipart/formdata_test.go b/src/mime/multipart/formdata_test.go
|
||||
index 7d756c8c244a0..7112e0d3727fe 100644
|
||||
--- a/src/mime/multipart/formdata_test.go
|
||||
+++ b/src/mime/multipart/formdata_test.go
|
||||
@@ -7,6 +7,7 @@ package multipart
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
+ "math"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -52,6 +53,23 @@ func TestReadFormWithNamelessFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
+// Issue 40430: Ensure that we report integer overflows in additions of maxMemory,
|
||||
+// instead of silently and subtly failing without indication.
|
||||
+func TestReadFormMaxMemoryOverflow(t *testing.T) {
|
||||
+ b := strings.NewReader(strings.ReplaceAll(messageWithTextContentType, "\n", "\r\n"))
|
||||
+ r := NewReader(b, boundary)
|
||||
+ f, err := r.ReadForm(math.MaxInt64)
|
||||
+ if err == nil {
|
||||
+ t.Fatal("Unexpected a non-nil error")
|
||||
+ }
|
||||
+ if f != nil {
|
||||
+ t.Fatalf("Unexpected returned a non-nil form: %v\n", f)
|
||||
+ }
|
||||
+ if g, w := err.Error(), "integer overflow from maxMemory"; !strings.Contains(g, w) {
|
||||
+ t.Errorf(`Error mismatch\n%q\ndid not contain\n%q`, g, w)
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
func TestReadFormWithTextContentType(t *testing.T) {
|
||||
// From https://github.com/golang/go/issues/24041
|
||||
b := strings.NewReader(strings.ReplaceAll(messageWithTextContentType, "\n", "\r\n"))
|
||||
97
meta/recipes-devtools/go/go-1.14/CVE-2022-41725-pre2.patch
Normal file
97
meta/recipes-devtools/go/go-1.14/CVE-2022-41725-pre2.patch
Normal file
@@ -0,0 +1,97 @@
|
||||
From 4e5a313524da62600eb59dbf98624cfe946456f8 Mon Sep 17 00:00:00 2001
|
||||
From: Emmanuel T Odeke <emmanuel@orijtech.com>
|
||||
Date: Tue, 20 Oct 2020 04:11:12 -0700
|
||||
Subject: [PATCH] net/http: test that ParseMultipartForm catches overflows
|
||||
|
||||
Tests that if the combination of:
|
||||
* HTTP multipart file payload size
|
||||
* ParseMultipartForm's maxMemory parameter
|
||||
* the internal leeway buffer size of 10MiB
|
||||
|
||||
overflows, then we'll report an overflow instead of silently
|
||||
passing.
|
||||
|
||||
Reapplies and fixes CL 254977, which was reverted in CL 263658.
|
||||
|
||||
The prior test lacked a res.Body.Close(), so fixed that and
|
||||
added a leaked Transport check to verify correctness.
|
||||
|
||||
Updates 40430.
|
||||
|
||||
Change-Id: I3c0f7ef43d621f6eb00f07755f04f9f36c51f98f
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/263817
|
||||
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
|
||||
TryBot-Result: Go Bot <gobot@golang.org>
|
||||
Reviewed-by: Bryan C. Mills <bcmills@google.com>
|
||||
Trust: Damien Neil <dneil@google.com>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/4e5a313524da62600eb59dbf98624cfe946456f8]
|
||||
CVE: CVE-2022-41725 #Dependency Patch2
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/net/http/request_test.go | 45 ++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 45 insertions(+)
|
||||
|
||||
diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go
|
||||
index b4ef472e71229..19526b9ad791a 100644
|
||||
--- a/src/net/http/request_test.go
|
||||
+++ b/src/net/http/request_test.go
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
+ "math"
|
||||
"mime/multipart"
|
||||
. "net/http"
|
||||
"net/http/httptest"
|
||||
@@ -245,6 +246,50 @@ func TestParseMultipartForm(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
+// Issue #40430: Test that if maxMemory for ParseMultipartForm when combined with
|
||||
+// the payload size and the internal leeway buffer size of 10MiB overflows, that we
|
||||
+// correctly return an error.
|
||||
+func TestMaxInt64ForMultipartFormMaxMemoryOverflow(t *testing.T) {
|
||||
+ defer afterTest(t)
|
||||
+
|
||||
+ payloadSize := 1 << 10
|
||||
+ cst := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, req *Request) {
|
||||
+ // The combination of:
|
||||
+ // MaxInt64 + payloadSize + (internal spare of 10MiB)
|
||||
+ // triggers the overflow. See issue https://golang.org/issue/40430/
|
||||
+ if err := req.ParseMultipartForm(math.MaxInt64); err != nil {
|
||||
+ Error(rw, err.Error(), StatusBadRequest)
|
||||
+ return
|
||||
+ }
|
||||
+ }))
|
||||
+ defer cst.Close()
|
||||
+ fBuf := new(bytes.Buffer)
|
||||
+ mw := multipart.NewWriter(fBuf)
|
||||
+ mf, err := mw.CreateFormFile("file", "myfile.txt")
|
||||
+ if err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ if _, err := mf.Write(bytes.Repeat([]byte("abc"), payloadSize)); err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ if err := mw.Close(); err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ req, err := NewRequest("POST", cst.URL, fBuf)
|
||||
+ if err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ req.Header.Set("Content-Type", mw.FormDataContentType())
|
||||
+ res, err := cst.Client().Do(req)
|
||||
+ if err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ res.Body.Close()
|
||||
+ if g, w := res.StatusCode, StatusBadRequest; g != w {
|
||||
+ t.Fatalf("Status code mismatch: got %d, want %d", g, w)
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
func TestRedirect_h1(t *testing.T) { testRedirect(t, h1Mode) }
|
||||
func TestRedirect_h2(t *testing.T) { testRedirect(t, h2Mode) }
|
||||
func testRedirect(t *testing.T, h2 bool) {
|
||||
98
meta/recipes-devtools/go/go-1.14/CVE-2022-41725-pre3.patch
Normal file
98
meta/recipes-devtools/go/go-1.14/CVE-2022-41725-pre3.patch
Normal file
@@ -0,0 +1,98 @@
|
||||
From 5246fa5e75b129a7dbd9722aa4de0cbaf7ceae43 Mon Sep 17 00:00:00 2001
|
||||
From: Russ Cox <rsc@golang.org>
|
||||
Date: Thu, 3 Dec 2020 09:45:07 -0500
|
||||
Subject: [PATCH] mime/multipart: handle ReadForm(math.MaxInt64) better
|
||||
|
||||
Returning an error about integer overflow is needlessly pedantic.
|
||||
The meaning of ReadForm(MaxInt64) is easily understood
|
||||
(accept a lot of data) and can be implemented.
|
||||
|
||||
Fixes #40430.
|
||||
|
||||
Change-Id: I8a522033dd9a2f9ad31dd2ad82cf08d553736ab9
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/275112
|
||||
Trust: Russ Cox <rsc@golang.org>
|
||||
Run-TryBot: Russ Cox <rsc@golang.org>
|
||||
TryBot-Result: Go Bot <gobot@golang.org>
|
||||
Reviewed-by: Ian Lance Taylor <iant@golang.org>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/5246fa5e75b129a7dbd9722aa4de0cbaf7ceae43]
|
||||
CVE: CVE-2022-41725 #Dependency Patch3
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/mime/multipart/formdata.go | 8 ++++++--
|
||||
src/mime/multipart/formdata_test.go | 14 +++++---------
|
||||
src/net/http/request_test.go | 2 +-
|
||||
3 files changed, 12 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go
|
||||
index 4eb31012941ac..9c42ea8c023b5 100644
|
||||
--- a/src/mime/multipart/formdata.go
|
||||
+++ b/src/mime/multipart/formdata.go
|
||||
@@ -7,9 +7,9 @@ package multipart
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
- "fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
+ "math"
|
||||
"net/textproto"
|
||||
"os"
|
||||
)
|
||||
@@ -43,7 +43,11 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
// Reserve an additional 10 MB for non-file parts.
|
||||
maxValueBytes := maxMemory + int64(10<<20)
|
||||
if maxValueBytes <= 0 {
|
||||
- return nil, fmt.Errorf("multipart: integer overflow from maxMemory(%d) + 10MiB for non-file parts", maxMemory)
|
||||
+ if maxMemory < 0 {
|
||||
+ maxValueBytes = 0
|
||||
+ } else {
|
||||
+ maxValueBytes = math.MaxInt64
|
||||
+ }
|
||||
}
|
||||
for {
|
||||
p, err := r.NextPart()
|
||||
diff --git a/src/mime/multipart/formdata_test.go b/src/mime/multipart/formdata_test.go
|
||||
index 7112e0d3727fe..e3a3a3eae8e15 100644
|
||||
--- a/src/mime/multipart/formdata_test.go
|
||||
+++ b/src/mime/multipart/formdata_test.go
|
||||
@@ -53,20 +53,16 @@ func TestReadFormWithNamelessFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
-// Issue 40430: Ensure that we report integer overflows in additions of maxMemory,
|
||||
-// instead of silently and subtly failing without indication.
|
||||
+// Issue 40430: Handle ReadForm(math.MaxInt64)
|
||||
func TestReadFormMaxMemoryOverflow(t *testing.T) {
|
||||
b := strings.NewReader(strings.ReplaceAll(messageWithTextContentType, "\n", "\r\n"))
|
||||
r := NewReader(b, boundary)
|
||||
f, err := r.ReadForm(math.MaxInt64)
|
||||
- if err == nil {
|
||||
- t.Fatal("Unexpected a non-nil error")
|
||||
- }
|
||||
- if f != nil {
|
||||
- t.Fatalf("Unexpected returned a non-nil form: %v\n", f)
|
||||
+ if err != nil {
|
||||
+ t.Fatalf("ReadForm(MaxInt64): %v", err)
|
||||
}
|
||||
- if g, w := err.Error(), "integer overflow from maxMemory"; !strings.Contains(g, w) {
|
||||
- t.Errorf(`Error mismatch\n%q\ndid not contain\n%q`, g, w)
|
||||
+ if f == nil {
|
||||
+ t.Fatal("ReadForm(MaxInt64): missing form")
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go
|
||||
index 19526b9ad791a..689498e19d5dd 100644
|
||||
--- a/src/net/http/request_test.go
|
||||
+++ b/src/net/http/request_test.go
|
||||
@@ -285,7 +285,7 @@ func TestMaxInt64ForMultipartFormMaxMemoryOverflow(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res.Body.Close()
|
||||
- if g, w := res.StatusCode, StatusBadRequest; g != w {
|
||||
+ if g, w := res.StatusCode, StatusOK; g != w {
|
||||
t.Fatalf("Status code mismatch: got %d, want %d", g, w)
|
||||
}
|
||||
}
|
||||
660
meta/recipes-devtools/go/go-1.14/CVE-2022-41725.patch
Normal file
660
meta/recipes-devtools/go/go-1.14/CVE-2022-41725.patch
Normal file
@@ -0,0 +1,660 @@
|
||||
From 5c55ac9bf1e5f779220294c843526536605f42ab Mon Sep 17 00:00:00 2001
|
||||
From: Damien Neil <dneil@google.com>
|
||||
Date: Wed, 25 Jan 2023 09:27:01 -0800
|
||||
Subject: [PATCH] [release-branch.go1.19] mime/multipart: limit memory/inode consumption of ReadForm
|
||||
|
||||
Reader.ReadForm is documented as storing "up to maxMemory bytes + 10MB"
|
||||
in memory. Parsed forms can consume substantially more memory than
|
||||
this limit, since ReadForm does not account for map entry overhead
|
||||
and MIME headers.
|
||||
|
||||
In addition, while the amount of disk memory consumed by ReadForm can
|
||||
be constrained by limiting the size of the parsed input, ReadForm will
|
||||
create one temporary file per form part stored on disk, potentially
|
||||
consuming a large number of inodes.
|
||||
|
||||
Update ReadForm's memory accounting to include part names,
|
||||
MIME headers, and map entry overhead.
|
||||
|
||||
Update ReadForm to store all on-disk file parts in a single
|
||||
temporary file.
|
||||
|
||||
Files returned by FileHeader.Open are documented as having a concrete
|
||||
type of *os.File when a file is stored on disk. The change to use a
|
||||
single temporary file for all parts means that this is no longer the
|
||||
case when a form contains more than a single file part stored on disk.
|
||||
|
||||
The previous behavior of storing each file part in a separate disk
|
||||
file may be reenabled with GODEBUG=multipartfiles=distinct.
|
||||
|
||||
Update Reader.NextPart and Reader.NextRawPart to set a 10MiB cap
|
||||
on the size of MIME headers.
|
||||
|
||||
Thanks to Jakob Ackermann (@das7pad) for reporting this issue.
|
||||
|
||||
Updates #58006
|
||||
Fixes #58362
|
||||
Fixes CVE-2022-41725
|
||||
|
||||
Change-Id: Ibd780a6c4c83ac8bcfd3cbe344f042e9940f2eab
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1714276
|
||||
Reviewed-by: Julie Qiu <julieqiu@google.com>
|
||||
TryBot-Result: Security TryBots <security-trybots@go-security-trybots.iam.gserviceaccount.com>
|
||||
Reviewed-by: Roland Shoemaker <bracewell@google.com>
|
||||
Run-TryBot: Damien Neil <dneil@google.com>
|
||||
(cherry picked from commit ed4664330edcd91b24914c9371c377c132dbce8c)
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1728949
|
||||
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
|
||||
Run-TryBot: Roland Shoemaker <bracewell@google.com>
|
||||
Reviewed-by: Damien Neil <dneil@google.com>
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/468116
|
||||
TryBot-Result: Gopher Robot <gobot@golang.org>
|
||||
Reviewed-by: Than McIntosh <thanm@google.com>
|
||||
Run-TryBot: Michael Pratt <mpratt@google.com>
|
||||
Auto-Submit: Michael Pratt <mpratt@google.com>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/5c55ac9bf1e5f779220294c843526536605f42ab]
|
||||
CVE: CVE-2022-41725
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/mime/multipart/formdata.go | 132 ++++++++++++++++++++-----
|
||||
src/mime/multipart/formdata_test.go | 140 ++++++++++++++++++++++++++-
|
||||
src/mime/multipart/multipart.go | 25 +++--
|
||||
src/mime/multipart/readmimeheader.go | 14 +++
|
||||
src/net/http/request_test.go | 2 +-
|
||||
src/net/textproto/reader.go | 27 ++++++
|
||||
6 files changed, 303 insertions(+), 37 deletions(-)
|
||||
create mode 100644 src/mime/multipart/readmimeheader.go
|
||||
|
||||
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go
|
||||
index 9c42ea8..1eeb340 100644
|
||||
--- a/src/mime/multipart/formdata.go
|
||||
+++ b/src/mime/multipart/formdata.go
|
||||
@@ -7,6 +7,7 @@ package multipart
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
+ "internal/godebug"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
@@ -34,23 +35,58 @@ func (r *Reader) ReadForm(maxMemory int64) (*Form, error) {
|
||||
|
||||
func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
form := &Form{make(map[string][]string), make(map[string][]*FileHeader)}
|
||||
+ var (
|
||||
+ file *os.File
|
||||
+ fileOff int64
|
||||
+ )
|
||||
+ numDiskFiles := 0
|
||||
+ multipartFiles := godebug.Get("multipartfiles")
|
||||
+ combineFiles := multipartFiles != "distinct"
|
||||
defer func() {
|
||||
+ if file != nil {
|
||||
+ if cerr := file.Close(); err == nil {
|
||||
+ err = cerr
|
||||
+ }
|
||||
+ }
|
||||
+ if combineFiles && numDiskFiles > 1 {
|
||||
+ for _, fhs := range form.File {
|
||||
+ for _, fh := range fhs {
|
||||
+ fh.tmpshared = true
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
if err != nil {
|
||||
form.RemoveAll()
|
||||
+ if file != nil {
|
||||
+ os.Remove(file.Name())
|
||||
+ }
|
||||
}
|
||||
}()
|
||||
|
||||
- // Reserve an additional 10 MB for non-file parts.
|
||||
- maxValueBytes := maxMemory + int64(10<<20)
|
||||
- if maxValueBytes <= 0 {
|
||||
+ // maxFileMemoryBytes is the maximum bytes of file data we will store in memory.
|
||||
+ // Data past this limit is written to disk.
|
||||
+ // This limit strictly applies to content, not metadata (filenames, MIME headers, etc.),
|
||||
+ // since metadata is always stored in memory, not disk.
|
||||
+ //
|
||||
+ // maxMemoryBytes is the maximum bytes we will store in memory, including file content,
|
||||
+ // non-file part values, metdata, and map entry overhead.
|
||||
+ //
|
||||
+ // We reserve an additional 10 MB in maxMemoryBytes for non-file data.
|
||||
+ //
|
||||
+ // The relationship between these parameters, as well as the overly-large and
|
||||
+ // unconfigurable 10 MB added on to maxMemory, is unfortunate but difficult to change
|
||||
+ // within the constraints of the API as documented.
|
||||
+ maxFileMemoryBytes := maxMemory
|
||||
+ maxMemoryBytes := maxMemory + int64(10<<20)
|
||||
+ if maxMemoryBytes <= 0 {
|
||||
if maxMemory < 0 {
|
||||
- maxValueBytes = 0
|
||||
+ maxMemoryBytes = 0
|
||||
} else {
|
||||
- maxValueBytes = math.MaxInt64
|
||||
+ maxMemoryBytes = math.MaxInt64
|
||||
}
|
||||
}
|
||||
for {
|
||||
- p, err := r.NextPart()
|
||||
+ p, err := r.nextPart(false, maxMemoryBytes)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
@@ -64,16 +100,27 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
}
|
||||
filename := p.FileName()
|
||||
|
||||
+ // Multiple values for the same key (one map entry, longer slice) are cheaper
|
||||
+ // than the same number of values for different keys (many map entries), but
|
||||
+ // using a consistent per-value cost for overhead is simpler.
|
||||
+ maxMemoryBytes -= int64(len(name))
|
||||
+ maxMemoryBytes -= 100 // map overhead
|
||||
+ if maxMemoryBytes < 0 {
|
||||
+ // We can't actually take this path, since nextPart would already have
|
||||
+ // rejected the MIME headers for being too large. Check anyway.
|
||||
+ return nil, ErrMessageTooLarge
|
||||
+ }
|
||||
+
|
||||
var b bytes.Buffer
|
||||
|
||||
if filename == "" {
|
||||
// value, store as string in memory
|
||||
- n, err := io.CopyN(&b, p, maxValueBytes+1)
|
||||
+ n, err := io.CopyN(&b, p, maxMemoryBytes+1)
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
- maxValueBytes -= n
|
||||
- if maxValueBytes < 0 {
|
||||
+ maxMemoryBytes -= n
|
||||
+ if maxMemoryBytes < 0 {
|
||||
return nil, ErrMessageTooLarge
|
||||
}
|
||||
form.Value[name] = append(form.Value[name], b.String())
|
||||
@@ -81,35 +128,45 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
}
|
||||
|
||||
// file, store in memory or on disk
|
||||
+ maxMemoryBytes -= mimeHeaderSize(p.Header)
|
||||
+ if maxMemoryBytes < 0 {
|
||||
+ return nil, ErrMessageTooLarge
|
||||
+ }
|
||||
fh := &FileHeader{
|
||||
Filename: filename,
|
||||
Header: p.Header,
|
||||
}
|
||||
- n, err := io.CopyN(&b, p, maxMemory+1)
|
||||
+ n, err := io.CopyN(&b, p, maxFileMemoryBytes+1)
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
- if n > maxMemory {
|
||||
- // too big, write to disk and flush buffer
|
||||
- file, err := ioutil.TempFile("", "multipart-")
|
||||
- if err != nil {
|
||||
- return nil, err
|
||||
+ if n > maxFileMemoryBytes {
|
||||
+ if file == nil {
|
||||
+ file, err = ioutil.TempFile(r.tempDir, "multipart-")
|
||||
+ if err != nil {
|
||||
+ return nil, err
|
||||
+ }
|
||||
}
|
||||
+ numDiskFiles++
|
||||
size, err := io.Copy(file, io.MultiReader(&b, p))
|
||||
- if cerr := file.Close(); err == nil {
|
||||
- err = cerr
|
||||
- }
|
||||
if err != nil {
|
||||
- os.Remove(file.Name())
|
||||
return nil, err
|
||||
}
|
||||
fh.tmpfile = file.Name()
|
||||
fh.Size = size
|
||||
+ fh.tmpoff = fileOff
|
||||
+ fileOff += size
|
||||
+ if !combineFiles {
|
||||
+ if err := file.Close(); err != nil {
|
||||
+ return nil, err
|
||||
+ }
|
||||
+ file = nil
|
||||
+ }
|
||||
} else {
|
||||
fh.content = b.Bytes()
|
||||
fh.Size = int64(len(fh.content))
|
||||
- maxMemory -= n
|
||||
- maxValueBytes -= n
|
||||
+ maxFileMemoryBytes -= n
|
||||
+ maxMemoryBytes -= n
|
||||
}
|
||||
form.File[name] = append(form.File[name], fh)
|
||||
}
|
||||
@@ -117,6 +174,17 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
return form, nil
|
||||
}
|
||||
|
||||
+func mimeHeaderSize(h textproto.MIMEHeader) (size int64) {
|
||||
+ for k, vs := range h {
|
||||
+ size += int64(len(k))
|
||||
+ size += 100 // map entry overhead
|
||||
+ for _, v := range vs {
|
||||
+ size += int64(len(v))
|
||||
+ }
|
||||
+ }
|
||||
+ return size
|
||||
+}
|
||||
+
|
||||
// Form is a parsed multipart form.
|
||||
// Its File parts are stored either in memory or on disk,
|
||||
// and are accessible via the *FileHeader's Open method.
|
||||
@@ -134,7 +202,7 @@ func (f *Form) RemoveAll() error {
|
||||
for _, fh := range fhs {
|
||||
if fh.tmpfile != "" {
|
||||
e := os.Remove(fh.tmpfile)
|
||||
- if e != nil && err == nil {
|
||||
+ if e != nil && !errors.Is(e, os.ErrNotExist) && err == nil {
|
||||
err = e
|
||||
}
|
||||
}
|
||||
@@ -149,15 +217,25 @@ type FileHeader struct {
|
||||
Header textproto.MIMEHeader
|
||||
Size int64
|
||||
|
||||
- content []byte
|
||||
- tmpfile string
|
||||
+ content []byte
|
||||
+ tmpfile string
|
||||
+ tmpoff int64
|
||||
+ tmpshared bool
|
||||
}
|
||||
|
||||
// Open opens and returns the FileHeader's associated File.
|
||||
func (fh *FileHeader) Open() (File, error) {
|
||||
if b := fh.content; b != nil {
|
||||
r := io.NewSectionReader(bytes.NewReader(b), 0, int64(len(b)))
|
||||
- return sectionReadCloser{r}, nil
|
||||
+ return sectionReadCloser{r, nil}, nil
|
||||
+ }
|
||||
+ if fh.tmpshared {
|
||||
+ f, err := os.Open(fh.tmpfile)
|
||||
+ if err != nil {
|
||||
+ return nil, err
|
||||
+ }
|
||||
+ r := io.NewSectionReader(f, fh.tmpoff, fh.Size)
|
||||
+ return sectionReadCloser{r, f}, nil
|
||||
}
|
||||
return os.Open(fh.tmpfile)
|
||||
}
|
||||
@@ -176,8 +254,12 @@ type File interface {
|
||||
|
||||
type sectionReadCloser struct {
|
||||
*io.SectionReader
|
||||
+ io.Closer
|
||||
}
|
||||
|
||||
func (rc sectionReadCloser) Close() error {
|
||||
+ if rc.Closer != nil {
|
||||
+ return rc.Closer.Close()
|
||||
+ }
|
||||
return nil
|
||||
}
|
||||
diff --git a/src/mime/multipart/formdata_test.go b/src/mime/multipart/formdata_test.go
|
||||
index e3a3a3e..5cded71 100644
|
||||
--- a/src/mime/multipart/formdata_test.go
|
||||
+++ b/src/mime/multipart/formdata_test.go
|
||||
@@ -6,8 +6,10 @@ package multipart
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
+ "fmt"
|
||||
"io"
|
||||
"math"
|
||||
+ "net/textproto"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -208,8 +210,8 @@ Content-Disposition: form-data; name="largetext"
|
||||
maxMemory int64
|
||||
err error
|
||||
}{
|
||||
- {"smaller", 50, nil},
|
||||
- {"exact-fit", 25, nil},
|
||||
+ {"smaller", 50 + int64(len("largetext")) + 100, nil},
|
||||
+ {"exact-fit", 25 + int64(len("largetext")) + 100, nil},
|
||||
{"too-large", 0, ErrMessageTooLarge},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
@@ -224,7 +226,7 @@ Content-Disposition: form-data; name="largetext"
|
||||
defer f.RemoveAll()
|
||||
}
|
||||
if tc.err != err {
|
||||
- t.Fatalf("ReadForm error - got: %v; expected: %v", tc.err, err)
|
||||
+ t.Fatalf("ReadForm error - got: %v; expected: %v", err, tc.err)
|
||||
}
|
||||
if err == nil {
|
||||
if g := f.Value["largetext"][0]; g != largeTextValue {
|
||||
@@ -234,3 +236,135 @@ Content-Disposition: form-data; name="largetext"
|
||||
})
|
||||
}
|
||||
}
|
||||
+
|
||||
+// TestReadForm_MetadataTooLarge verifies that we account for the size of field names,
|
||||
+// MIME headers, and map entry overhead while limiting the memory consumption of parsed forms.
|
||||
+func TestReadForm_MetadataTooLarge(t *testing.T) {
|
||||
+ for _, test := range []struct {
|
||||
+ name string
|
||||
+ f func(*Writer)
|
||||
+ }{{
|
||||
+ name: "large name",
|
||||
+ f: func(fw *Writer) {
|
||||
+ name := strings.Repeat("a", 10<<20)
|
||||
+ w, _ := fw.CreateFormField(name)
|
||||
+ w.Write([]byte("value"))
|
||||
+ },
|
||||
+ }, {
|
||||
+ name: "large MIME header",
|
||||
+ f: func(fw *Writer) {
|
||||
+ h := make(textproto.MIMEHeader)
|
||||
+ h.Set("Content-Disposition", `form-data; name="a"`)
|
||||
+ h.Set("X-Foo", strings.Repeat("a", 10<<20))
|
||||
+ w, _ := fw.CreatePart(h)
|
||||
+ w.Write([]byte("value"))
|
||||
+ },
|
||||
+ }, {
|
||||
+ name: "many parts",
|
||||
+ f: func(fw *Writer) {
|
||||
+ for i := 0; i < 110000; i++ {
|
||||
+ w, _ := fw.CreateFormField("f")
|
||||
+ w.Write([]byte("v"))
|
||||
+ }
|
||||
+ },
|
||||
+ }} {
|
||||
+ t.Run(test.name, func(t *testing.T) {
|
||||
+ var buf bytes.Buffer
|
||||
+ fw := NewWriter(&buf)
|
||||
+ test.f(fw)
|
||||
+ if err := fw.Close(); err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ fr := NewReader(&buf, fw.Boundary())
|
||||
+ _, err := fr.ReadForm(0)
|
||||
+ if err != ErrMessageTooLarge {
|
||||
+ t.Errorf("fr.ReadForm() = %v, want ErrMessageTooLarge", err)
|
||||
+ }
|
||||
+ })
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// TestReadForm_ManyFiles_Combined tests that a multipart form containing many files only
|
||||
+// results in a single on-disk file.
|
||||
+func TestReadForm_ManyFiles_Combined(t *testing.T) {
|
||||
+ const distinct = false
|
||||
+ testReadFormManyFiles(t, distinct)
|
||||
+}
|
||||
+
|
||||
+// TestReadForm_ManyFiles_Distinct tests that setting GODEBUG=multipartfiles=distinct
|
||||
+// results in every file in a multipart form being placed in a distinct on-disk file.
|
||||
+func TestReadForm_ManyFiles_Distinct(t *testing.T) {
|
||||
+ t.Setenv("GODEBUG", "multipartfiles=distinct")
|
||||
+ const distinct = true
|
||||
+ testReadFormManyFiles(t, distinct)
|
||||
+}
|
||||
+
|
||||
+func testReadFormManyFiles(t *testing.T, distinct bool) {
|
||||
+ var buf bytes.Buffer
|
||||
+ fw := NewWriter(&buf)
|
||||
+ const numFiles = 10
|
||||
+ for i := 0; i < numFiles; i++ {
|
||||
+ name := fmt.Sprint(i)
|
||||
+ w, err := fw.CreateFormFile(name, name)
|
||||
+ if err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ w.Write([]byte(name))
|
||||
+ }
|
||||
+ if err := fw.Close(); err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ fr := NewReader(&buf, fw.Boundary())
|
||||
+ fr.tempDir = t.TempDir()
|
||||
+ form, err := fr.ReadForm(0)
|
||||
+ if err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ for i := 0; i < numFiles; i++ {
|
||||
+ name := fmt.Sprint(i)
|
||||
+ if got := len(form.File[name]); got != 1 {
|
||||
+ t.Fatalf("form.File[%q] has %v entries, want 1", name, got)
|
||||
+ }
|
||||
+ fh := form.File[name][0]
|
||||
+ file, err := fh.Open()
|
||||
+ if err != nil {
|
||||
+ t.Fatalf("form.File[%q].Open() = %v", name, err)
|
||||
+ }
|
||||
+ if distinct {
|
||||
+ if _, ok := file.(*os.File); !ok {
|
||||
+ t.Fatalf("form.File[%q].Open: %T, want *os.File", name, file)
|
||||
+ }
|
||||
+ }
|
||||
+ got, err := io.ReadAll(file)
|
||||
+ file.Close()
|
||||
+ if string(got) != name || err != nil {
|
||||
+ t.Fatalf("read form.File[%q]: %q, %v; want %q, nil", name, string(got), err, name)
|
||||
+ }
|
||||
+ }
|
||||
+ dir, err := os.Open(fr.tempDir)
|
||||
+ if err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ defer dir.Close()
|
||||
+ names, err := dir.Readdirnames(0)
|
||||
+ if err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ wantNames := 1
|
||||
+ if distinct {
|
||||
+ wantNames = numFiles
|
||||
+ }
|
||||
+ if len(names) != wantNames {
|
||||
+ t.Fatalf("temp dir contains %v files; want 1", len(names))
|
||||
+ }
|
||||
+ if err := form.RemoveAll(); err != nil {
|
||||
+ t.Fatalf("form.RemoveAll() = %v", err)
|
||||
+ }
|
||||
+ names, err = dir.Readdirnames(0)
|
||||
+ if err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ if len(names) != 0 {
|
||||
+ t.Fatalf("temp dir contains %v files; want 0", len(names))
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/mime/multipart/multipart.go b/src/mime/multipart/multipart.go
|
||||
index 1750300..958cef8 100644
|
||||
--- a/src/mime/multipart/multipart.go
|
||||
+++ b/src/mime/multipart/multipart.go
|
||||
@@ -121,12 +121,12 @@ func (r *stickyErrorReader) Read(p []byte) (n int, _ error) {
|
||||
return n, r.err
|
||||
}
|
||||
|
||||
-func newPart(mr *Reader, rawPart bool) (*Part, error) {
|
||||
+func newPart(mr *Reader, rawPart bool, maxMIMEHeaderSize int64) (*Part, error) {
|
||||
bp := &Part{
|
||||
Header: make(map[string][]string),
|
||||
mr: mr,
|
||||
}
|
||||
- if err := bp.populateHeaders(); err != nil {
|
||||
+ if err := bp.populateHeaders(maxMIMEHeaderSize); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bp.r = partReader{bp}
|
||||
@@ -142,12 +142,16 @@ func newPart(mr *Reader, rawPart bool) (*Part, error) {
|
||||
return bp, nil
|
||||
}
|
||||
|
||||
-func (bp *Part) populateHeaders() error {
|
||||
+func (bp *Part) populateHeaders(maxMIMEHeaderSize int64) error {
|
||||
r := textproto.NewReader(bp.mr.bufReader)
|
||||
- header, err := r.ReadMIMEHeader()
|
||||
+ header, err := readMIMEHeader(r, maxMIMEHeaderSize)
|
||||
if err == nil {
|
||||
bp.Header = header
|
||||
}
|
||||
+ // TODO: Add a distinguishable error to net/textproto.
|
||||
+ if err != nil && err.Error() == "message too large" {
|
||||
+ err = ErrMessageTooLarge
|
||||
+ }
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -287,6 +291,7 @@ func (p *Part) Close() error {
|
||||
// isn't supported.
|
||||
type Reader struct {
|
||||
bufReader *bufio.Reader
|
||||
+ tempDir string // used in tests
|
||||
|
||||
currentPart *Part
|
||||
partsRead int
|
||||
@@ -297,6 +302,10 @@ type Reader struct {
|
||||
dashBoundary []byte // "--boundary"
|
||||
}
|
||||
|
||||
+// maxMIMEHeaderSize is the maximum size of a MIME header we will parse,
|
||||
+// including header keys, values, and map overhead.
|
||||
+const maxMIMEHeaderSize = 10 << 20
|
||||
+
|
||||
// NextPart returns the next part in the multipart or an error.
|
||||
// When there are no more parts, the error io.EOF is returned.
|
||||
//
|
||||
@@ -304,7 +313,7 @@ type Reader struct {
|
||||
// has a value of "quoted-printable", that header is instead
|
||||
// hidden and the body is transparently decoded during Read calls.
|
||||
func (r *Reader) NextPart() (*Part, error) {
|
||||
- return r.nextPart(false)
|
||||
+ return r.nextPart(false, maxMIMEHeaderSize)
|
||||
}
|
||||
|
||||
// NextRawPart returns the next part in the multipart or an error.
|
||||
@@ -313,10 +322,10 @@ func (r *Reader) NextPart() (*Part, error) {
|
||||
// Unlike NextPart, it does not have special handling for
|
||||
// "Content-Transfer-Encoding: quoted-printable".
|
||||
func (r *Reader) NextRawPart() (*Part, error) {
|
||||
- return r.nextPart(true)
|
||||
+ return r.nextPart(true, maxMIMEHeaderSize)
|
||||
}
|
||||
|
||||
-func (r *Reader) nextPart(rawPart bool) (*Part, error) {
|
||||
+func (r *Reader) nextPart(rawPart bool, maxMIMEHeaderSize int64) (*Part, error) {
|
||||
if r.currentPart != nil {
|
||||
r.currentPart.Close()
|
||||
}
|
||||
@@ -341,7 +350,7 @@ func (r *Reader) nextPart(rawPart bool) (*Part, error) {
|
||||
|
||||
if r.isBoundaryDelimiterLine(line) {
|
||||
r.partsRead++
|
||||
- bp, err := newPart(r, rawPart)
|
||||
+ bp, err := newPart(r, rawPart, maxMIMEHeaderSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
diff --git a/src/mime/multipart/readmimeheader.go b/src/mime/multipart/readmimeheader.go
|
||||
new file mode 100644
|
||||
index 0000000..6836928
|
||||
--- /dev/null
|
||||
+++ b/src/mime/multipart/readmimeheader.go
|
||||
@@ -0,0 +1,14 @@
|
||||
+// Copyright 2023 The Go Authors. All rights reserved.
|
||||
+// Use of this source code is governed by a BSD-style
|
||||
+// license that can be found in the LICENSE file.
|
||||
+package multipart
|
||||
+
|
||||
+import (
|
||||
+ "net/textproto"
|
||||
+ _ "unsafe" // for go:linkname
|
||||
+)
|
||||
+
|
||||
+// readMIMEHeader is defined in package net/textproto.
|
||||
+//
|
||||
+//go:linkname readMIMEHeader net/textproto.readMIMEHeader
|
||||
+func readMIMEHeader(r *textproto.Reader, lim int64) (textproto.MIMEHeader, error)
|
||||
diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go
|
||||
index 94133ee..170d3f5 100644
|
||||
--- a/src/net/http/request_test.go
|
||||
+++ b/src/net/http/request_test.go
|
||||
@@ -962,7 +962,7 @@ func testMissingFile(t *testing.T, req *Request) {
|
||||
t.Errorf("FormFile file = %v, want nil", f)
|
||||
}
|
||||
if fh != nil {
|
||||
- t.Errorf("FormFile file header = %q, want nil", fh)
|
||||
+ t.Errorf("FormFile file header = %v, want nil", fh)
|
||||
}
|
||||
if err != ErrMissingFile {
|
||||
t.Errorf("FormFile err = %q, want ErrMissingFile", err)
|
||||
diff --git a/src/net/textproto/reader.go b/src/net/textproto/reader.go
|
||||
index f63f5ec..96553fb 100644
|
||||
--- a/src/net/textproto/reader.go
|
||||
+++ b/src/net/textproto/reader.go
|
||||
@@ -7,9 +7,11 @@ package textproto
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
+ "errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
+ "math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -482,6 +484,12 @@ func (r *Reader) ReadDotLines() ([]string, error) {
|
||||
// }
|
||||
//
|
||||
func (r *Reader) ReadMIMEHeader() (MIMEHeader, error) {
|
||||
+ return readMIMEHeader(r, math.MaxInt64)
|
||||
+}
|
||||
+
|
||||
+// readMIMEHeader is a version of ReadMIMEHeader which takes a limit on the header size.
|
||||
+// It is called by the mime/multipart package.
|
||||
+func readMIMEHeader(r *Reader, lim int64) (MIMEHeader, error) {
|
||||
// Avoid lots of small slice allocations later by allocating one
|
||||
// large one ahead of time which we'll cut up into smaller
|
||||
// slices. If this isn't big enough later, we allocate small ones.
|
||||
@@ -525,6 +533,15 @@ func (r *Reader) ReadMIMEHeader() (MIMEHeader, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
+ // backport 5c55ac9bf1e5f779220294c843526536605f42ab
|
||||
+ //
|
||||
+ // value is computed as
|
||||
+ // value := string(bytes.TrimLeft(v, " \t"))
|
||||
+ //
|
||||
+ // in the original patch from 1.19. This relies on
|
||||
+ // 'v' which does not exist in 1.14. We leave the
|
||||
+ // 1.14 method unchanged.
|
||||
+
|
||||
// Skip initial spaces in value.
|
||||
i++ // skip colon
|
||||
for i < len(kv) && (kv[i] == ' ' || kv[i] == '\t') {
|
||||
@@ -533,6 +550,16 @@ func (r *Reader) ReadMIMEHeader() (MIMEHeader, error) {
|
||||
value := string(kv[i:])
|
||||
|
||||
vv := m[key]
|
||||
+ if vv == nil {
|
||||
+ lim -= int64(len(key))
|
||||
+ lim -= 100 // map entry overhead
|
||||
+ }
|
||||
+ lim -= int64(len(value))
|
||||
+ if lim < 0 {
|
||||
+ // TODO: This should be a distinguishable error (ErrMessageTooLarge)
|
||||
+ // to allow mime/multipart to detect it.
|
||||
+ return m, errors.New("message too large")
|
||||
+ }
|
||||
if vv == nil && len(strs) > 0 {
|
||||
// More than likely this will be a single-element key.
|
||||
// Most headers aren't multi-valued.
|
||||
--
|
||||
2.25.1
|
||||
|
||||
134
meta/recipes-devtools/go/go-1.14/CVE-2023-24536_1.patch
Normal file
134
meta/recipes-devtools/go/go-1.14/CVE-2023-24536_1.patch
Normal file
@@ -0,0 +1,134 @@
|
||||
From ef41a4e2face45e580c5836eaebd51629fc23f15 Mon Sep 17 00:00:00 2001
|
||||
From: Damien Neil <dneil@google.com>
|
||||
Date: Thu, 16 Mar 2023 14:18:04 -0700
|
||||
Subject: [PATCH] [release-branch.go1.19] mime/multipart: avoid excessive copy
|
||||
buffer allocations in ReadForm
|
||||
|
||||
When copying form data to disk with io.Copy,
|
||||
allocate only one copy buffer and reuse it rather than
|
||||
creating two buffers per file (one from io.multiReader.WriteTo,
|
||||
and a second one from os.File.ReadFrom).
|
||||
|
||||
Thanks to Jakob Ackermann (@das7pad) for reporting this issue.
|
||||
|
||||
For CVE-2023-24536
|
||||
For #59153
|
||||
For #59269
|
||||
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802453
|
||||
Run-TryBot: Damien Neil <dneil@google.com>
|
||||
Reviewed-by: Julie Qiu <julieqiu@google.com>
|
||||
Reviewed-by: Roland Shoemaker <bracewell@google.com>
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802395
|
||||
Run-TryBot: Roland Shoemaker <bracewell@google.com>
|
||||
Reviewed-by: Damien Neil <dneil@google.com>
|
||||
Change-Id: Ie405470c92abffed3356913b37d813e982c96c8b
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/481983
|
||||
Run-TryBot: Michael Knyszek <mknyszek@google.com>
|
||||
TryBot-Result: Gopher Robot <gobot@golang.org>
|
||||
Auto-Submit: Michael Knyszek <mknyszek@google.com>
|
||||
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/ef41a4e2face45e580c5836eaebd51629fc23f15]
|
||||
CVE: CVE-2023-24536
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/mime/multipart/formdata.go | 15 +++++++--
|
||||
src/mime/multipart/formdata_test.go | 49 +++++++++++++++++++++++++++++
|
||||
2 files changed, 61 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go
|
||||
index a7d4ca97f0484..975dcb6b26db4 100644
|
||||
--- a/src/mime/multipart/formdata.go
|
||||
+++ b/src/mime/multipart/formdata.go
|
||||
@@ -84,6 +84,7 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
maxMemoryBytes = math.MaxInt64
|
||||
}
|
||||
}
|
||||
+ var copyBuf []byte
|
||||
for {
|
||||
p, err := r.nextPart(false, maxMemoryBytes)
|
||||
if err == io.EOF {
|
||||
@@ -147,14 +148,22 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
}
|
||||
}
|
||||
numDiskFiles++
|
||||
- size, err := io.Copy(file, io.MultiReader(&b, p))
|
||||
+ if _, err := file.Write(b.Bytes()); err != nil {
|
||||
+ return nil, err
|
||||
+ }
|
||||
+ if copyBuf == nil {
|
||||
+ copyBuf = make([]byte, 32*1024) // same buffer size as io.Copy uses
|
||||
+ }
|
||||
+ // os.File.ReadFrom will allocate its own copy buffer if we let io.Copy use it.
|
||||
+ type writerOnly struct{ io.Writer }
|
||||
+ remainingSize, err := io.CopyBuffer(writerOnly{file}, p, copyBuf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fh.tmpfile = file.Name()
|
||||
- fh.Size = size
|
||||
+ fh.Size = int64(b.Len()) + remainingSize
|
||||
fh.tmpoff = fileOff
|
||||
- fileOff += size
|
||||
+ fileOff += fh.Size
|
||||
if !combineFiles {
|
||||
if err := file.Close(); err != nil {
|
||||
return nil, err
|
||||
diff --git a/src/mime/multipart/formdata_test.go b/src/mime/multipart/formdata_test.go
|
||||
index 5cded7170c6b8..f5b56083b2377 100644
|
||||
--- a/src/mime/multipart/formdata_test.go
|
||||
+++ b/src/mime/multipart/formdata_test.go
|
||||
@@ -368,3 +368,52 @@ func testReadFormManyFiles(t *testing.T, distinct bool) {
|
||||
t.Fatalf("temp dir contains %v files; want 0", len(names))
|
||||
}
|
||||
}
|
||||
+
|
||||
+func BenchmarkReadForm(b *testing.B) {
|
||||
+ for _, test := range []struct {
|
||||
+ name string
|
||||
+ form func(fw *Writer, count int)
|
||||
+ }{{
|
||||
+ name: "fields",
|
||||
+ form: func(fw *Writer, count int) {
|
||||
+ for i := 0; i < count; i++ {
|
||||
+ w, _ := fw.CreateFormField(fmt.Sprintf("field%v", i))
|
||||
+ fmt.Fprintf(w, "value %v", i)
|
||||
+ }
|
||||
+ },
|
||||
+ }, {
|
||||
+ name: "files",
|
||||
+ form: func(fw *Writer, count int) {
|
||||
+ for i := 0; i < count; i++ {
|
||||
+ w, _ := fw.CreateFormFile(fmt.Sprintf("field%v", i), fmt.Sprintf("file%v", i))
|
||||
+ fmt.Fprintf(w, "value %v", i)
|
||||
+ }
|
||||
+ },
|
||||
+ }} {
|
||||
+ b.Run(test.name, func(b *testing.B) {
|
||||
+ for _, maxMemory := range []int64{
|
||||
+ 0,
|
||||
+ 1 << 20,
|
||||
+ } {
|
||||
+ var buf bytes.Buffer
|
||||
+ fw := NewWriter(&buf)
|
||||
+ test.form(fw, 10)
|
||||
+ if err := fw.Close(); err != nil {
|
||||
+ b.Fatal(err)
|
||||
+ }
|
||||
+ b.Run(fmt.Sprintf("maxMemory=%v", maxMemory), func(b *testing.B) {
|
||||
+ b.ReportAllocs()
|
||||
+ for i := 0; i < b.N; i++ {
|
||||
+ fr := NewReader(bytes.NewReader(buf.Bytes()), fw.Boundary())
|
||||
+ form, err := fr.ReadForm(maxMemory)
|
||||
+ if err != nil {
|
||||
+ b.Fatal(err)
|
||||
+ }
|
||||
+ form.RemoveAll()
|
||||
+ }
|
||||
+
|
||||
+ })
|
||||
+ }
|
||||
+ })
|
||||
+ }
|
||||
+}
|
||||
184
meta/recipes-devtools/go/go-1.14/CVE-2023-24536_2.patch
Normal file
184
meta/recipes-devtools/go/go-1.14/CVE-2023-24536_2.patch
Normal file
@@ -0,0 +1,184 @@
|
||||
From 7a359a651c7ebdb29e0a1c03102fce793e9f58f0 Mon Sep 17 00:00:00 2001
|
||||
From: Damien Neil <dneil@google.com>
|
||||
Date: Thu, 16 Mar 2023 16:56:12 -0700
|
||||
Subject: [PATCH] [release-branch.go1.19] net/textproto, mime/multipart:
|
||||
improve accounting of non-file data
|
||||
|
||||
For requests containing large numbers of small parts,
|
||||
memory consumption of a parsed form could be about 250%
|
||||
over the estimated size.
|
||||
|
||||
When considering the size of parsed forms, account for the size of
|
||||
FileHeader structs and increase the estimate of memory consumed by
|
||||
map entries.
|
||||
|
||||
Thanks to Jakob Ackermann (@das7pad) for reporting this issue.
|
||||
|
||||
For CVE-2023-24536
|
||||
For #59153
|
||||
For #59269
|
||||
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802454
|
||||
Run-TryBot: Damien Neil <dneil@google.com>
|
||||
Reviewed-by: Roland Shoemaker <bracewell@google.com>
|
||||
Reviewed-by: Julie Qiu <julieqiu@google.com>
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802396
|
||||
Run-TryBot: Roland Shoemaker <bracewell@google.com>
|
||||
Reviewed-by: Damien Neil <dneil@google.com>
|
||||
Change-Id: I31bc50e9346b4eee6fbe51a18c3c57230cc066db
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/481984
|
||||
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
|
||||
Auto-Submit: Michael Knyszek <mknyszek@google.com>
|
||||
TryBot-Result: Gopher Robot <gobot@golang.org>
|
||||
Run-TryBot: Michael Knyszek <mknyszek@google.com>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/7a359a651c7ebdb29e0a1c03102fce793e9f58f0]
|
||||
CVE: CVE-2023-24536
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/mime/multipart/formdata.go | 9 +++--
|
||||
src/mime/multipart/formdata_test.go | 55 ++++++++++++-----------------
|
||||
src/net/textproto/reader.go | 8 ++++-
|
||||
3 files changed, 37 insertions(+), 35 deletions(-)
|
||||
|
||||
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go
|
||||
index 975dcb6b26db4..3f6ff697ca608 100644
|
||||
--- a/src/mime/multipart/formdata.go
|
||||
+++ b/src/mime/multipart/formdata.go
|
||||
@@ -103,8 +103,9 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
// Multiple values for the same key (one map entry, longer slice) are cheaper
|
||||
// than the same number of values for different keys (many map entries), but
|
||||
// using a consistent per-value cost for overhead is simpler.
|
||||
+ const mapEntryOverhead = 200
|
||||
maxMemoryBytes -= int64(len(name))
|
||||
- maxMemoryBytes -= 100 // map overhead
|
||||
+ maxMemoryBytes -= mapEntryOverhead
|
||||
if maxMemoryBytes < 0 {
|
||||
// We can't actually take this path, since nextPart would already have
|
||||
// rejected the MIME headers for being too large. Check anyway.
|
||||
@@ -128,7 +129,10 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
}
|
||||
|
||||
// file, store in memory or on disk
|
||||
+ const fileHeaderSize = 100
|
||||
maxMemoryBytes -= mimeHeaderSize(p.Header)
|
||||
+ maxMemoryBytes -= mapEntryOverhead
|
||||
+ maxMemoryBytes -= fileHeaderSize
|
||||
if maxMemoryBytes < 0 {
|
||||
return nil, ErrMessageTooLarge
|
||||
}
|
||||
@@ -183,9 +187,10 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
}
|
||||
|
||||
func mimeHeaderSize(h textproto.MIMEHeader) (size int64) {
|
||||
+ size = 400
|
||||
for k, vs := range h {
|
||||
size += int64(len(k))
|
||||
- size += 100 // map entry overhead
|
||||
+ size += 200 // map entry overhead
|
||||
for _, v := range vs {
|
||||
size += int64(len(v))
|
||||
}
|
||||
diff --git a/src/mime/multipart/formdata_test.go b/src/mime/multipart/formdata_test.go
|
||||
index f5b56083b2377..8ed26e0c34081 100644
|
||||
--- a/src/mime/multipart/formdata_test.go
|
||||
+++ b/src/mime/multipart/formdata_test.go
|
||||
@@ -192,10 +192,10 @@ func (r *failOnReadAfterErrorReader) Read(p []byte) (n int, err error) {
|
||||
// TestReadForm_NonFileMaxMemory asserts that the ReadForm maxMemory limit is applied
|
||||
// while processing non-file form data as well as file form data.
|
||||
func TestReadForm_NonFileMaxMemory(t *testing.T) {
|
||||
- n := 10<<20 + 25
|
||||
if testing.Short() {
|
||||
- n = 10<<10 + 25
|
||||
+ t.Skip("skipping in -short mode")
|
||||
}
|
||||
+ n := 10 << 20
|
||||
largeTextValue := strings.Repeat("1", n)
|
||||
message := `--MyBoundary
|
||||
Content-Disposition: form-data; name="largetext"
|
||||
@@ -203,38 +203,29 @@ Content-Disposition: form-data; name="largetext"
|
||||
` + largeTextValue + `
|
||||
--MyBoundary--
|
||||
`
|
||||
-
|
||||
testBody := strings.ReplaceAll(message, "\n", "\r\n")
|
||||
- testCases := []struct {
|
||||
- name string
|
||||
- maxMemory int64
|
||||
- err error
|
||||
- }{
|
||||
- {"smaller", 50 + int64(len("largetext")) + 100, nil},
|
||||
- {"exact-fit", 25 + int64(len("largetext")) + 100, nil},
|
||||
- {"too-large", 0, ErrMessageTooLarge},
|
||||
- }
|
||||
- for _, tc := range testCases {
|
||||
- t.Run(tc.name, func(t *testing.T) {
|
||||
- if tc.maxMemory == 0 && testing.Short() {
|
||||
- t.Skip("skipping in -short mode")
|
||||
- }
|
||||
- b := strings.NewReader(testBody)
|
||||
- r := NewReader(b, boundary)
|
||||
- f, err := r.ReadForm(tc.maxMemory)
|
||||
- if err == nil {
|
||||
- defer f.RemoveAll()
|
||||
- }
|
||||
- if tc.err != err {
|
||||
- t.Fatalf("ReadForm error - got: %v; expected: %v", err, tc.err)
|
||||
- }
|
||||
- if err == nil {
|
||||
- if g := f.Value["largetext"][0]; g != largeTextValue {
|
||||
- t.Errorf("largetext mismatch: got size: %v, expected size: %v", len(g), len(largeTextValue))
|
||||
- }
|
||||
- }
|
||||
- })
|
||||
+ // Try parsing the form with increasing maxMemory values.
|
||||
+ // Changes in how we account for non-file form data may cause the exact point
|
||||
+ // where we change from rejecting the form as too large to accepting it to vary,
|
||||
+ // but we should see both successes and failures.
|
||||
+ const failWhenMaxMemoryLessThan = 128
|
||||
+ for maxMemory := int64(0); maxMemory < failWhenMaxMemoryLessThan*2; maxMemory += 16 {
|
||||
+ b := strings.NewReader(testBody)
|
||||
+ r := NewReader(b, boundary)
|
||||
+ f, err := r.ReadForm(maxMemory)
|
||||
+ if err != nil {
|
||||
+ continue
|
||||
+ }
|
||||
+ if g := f.Value["largetext"][0]; g != largeTextValue {
|
||||
+ t.Errorf("largetext mismatch: got size: %v, expected size: %v", len(g), len(largeTextValue))
|
||||
+ }
|
||||
+ f.RemoveAll()
|
||||
+ if maxMemory < failWhenMaxMemoryLessThan {
|
||||
+ t.Errorf("ReadForm(%v): no error, expect to hit memory limit when maxMemory < %v", maxMemory, failWhenMaxMemoryLessThan)
|
||||
+ }
|
||||
+ return
|
||||
}
|
||||
+ t.Errorf("ReadForm(x) failed for x < 1024, expect success")
|
||||
}
|
||||
|
||||
// TestReadForm_MetadataTooLarge verifies that we account for the size of field names,
|
||||
diff --git a/src/net/textproto/reader.go b/src/net/textproto/reader.go
|
||||
index 9a21777df8be0..c1284fde25eb7 100644
|
||||
--- a/src/net/textproto/reader.go
|
||||
+++ b/src/net/textproto/reader.go
|
||||
@@ -503,6 +503,12 @@ func readMIMEHeader(r *Reader, lim int64) (MIMEHeader, error) {
|
||||
|
||||
m := make(MIMEHeader, hint)
|
||||
|
||||
+ // Account for 400 bytes of overhead for the MIMEHeader, plus 200 bytes per entry.
|
||||
+ // Benchmarking map creation as of go1.20, a one-entry MIMEHeader is 416 bytes and large
|
||||
+ // MIMEHeaders average about 200 bytes per entry.
|
||||
+ lim -= 400
|
||||
+ const mapEntryOverhead = 200
|
||||
+
|
||||
// The first line cannot start with a leading space.
|
||||
if buf, err := r.R.Peek(1); err == nil && (buf[0] == ' ' || buf[0] == '\t') {
|
||||
line, err := r.readLineSlice()
|
||||
@@ -538,7 +544,7 @@ func readMIMEHeader(r *Reader, lim int64) (MIMEHeader, error) {
|
||||
vv := m[key]
|
||||
if vv == nil {
|
||||
lim -= int64(len(key))
|
||||
- lim -= 100 // map entry overhead
|
||||
+ lim -= mapEntryOverhead
|
||||
}
|
||||
lim -= int64(len(value))
|
||||
if lim < 0 {
|
||||
349
meta/recipes-devtools/go/go-1.14/CVE-2023-24536_3.patch
Normal file
349
meta/recipes-devtools/go/go-1.14/CVE-2023-24536_3.patch
Normal file
@@ -0,0 +1,349 @@
|
||||
From 7917b5f31204528ea72e0629f0b7d52b35b27538 Mon Sep 17 00:00:00 2001
|
||||
From: Damien Neil <dneil@google.com>
|
||||
Date: Mon, 20 Mar 2023 10:43:19 -0700
|
||||
Subject: [PATCH] [release-branch.go1.19] mime/multipart: limit parsed mime message sizes
|
||||
|
||||
The parsed forms of MIME headers and multipart forms can consume
|
||||
substantially more memory than the size of the input data.
|
||||
A malicious input containing a very large number of headers or
|
||||
form parts can cause excessively large memory allocations.
|
||||
|
||||
Set limits on the size of MIME data:
|
||||
|
||||
Reader.NextPart and Reader.NextRawPart limit the the number
|
||||
of headers in a part to 10000.
|
||||
|
||||
Reader.ReadForm limits the total number of headers in all
|
||||
FileHeaders to 10000.
|
||||
|
||||
Both of these limits may be set with with
|
||||
GODEBUG=multipartmaxheaders=<values>.
|
||||
|
||||
Reader.ReadForm limits the number of parts in a form to 1000.
|
||||
This limit may be set with GODEBUG=multipartmaxparts=<value>.
|
||||
|
||||
Thanks for Jakob Ackermann (@das7pad) for reporting this issue.
|
||||
|
||||
For CVE-2023-24536
|
||||
For #59153
|
||||
For #59269
|
||||
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1802455
|
||||
Run-TryBot: Damien Neil <dneil@google.com>
|
||||
Reviewed-by: Roland Shoemaker <bracewell@google.com>
|
||||
Reviewed-by: Julie Qiu <julieqiu@google.com>
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1801087
|
||||
Reviewed-by: Damien Neil <dneil@google.com>
|
||||
Run-TryBot: Roland Shoemaker <bracewell@google.com>
|
||||
Change-Id: If134890d75f0d95c681d67234daf191ba08e6424
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/481985
|
||||
Run-TryBot: Michael Knyszek <mknyszek@google.com>
|
||||
Auto-Submit: Michael Knyszek <mknyszek@google.com>
|
||||
TryBot-Result: Gopher Robot <gobot@golang.org>
|
||||
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/7917b5f31204528ea72e0629f0b7d52b35b27538]
|
||||
CVE: CVE-2023-24536
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/mime/multipart/formdata.go | 19 ++++++++-
|
||||
src/mime/multipart/formdata_test.go | 61 ++++++++++++++++++++++++++++
|
||||
src/mime/multipart/multipart.go | 31 ++++++++++----
|
||||
src/mime/multipart/readmimeheader.go | 2 +-
|
||||
src/net/textproto/reader.go | 19 +++++----
|
||||
5 files changed, 115 insertions(+), 17 deletions(-)
|
||||
|
||||
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go
|
||||
index 216cccb..0b508ae 100644
|
||||
--- a/src/mime/multipart/formdata.go
|
||||
+++ b/src/mime/multipart/formdata.go
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"math"
|
||||
"net/textproto"
|
||||
"os"
|
||||
+ "strconv"
|
||||
)
|
||||
|
||||
// ErrMessageTooLarge is returned by ReadForm if the message form
|
||||
@@ -42,6 +43,15 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
numDiskFiles := 0
|
||||
multipartFiles := godebug.Get("multipartfiles")
|
||||
combineFiles := multipartFiles != "distinct"
|
||||
+ maxParts := 1000
|
||||
+ multipartMaxParts := godebug.Get("multipartmaxparts")
|
||||
+ if multipartMaxParts != "" {
|
||||
+ if v, err := strconv.Atoi(multipartMaxParts); err == nil && v >= 0 {
|
||||
+ maxParts = v
|
||||
+ }
|
||||
+ }
|
||||
+ maxHeaders := maxMIMEHeaders()
|
||||
+
|
||||
defer func() {
|
||||
if file != nil {
|
||||
if cerr := file.Close(); err == nil {
|
||||
@@ -87,13 +97,17 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
}
|
||||
var copyBuf []byte
|
||||
for {
|
||||
- p, err := r.nextPart(false, maxMemoryBytes)
|
||||
+ p, err := r.nextPart(false, maxMemoryBytes, maxHeaders)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
+ if maxParts <= 0 {
|
||||
+ return nil, ErrMessageTooLarge
|
||||
+ }
|
||||
+ maxParts--
|
||||
|
||||
name := p.FormName()
|
||||
if name == "" {
|
||||
@@ -137,6 +151,9 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
|
||||
if maxMemoryBytes < 0 {
|
||||
return nil, ErrMessageTooLarge
|
||||
}
|
||||
+ for _, v := range p.Header {
|
||||
+ maxHeaders -= int64(len(v))
|
||||
+ }
|
||||
fh := &FileHeader{
|
||||
Filename: filename,
|
||||
Header: p.Header,
|
||||
diff --git a/src/mime/multipart/formdata_test.go b/src/mime/multipart/formdata_test.go
|
||||
index 8ed26e0..c78eeb7 100644
|
||||
--- a/src/mime/multipart/formdata_test.go
|
||||
+++ b/src/mime/multipart/formdata_test.go
|
||||
@@ -360,6 +360,67 @@ func testReadFormManyFiles(t *testing.T, distinct bool) {
|
||||
}
|
||||
}
|
||||
|
||||
+func TestReadFormLimits(t *testing.T) {
|
||||
+ for _, test := range []struct {
|
||||
+ values int
|
||||
+ files int
|
||||
+ extraKeysPerFile int
|
||||
+ wantErr error
|
||||
+ godebug string
|
||||
+ }{
|
||||
+ {values: 1000},
|
||||
+ {values: 1001, wantErr: ErrMessageTooLarge},
|
||||
+ {values: 500, files: 500},
|
||||
+ {values: 501, files: 500, wantErr: ErrMessageTooLarge},
|
||||
+ {files: 1000},
|
||||
+ {files: 1001, wantErr: ErrMessageTooLarge},
|
||||
+ {files: 1, extraKeysPerFile: 9998}, // plus Content-Disposition and Content-Type
|
||||
+ {files: 1, extraKeysPerFile: 10000, wantErr: ErrMessageTooLarge},
|
||||
+ {godebug: "multipartmaxparts=100", values: 100},
|
||||
+ {godebug: "multipartmaxparts=100", values: 101, wantErr: ErrMessageTooLarge},
|
||||
+ {godebug: "multipartmaxheaders=100", files: 2, extraKeysPerFile: 48},
|
||||
+ {godebug: "multipartmaxheaders=100", files: 2, extraKeysPerFile: 50, wantErr: ErrMessageTooLarge},
|
||||
+ } {
|
||||
+ name := fmt.Sprintf("values=%v/files=%v/extraKeysPerFile=%v", test.values, test.files, test.extraKeysPerFile)
|
||||
+ if test.godebug != "" {
|
||||
+ name += fmt.Sprintf("/godebug=%v", test.godebug)
|
||||
+ }
|
||||
+ t.Run(name, func(t *testing.T) {
|
||||
+ if test.godebug != "" {
|
||||
+ t.Setenv("GODEBUG", test.godebug)
|
||||
+ }
|
||||
+ var buf bytes.Buffer
|
||||
+ fw := NewWriter(&buf)
|
||||
+ for i := 0; i < test.values; i++ {
|
||||
+ w, _ := fw.CreateFormField(fmt.Sprintf("field%v", i))
|
||||
+ fmt.Fprintf(w, "value %v", i)
|
||||
+ }
|
||||
+ for i := 0; i < test.files; i++ {
|
||||
+ h := make(textproto.MIMEHeader)
|
||||
+ h.Set("Content-Disposition",
|
||||
+ fmt.Sprintf(`form-data; name="file%v"; filename="file%v"`, i, i))
|
||||
+ h.Set("Content-Type", "application/octet-stream")
|
||||
+ for j := 0; j < test.extraKeysPerFile; j++ {
|
||||
+ h.Set(fmt.Sprintf("k%v", j), "v")
|
||||
+ }
|
||||
+ w, _ := fw.CreatePart(h)
|
||||
+ fmt.Fprintf(w, "value %v", i)
|
||||
+ }
|
||||
+ if err := fw.Close(); err != nil {
|
||||
+ t.Fatal(err)
|
||||
+ }
|
||||
+ fr := NewReader(bytes.NewReader(buf.Bytes()), fw.Boundary())
|
||||
+ form, err := fr.ReadForm(1 << 10)
|
||||
+ if err == nil {
|
||||
+ defer form.RemoveAll()
|
||||
+ }
|
||||
+ if err != test.wantErr {
|
||||
+ t.Errorf("ReadForm = %v, want %v", err, test.wantErr)
|
||||
+ }
|
||||
+ })
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
func BenchmarkReadForm(b *testing.B) {
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
diff --git a/src/mime/multipart/multipart.go b/src/mime/multipart/multipart.go
|
||||
index 958cef8..94464a8 100644
|
||||
--- a/src/mime/multipart/multipart.go
|
||||
+++ b/src/mime/multipart/multipart.go
|
||||
@@ -16,11 +16,13 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
+ "internal/godebug"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"mime/quotedprintable"
|
||||
"net/textproto"
|
||||
+ "strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -121,12 +123,12 @@ func (r *stickyErrorReader) Read(p []byte) (n int, _ error) {
|
||||
return n, r.err
|
||||
}
|
||||
|
||||
-func newPart(mr *Reader, rawPart bool, maxMIMEHeaderSize int64) (*Part, error) {
|
||||
+func newPart(mr *Reader, rawPart bool, maxMIMEHeaderSize, maxMIMEHeaders int64) (*Part, error) {
|
||||
bp := &Part{
|
||||
Header: make(map[string][]string),
|
||||
mr: mr,
|
||||
}
|
||||
- if err := bp.populateHeaders(maxMIMEHeaderSize); err != nil {
|
||||
+ if err := bp.populateHeaders(maxMIMEHeaderSize, maxMIMEHeaders); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bp.r = partReader{bp}
|
||||
@@ -142,9 +144,9 @@ func newPart(mr *Reader, rawPart bool, maxMIMEHeaderSize int64) (*Part, error) {
|
||||
return bp, nil
|
||||
}
|
||||
|
||||
-func (bp *Part) populateHeaders(maxMIMEHeaderSize int64) error {
|
||||
+func (bp *Part) populateHeaders(maxMIMEHeaderSize, maxMIMEHeaders int64) error {
|
||||
r := textproto.NewReader(bp.mr.bufReader)
|
||||
- header, err := readMIMEHeader(r, maxMIMEHeaderSize)
|
||||
+ header, err := readMIMEHeader(r, maxMIMEHeaderSize, maxMIMEHeaders)
|
||||
if err == nil {
|
||||
bp.Header = header
|
||||
}
|
||||
@@ -306,6 +308,19 @@ type Reader struct {
|
||||
// including header keys, values, and map overhead.
|
||||
const maxMIMEHeaderSize = 10 << 20
|
||||
|
||||
+func maxMIMEHeaders() int64 {
|
||||
+ // multipartMaxHeaders is the maximum number of header entries NextPart will return,
|
||||
+ // as well as the maximum combined total of header entries Reader.ReadForm will return
|
||||
+ // in FileHeaders.
|
||||
+ multipartMaxHeaders := godebug.Get("multipartmaxheaders")
|
||||
+ if multipartMaxHeaders != "" {
|
||||
+ if v, err := strconv.ParseInt(multipartMaxHeaders, 10, 64); err == nil && v >= 0 {
|
||||
+ return v
|
||||
+ }
|
||||
+ }
|
||||
+ return 10000
|
||||
+}
|
||||
+
|
||||
// NextPart returns the next part in the multipart or an error.
|
||||
// When there are no more parts, the error io.EOF is returned.
|
||||
//
|
||||
@@ -313,7 +328,7 @@ const maxMIMEHeaderSize = 10 << 20
|
||||
// has a value of "quoted-printable", that header is instead
|
||||
// hidden and the body is transparently decoded during Read calls.
|
||||
func (r *Reader) NextPart() (*Part, error) {
|
||||
- return r.nextPart(false, maxMIMEHeaderSize)
|
||||
+ return r.nextPart(false, maxMIMEHeaderSize, maxMIMEHeaders())
|
||||
}
|
||||
|
||||
// NextRawPart returns the next part in the multipart or an error.
|
||||
@@ -322,10 +337,10 @@ func (r *Reader) NextPart() (*Part, error) {
|
||||
// Unlike NextPart, it does not have special handling for
|
||||
// "Content-Transfer-Encoding: quoted-printable".
|
||||
func (r *Reader) NextRawPart() (*Part, error) {
|
||||
- return r.nextPart(true, maxMIMEHeaderSize)
|
||||
+ return r.nextPart(true, maxMIMEHeaderSize, maxMIMEHeaders())
|
||||
}
|
||||
|
||||
-func (r *Reader) nextPart(rawPart bool, maxMIMEHeaderSize int64) (*Part, error) {
|
||||
+func (r *Reader) nextPart(rawPart bool, maxMIMEHeaderSize, maxMIMEHeaders int64) (*Part, error) {
|
||||
if r.currentPart != nil {
|
||||
r.currentPart.Close()
|
||||
}
|
||||
@@ -350,7 +365,7 @@ func (r *Reader) nextPart(rawPart bool, maxMIMEHeaderSize int64) (*Part, error)
|
||||
|
||||
if r.isBoundaryDelimiterLine(line) {
|
||||
r.partsRead++
|
||||
- bp, err := newPart(r, rawPart, maxMIMEHeaderSize)
|
||||
+ bp, err := newPart(r, rawPart, maxMIMEHeaderSize, maxMIMEHeaders)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
diff --git a/src/mime/multipart/readmimeheader.go b/src/mime/multipart/readmimeheader.go
|
||||
index 6836928..25aa6e2 100644
|
||||
--- a/src/mime/multipart/readmimeheader.go
|
||||
+++ b/src/mime/multipart/readmimeheader.go
|
||||
@@ -11,4 +11,4 @@ import (
|
||||
// readMIMEHeader is defined in package net/textproto.
|
||||
//
|
||||
//go:linkname readMIMEHeader net/textproto.readMIMEHeader
|
||||
-func readMIMEHeader(r *textproto.Reader, lim int64) (textproto.MIMEHeader, error)
|
||||
+func readMIMEHeader(r *textproto.Reader, maxMemory, maxHeaders int64) (textproto.MIMEHeader, error)
|
||||
diff --git a/src/net/textproto/reader.go b/src/net/textproto/reader.go
|
||||
index 1c79f0a..ad2d777 100644
|
||||
--- a/src/net/textproto/reader.go
|
||||
+++ b/src/net/textproto/reader.go
|
||||
@@ -484,12 +484,12 @@ func (r *Reader) ReadDotLines() ([]string, error) {
|
||||
// }
|
||||
//
|
||||
func (r *Reader) ReadMIMEHeader() (MIMEHeader, error) {
|
||||
- return readMIMEHeader(r, math.MaxInt64)
|
||||
+ return readMIMEHeader(r, math.MaxInt64, math.MaxInt64)
|
||||
}
|
||||
|
||||
// readMIMEHeader is a version of ReadMIMEHeader which takes a limit on the header size.
|
||||
// It is called by the mime/multipart package.
|
||||
-func readMIMEHeader(r *Reader, lim int64) (MIMEHeader, error) {
|
||||
+func readMIMEHeader(r *Reader, maxMemory, maxHeaders int64) (MIMEHeader, error) {
|
||||
// Avoid lots of small slice allocations later by allocating one
|
||||
// large one ahead of time which we'll cut up into smaller
|
||||
// slices. If this isn't big enough later, we allocate small ones.
|
||||
@@ -507,7 +507,7 @@ func readMIMEHeader(r *Reader, lim int64) (MIMEHeader, error) {
|
||||
// Account for 400 bytes of overhead for the MIMEHeader, plus 200 bytes per entry.
|
||||
// Benchmarking map creation as of go1.20, a one-entry MIMEHeader is 416 bytes and large
|
||||
// MIMEHeaders average about 200 bytes per entry.
|
||||
- lim -= 400
|
||||
+ maxMemory -= 400
|
||||
const mapEntryOverhead = 200
|
||||
|
||||
// The first line cannot start with a leading space.
|
||||
@@ -539,6 +539,11 @@ func readMIMEHeader(r *Reader, lim int64) (MIMEHeader, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
+ maxHeaders--
|
||||
+ if maxHeaders < 0 {
|
||||
+ return nil, errors.New("message too large")
|
||||
+ }
|
||||
+
|
||||
// backport 5c55ac9bf1e5f779220294c843526536605f42ab
|
||||
//
|
||||
// value is computed as
|
||||
@@ -557,11 +562,11 @@ func readMIMEHeader(r *Reader, lim int64) (MIMEHeader, error) {
|
||||
|
||||
vv := m[key]
|
||||
if vv == nil {
|
||||
- lim -= int64(len(key))
|
||||
- lim -= mapEntryOverhead
|
||||
+ maxMemory -= int64(len(key))
|
||||
+ maxMemory -= mapEntryOverhead
|
||||
}
|
||||
- lim -= int64(len(value))
|
||||
- if lim < 0 {
|
||||
+ maxMemory -= int64(len(value))
|
||||
+ if maxMemory < 0 {
|
||||
// TODO: This should be a distinguishable error (ErrMessageTooLarge)
|
||||
// to allow mime/multipart to detect it.
|
||||
return m, errors.New("message too large")
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 8acd01094d9ee17f6e763a61e49a8a808b3a9ddb Mon Sep 17 00:00:00 2001
|
||||
From: Brad Fitzpatrick <bradfitz@golang.org>
|
||||
Date: Mon, 2 Aug 2021 14:55:51 -0700
|
||||
Subject: [PATCH 1/3] net/netip: add new IP address package
|
||||
Subject: [PATCH 1/6] net/netip: add new IP address package
|
||||
|
||||
Co-authored-by: Alex Willmer <alex@moreati.org.uk> (GitHub @moreati)
|
||||
Co-authored-by: Alexander Yastrebov <yastrebov.alex@gmail.com>
|
||||
@@ -31,7 +31,7 @@ Trust: Brad Fitzpatrick <bradfitz@golang.org>
|
||||
|
||||
Dependency Patch #1
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/a59e33224e42d60a97fa720a45e1b74eb6aaa3d0]
|
||||
Upstream-Status: Backport from https://github.com/golang/go/commit/a59e33224e42d60a97fa720a45e1b74eb6aaa3d0
|
||||
CVE: CVE-2023-24538
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
From 6fc21505614f36178df0dad7034b6b8e3f7588d5 Mon Sep 17 00:00:00 2001
|
||||
From: empijei <robclap8@gmail.com>
|
||||
Date: Fri, 27 Mar 2020 19:27:55 +0100
|
||||
Subject: [PATCH 2/3] html/template,text/template: switch to Unicode escapes
|
||||
Subject: [PATCH 2/6] html/template,text/template: switch to Unicode escapes
|
||||
for JSON compatibility
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
@@ -31,10 +31,238 @@ Upstream-Status: Backport from https://github.com/golang/go/commit/d4d298040d072
|
||||
CVE: CVE-2023-24538
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
src/html/template/js.go | 70 +++++++++++++++++++++++++++-------------------
|
||||
src/text/template/funcs.go | 8 +++---
|
||||
2 files changed, 46 insertions(+), 32 deletions(-)
|
||||
src/html/template/content_test.go | 70 +++++++++++++++++++-------------------
|
||||
src/html/template/escape_test.go | 6 ++--
|
||||
src/html/template/example_test.go | 6 ++--
|
||||
src/html/template/js.go | 70 +++++++++++++++++++++++---------------
|
||||
src/html/template/js_test.go | 68 ++++++++++++++++++------------------
|
||||
src/html/template/template_test.go | 39 +++++++++++++++++++++
|
||||
src/text/template/exec_test.go | 6 ++--
|
||||
src/text/template/funcs.go | 8 ++---
|
||||
8 files changed, 163 insertions(+), 110 deletions(-)
|
||||
|
||||
diff --git a/src/html/template/content_test.go b/src/html/template/content_test.go
|
||||
index 72d56f5..bd86527 100644
|
||||
--- a/src/html/template/content_test.go
|
||||
+++ b/src/html/template/content_test.go
|
||||
@@ -18,7 +18,7 @@ func TestTypedContent(t *testing.T) {
|
||||
HTML(`Hello, <b>World</b> &tc!`),
|
||||
HTMLAttr(` dir="ltr"`),
|
||||
JS(`c && alert("Hello, World!");`),
|
||||
- JSStr(`Hello, World & O'Reilly\x21`),
|
||||
+ JSStr(`Hello, World & O'Reilly\u0021`),
|
||||
URL(`greeting=H%69,&addressee=(World)`),
|
||||
Srcset(`greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`),
|
||||
URL(`,foo/,`),
|
||||
@@ -70,7 +70,7 @@ func TestTypedContent(t *testing.T) {
|
||||
`Hello, <b>World</b> &tc!`,
|
||||
` dir="ltr"`,
|
||||
`c && alert("Hello, World!");`,
|
||||
- `Hello, World & O'Reilly\x21`,
|
||||
+ `Hello, World & O'Reilly\u0021`,
|
||||
`greeting=H%69,&addressee=(World)`,
|
||||
`greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`,
|
||||
`,foo/,`,
|
||||
@@ -100,7 +100,7 @@ func TestTypedContent(t *testing.T) {
|
||||
`Hello, World &tc!`,
|
||||
` dir="ltr"`,
|
||||
`c && alert("Hello, World!");`,
|
||||
- `Hello, World & O'Reilly\x21`,
|
||||
+ `Hello, World & O'Reilly\u0021`,
|
||||
`greeting=H%69,&addressee=(World)`,
|
||||
`greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`,
|
||||
`,foo/,`,
|
||||
@@ -115,7 +115,7 @@ func TestTypedContent(t *testing.T) {
|
||||
`Hello, World &tc!`,
|
||||
` dir="ltr"`,
|
||||
`c && alert("Hello, World!");`,
|
||||
- `Hello, World & O'Reilly\x21`,
|
||||
+ `Hello, World & O'Reilly\u0021`,
|
||||
`greeting=H%69,&addressee=(World)`,
|
||||
`greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`,
|
||||
`,foo/,`,
|
||||
@@ -130,7 +130,7 @@ func TestTypedContent(t *testing.T) {
|
||||
`Hello, <b>World</b> &tc!`,
|
||||
` dir="ltr"`,
|
||||
`c && alert("Hello, World!");`,
|
||||
- `Hello, World & O'Reilly\x21`,
|
||||
+ `Hello, World & O'Reilly\u0021`,
|
||||
`greeting=H%69,&addressee=(World)`,
|
||||
`greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`,
|
||||
`,foo/,`,
|
||||
@@ -146,7 +146,7 @@ func TestTypedContent(t *testing.T) {
|
||||
// Not escaped.
|
||||
`c && alert("Hello, World!");`,
|
||||
// Escape sequence not over-escaped.
|
||||
- `"Hello, World & O'Reilly\x21"`,
|
||||
+ `"Hello, World & O'Reilly\u0021"`,
|
||||
`"greeting=H%69,\u0026addressee=(World)"`,
|
||||
`"greeting=H%69,\u0026addressee=(World) 2x, https://golang.org/favicon.ico 500.5w"`,
|
||||
`",foo/,"`,
|
||||
@@ -162,7 +162,7 @@ func TestTypedContent(t *testing.T) {
|
||||
// Not JS escaped but HTML escaped.
|
||||
`c && alert("Hello, World!");`,
|
||||
// Escape sequence not over-escaped.
|
||||
- `"Hello, World & O'Reilly\x21"`,
|
||||
+ `"Hello, World & O'Reilly\u0021"`,
|
||||
`"greeting=H%69,\u0026addressee=(World)"`,
|
||||
`"greeting=H%69,\u0026addressee=(World) 2x, https://golang.org/favicon.ico 500.5w"`,
|
||||
`",foo/,"`,
|
||||
@@ -171,30 +171,30 @@ func TestTypedContent(t *testing.T) {
|
||||
{
|
||||
`<script>alert("{{.}}")</script>`,
|
||||
[]string{
|
||||
- `\x3cb\x3e \x22foo%\x22 O\x27Reilly \x26bar;`,
|
||||
- `a[href =~ \x22\/\/example.com\x22]#foo`,
|
||||
- `Hello, \x3cb\x3eWorld\x3c\/b\x3e \x26amp;tc!`,
|
||||
- ` dir=\x22ltr\x22`,
|
||||
- `c \x26\x26 alert(\x22Hello, World!\x22);`,
|
||||
+ `\u003cb\u003e \u0022foo%\u0022 O\u0027Reilly \u0026bar;`,
|
||||
+ `a[href =~ \u0022\/\/example.com\u0022]#foo`,
|
||||
+ `Hello, \u003cb\u003eWorld\u003c\/b\u003e \u0026amp;tc!`,
|
||||
+ ` dir=\u0022ltr\u0022`,
|
||||
+ `c \u0026\u0026 alert(\u0022Hello, World!\u0022);`,
|
||||
// Escape sequence not over-escaped.
|
||||
- `Hello, World \x26 O\x27Reilly\x21`,
|
||||
- `greeting=H%69,\x26addressee=(World)`,
|
||||
- `greeting=H%69,\x26addressee=(World) 2x, https:\/\/golang.org\/favicon.ico 500.5w`,
|
||||
+ `Hello, World \u0026 O\u0027Reilly\u0021`,
|
||||
+ `greeting=H%69,\u0026addressee=(World)`,
|
||||
+ `greeting=H%69,\u0026addressee=(World) 2x, https:\/\/golang.org\/favicon.ico 500.5w`,
|
||||
`,foo\/,`,
|
||||
},
|
||||
},
|
||||
{
|
||||
`<script type="text/javascript">alert("{{.}}")</script>`,
|
||||
[]string{
|
||||
- `\x3cb\x3e \x22foo%\x22 O\x27Reilly \x26bar;`,
|
||||
- `a[href =~ \x22\/\/example.com\x22]#foo`,
|
||||
- `Hello, \x3cb\x3eWorld\x3c\/b\x3e \x26amp;tc!`,
|
||||
- ` dir=\x22ltr\x22`,
|
||||
- `c \x26\x26 alert(\x22Hello, World!\x22);`,
|
||||
+ `\u003cb\u003e \u0022foo%\u0022 O\u0027Reilly \u0026bar;`,
|
||||
+ `a[href =~ \u0022\/\/example.com\u0022]#foo`,
|
||||
+ `Hello, \u003cb\u003eWorld\u003c\/b\u003e \u0026amp;tc!`,
|
||||
+ ` dir=\u0022ltr\u0022`,
|
||||
+ `c \u0026\u0026 alert(\u0022Hello, World!\u0022);`,
|
||||
// Escape sequence not over-escaped.
|
||||
- `Hello, World \x26 O\x27Reilly\x21`,
|
||||
- `greeting=H%69,\x26addressee=(World)`,
|
||||
- `greeting=H%69,\x26addressee=(World) 2x, https:\/\/golang.org\/favicon.ico 500.5w`,
|
||||
+ `Hello, World \u0026 O\u0027Reilly\u0021`,
|
||||
+ `greeting=H%69,\u0026addressee=(World)`,
|
||||
+ `greeting=H%69,\u0026addressee=(World) 2x, https:\/\/golang.org\/favicon.ico 500.5w`,
|
||||
`,foo\/,`,
|
||||
},
|
||||
},
|
||||
@@ -208,7 +208,7 @@ func TestTypedContent(t *testing.T) {
|
||||
// Not escaped.
|
||||
`c && alert("Hello, World!");`,
|
||||
// Escape sequence not over-escaped.
|
||||
- `"Hello, World & O'Reilly\x21"`,
|
||||
+ `"Hello, World & O'Reilly\u0021"`,
|
||||
`"greeting=H%69,\u0026addressee=(World)"`,
|
||||
`"greeting=H%69,\u0026addressee=(World) 2x, https://golang.org/favicon.ico 500.5w"`,
|
||||
`",foo/,"`,
|
||||
@@ -224,7 +224,7 @@ func TestTypedContent(t *testing.T) {
|
||||
`Hello, <b>World</b> &tc!`,
|
||||
` dir="ltr"`,
|
||||
`c && alert("Hello, World!");`,
|
||||
- `Hello, World & O'Reilly\x21`,
|
||||
+ `Hello, World & O'Reilly\u0021`,
|
||||
`greeting=H%69,&addressee=(World)`,
|
||||
`greeting=H%69,&addressee=(World) 2x, https://golang.org/favicon.ico 500.5w`,
|
||||
`,foo/,`,
|
||||
@@ -233,15 +233,15 @@ func TestTypedContent(t *testing.T) {
|
||||
{
|
||||
`<button onclick='alert("{{.}}")'>`,
|
||||
[]string{
|
||||
- `\x3cb\x3e \x22foo%\x22 O\x27Reilly \x26bar;`,
|
||||
- `a[href =~ \x22\/\/example.com\x22]#foo`,
|
||||
- `Hello, \x3cb\x3eWorld\x3c\/b\x3e \x26amp;tc!`,
|
||||
- ` dir=\x22ltr\x22`,
|
||||
- `c \x26\x26 alert(\x22Hello, World!\x22);`,
|
||||
+ `\u003cb\u003e \u0022foo%\u0022 O\u0027Reilly \u0026bar;`,
|
||||
+ `a[href =~ \u0022\/\/example.com\u0022]#foo`,
|
||||
+ `Hello, \u003cb\u003eWorld\u003c\/b\u003e \u0026amp;tc!`,
|
||||
+ ` dir=\u0022ltr\u0022`,
|
||||
+ `c \u0026\u0026 alert(\u0022Hello, World!\u0022);`,
|
||||
// Escape sequence not over-escaped.
|
||||
- `Hello, World \x26 O\x27Reilly\x21`,
|
||||
- `greeting=H%69,\x26addressee=(World)`,
|
||||
- `greeting=H%69,\x26addressee=(World) 2x, https:\/\/golang.org\/favicon.ico 500.5w`,
|
||||
+ `Hello, World \u0026 O\u0027Reilly\u0021`,
|
||||
+ `greeting=H%69,\u0026addressee=(World)`,
|
||||
+ `greeting=H%69,\u0026addressee=(World) 2x, https:\/\/golang.org\/favicon.ico 500.5w`,
|
||||
`,foo\/,`,
|
||||
},
|
||||
},
|
||||
@@ -253,7 +253,7 @@ func TestTypedContent(t *testing.T) {
|
||||
`Hello%2c%20%3cb%3eWorld%3c%2fb%3e%20%26amp%3btc%21`,
|
||||
`%20dir%3d%22ltr%22`,
|
||||
`c%20%26%26%20alert%28%22Hello%2c%20World%21%22%29%3b`,
|
||||
- `Hello%2c%20World%20%26%20O%27Reilly%5cx21`,
|
||||
+ `Hello%2c%20World%20%26%20O%27Reilly%5cu0021`,
|
||||
// Quotes and parens are escaped but %69 is not over-escaped. HTML escaping is done.
|
||||
`greeting=H%69,&addressee=%28World%29`,
|
||||
`greeting%3dH%2569%2c%26addressee%3d%28World%29%202x%2c%20https%3a%2f%2fgolang.org%2ffavicon.ico%20500.5w`,
|
||||
@@ -268,7 +268,7 @@ func TestTypedContent(t *testing.T) {
|
||||
`Hello%2c%20%3cb%3eWorld%3c%2fb%3e%20%26amp%3btc%21`,
|
||||
`%20dir%3d%22ltr%22`,
|
||||
`c%20%26%26%20alert%28%22Hello%2c%20World%21%22%29%3b`,
|
||||
- `Hello%2c%20World%20%26%20O%27Reilly%5cx21`,
|
||||
+ `Hello%2c%20World%20%26%20O%27Reilly%5cu0021`,
|
||||
// Quotes and parens are escaped but %69 is not over-escaped. HTML escaping is not done.
|
||||
`greeting=H%69,&addressee=%28World%29`,
|
||||
`greeting%3dH%2569%2c%26addressee%3d%28World%29%202x%2c%20https%3a%2f%2fgolang.org%2ffavicon.ico%20500.5w`,
|
||||
diff --git a/src/html/template/escape_test.go b/src/html/template/escape_test.go
|
||||
index e72a9ba..c709660 100644
|
||||
--- a/src/html/template/escape_test.go
|
||||
+++ b/src/html/template/escape_test.go
|
||||
@@ -238,7 +238,7 @@ func TestEscape(t *testing.T) {
|
||||
{
|
||||
"jsStr",
|
||||
"<button onclick='alert("{{.H}}")'>",
|
||||
- `<button onclick='alert("\x3cHello\x3e")'>`,
|
||||
+ `<button onclick='alert("\u003cHello\u003e")'>`,
|
||||
},
|
||||
{
|
||||
"badMarshaler",
|
||||
@@ -259,7 +259,7 @@ func TestEscape(t *testing.T) {
|
||||
{
|
||||
"jsRe",
|
||||
`<button onclick='alert(/{{"foo+bar"}}/.test(""))'>`,
|
||||
- `<button onclick='alert(/foo\x2bbar/.test(""))'>`,
|
||||
+ `<button onclick='alert(/foo\u002bbar/.test(""))'>`,
|
||||
},
|
||||
{
|
||||
"jsReBlank",
|
||||
@@ -825,7 +825,7 @@ func TestEscapeSet(t *testing.T) {
|
||||
"main": `<button onclick="title='{{template "helper"}}'; ...">{{template "helper"}}</button>`,
|
||||
"helper": `{{11}} of {{"<100>"}}`,
|
||||
},
|
||||
- `<button onclick="title='11 of \x3c100\x3e'; ...">11 of <100></button>`,
|
||||
+ `<button onclick="title='11 of \u003c100\u003e'; ...">11 of <100></button>`,
|
||||
},
|
||||
// A non-recursive template that ends in a different context.
|
||||
// helper starts in jsCtxRegexp and ends in jsCtxDivOp.
|
||||
diff --git a/src/html/template/example_test.go b/src/html/template/example_test.go
|
||||
index 9d965f1..6cf936f 100644
|
||||
--- a/src/html/template/example_test.go
|
||||
+++ b/src/html/template/example_test.go
|
||||
@@ -116,9 +116,9 @@ func Example_escape() {
|
||||
// "Fran & Freddie's Diner" <tasty@example.com>
|
||||
// "Fran & Freddie's Diner" <tasty@example.com>
|
||||
// "Fran & Freddie's Diner"32<tasty@example.com>
|
||||
- // \"Fran \x26 Freddie\'s Diner\" \x3Ctasty@example.com\x3E
|
||||
- // \"Fran \x26 Freddie\'s Diner\" \x3Ctasty@example.com\x3E
|
||||
- // \"Fran \x26 Freddie\'s Diner\"32\x3Ctasty@example.com\x3E
|
||||
+ // \"Fran \u0026 Freddie\'s Diner\" \u003Ctasty@example.com\u003E
|
||||
+ // \"Fran \u0026 Freddie\'s Diner\" \u003Ctasty@example.com\u003E
|
||||
+ // \"Fran \u0026 Freddie\'s Diner\"32\u003Ctasty@example.com\u003E
|
||||
// %22Fran+%26+Freddie%27s+Diner%2232%3Ctasty%40example.com%3E
|
||||
|
||||
}
|
||||
diff --git a/src/html/template/js.go b/src/html/template/js.go
|
||||
index 0e91458..ea9c183 100644
|
||||
--- a/src/html/template/js.go
|
||||
@@ -173,6 +401,217 @@ index 0e91458..ea9c183 100644
|
||||
'?': `\?`,
|
||||
'[': `\[`,
|
||||
'\\': `\\`,
|
||||
diff --git a/src/html/template/js_test.go b/src/html/template/js_test.go
|
||||
index 075adaa..d7ee47b 100644
|
||||
--- a/src/html/template/js_test.go
|
||||
+++ b/src/html/template/js_test.go
|
||||
@@ -137,7 +137,7 @@ func TestJSValEscaper(t *testing.T) {
|
||||
{"foo", `"foo"`},
|
||||
// Newlines.
|
||||
{"\r\n\u2028\u2029", `"\r\n\u2028\u2029"`},
|
||||
- // "\v" == "v" on IE 6 so use "\x0b" instead.
|
||||
+ // "\v" == "v" on IE 6 so use "\u000b" instead.
|
||||
{"\t\x0b", `"\t\u000b"`},
|
||||
{struct{ X, Y int }{1, 2}, `{"X":1,"Y":2}`},
|
||||
{[]interface{}{}, "[]"},
|
||||
@@ -173,7 +173,7 @@ func TestJSStrEscaper(t *testing.T) {
|
||||
}{
|
||||
{"", ``},
|
||||
{"foo", `foo`},
|
||||
- {"\u0000", `\0`},
|
||||
+ {"\u0000", `\u0000`},
|
||||
{"\t", `\t`},
|
||||
{"\n", `\n`},
|
||||
{"\r", `\r`},
|
||||
@@ -183,14 +183,14 @@ func TestJSStrEscaper(t *testing.T) {
|
||||
{"\\n", `\\n`},
|
||||
{"foo\r\nbar", `foo\r\nbar`},
|
||||
// Preserve attribute boundaries.
|
||||
- {`"`, `\x22`},
|
||||
- {`'`, `\x27`},
|
||||
+ {`"`, `\u0022`},
|
||||
+ {`'`, `\u0027`},
|
||||
// Allow embedding in HTML without further escaping.
|
||||
- {`&`, `\x26amp;`},
|
||||
+ {`&`, `\u0026amp;`},
|
||||
// Prevent breaking out of text node and element boundaries.
|
||||
- {"</script>", `\x3c\/script\x3e`},
|
||||
- {"<![CDATA[", `\x3c![CDATA[`},
|
||||
- {"]]>", `]]\x3e`},
|
||||
+ {"</script>", `\u003c\/script\u003e`},
|
||||
+ {"<![CDATA[", `\u003c![CDATA[`},
|
||||
+ {"]]>", `]]\u003e`},
|
||||
// https://dev.w3.org/html5/markup/aria/syntax.html#escaping-text-span
|
||||
// "The text in style, script, title, and textarea elements
|
||||
// must not have an escaping text span start that is not
|
||||
@@ -201,11 +201,11 @@ func TestJSStrEscaper(t *testing.T) {
|
||||
// allow regular text content to be interpreted as script
|
||||
// allowing script execution via a combination of a JS string
|
||||
// injection followed by an HTML text injection.
|
||||
- {"<!--", `\x3c!--`},
|
||||
- {"-->", `--\x3e`},
|
||||
+ {"<!--", `\u003c!--`},
|
||||
+ {"-->", `--\u003e`},
|
||||
// From https://code.google.com/p/doctype/wiki/ArticleUtf7
|
||||
{"+ADw-script+AD4-alert(1)+ADw-/script+AD4-",
|
||||
- `\x2bADw-script\x2bAD4-alert(1)\x2bADw-\/script\x2bAD4-`,
|
||||
+ `\u002bADw-script\u002bAD4-alert(1)\u002bADw-\/script\u002bAD4-`,
|
||||
},
|
||||
// Invalid UTF-8 sequence
|
||||
{"foo\xA0bar", "foo\xA0bar"},
|
||||
@@ -228,7 +228,7 @@ func TestJSRegexpEscaper(t *testing.T) {
|
||||
}{
|
||||
{"", `(?:)`},
|
||||
{"foo", `foo`},
|
||||
- {"\u0000", `\0`},
|
||||
+ {"\u0000", `\u0000`},
|
||||
{"\t", `\t`},
|
||||
{"\n", `\n`},
|
||||
{"\r", `\r`},
|
||||
@@ -238,19 +238,19 @@ func TestJSRegexpEscaper(t *testing.T) {
|
||||
{"\\n", `\\n`},
|
||||
{"foo\r\nbar", `foo\r\nbar`},
|
||||
// Preserve attribute boundaries.
|
||||
- {`"`, `\x22`},
|
||||
- {`'`, `\x27`},
|
||||
+ {`"`, `\u0022`},
|
||||
+ {`'`, `\u0027`},
|
||||
// Allow embedding in HTML without further escaping.
|
||||
- {`&`, `\x26amp;`},
|
||||
+ {`&`, `\u0026amp;`},
|
||||
// Prevent breaking out of text node and element boundaries.
|
||||
- {"</script>", `\x3c\/script\x3e`},
|
||||
- {"<![CDATA[", `\x3c!\[CDATA\[`},
|
||||
- {"]]>", `\]\]\x3e`},
|
||||
+ {"</script>", `\u003c\/script\u003e`},
|
||||
+ {"<![CDATA[", `\u003c!\[CDATA\[`},
|
||||
+ {"]]>", `\]\]\u003e`},
|
||||
// Escaping text spans.
|
||||
- {"<!--", `\x3c!\-\-`},
|
||||
- {"-->", `\-\-\x3e`},
|
||||
+ {"<!--", `\u003c!\-\-`},
|
||||
+ {"-->", `\-\-\u003e`},
|
||||
{"*", `\*`},
|
||||
- {"+", `\x2b`},
|
||||
+ {"+", `\u002b`},
|
||||
{"?", `\?`},
|
||||
{"[](){}", `\[\]\(\)\{\}`},
|
||||
{"$foo|x.y", `\$foo\|x\.y`},
|
||||
@@ -284,27 +284,27 @@ func TestEscapersOnLower7AndSelectHighCodepoints(t *testing.T) {
|
||||
{
|
||||
"jsStrEscaper",
|
||||
jsStrEscaper,
|
||||
- "\\0\x01\x02\x03\x04\x05\x06\x07" +
|
||||
- "\x08\\t\\n\\x0b\\f\\r\x0E\x0F" +
|
||||
- "\x10\x11\x12\x13\x14\x15\x16\x17" +
|
||||
- "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
|
||||
- ` !\x22#$%\x26\x27()*\x2b,-.\/` +
|
||||
- `0123456789:;\x3c=\x3e?` +
|
||||
+ `\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007` +
|
||||
+ `\u0008\t\n\u000b\f\r\u000e\u000f` +
|
||||
+ `\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017` +
|
||||
+ `\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f` +
|
||||
+ ` !\u0022#$%\u0026\u0027()*\u002b,-.\/` +
|
||||
+ `0123456789:;\u003c=\u003e?` +
|
||||
`@ABCDEFGHIJKLMNO` +
|
||||
`PQRSTUVWXYZ[\\]^_` +
|
||||
"`abcdefghijklmno" +
|
||||
- "pqrstuvwxyz{|}~\x7f" +
|
||||
+ "pqrstuvwxyz{|}~\u007f" +
|
||||
"\u00A0\u0100\\u2028\\u2029\ufeff\U0001D11E",
|
||||
},
|
||||
{
|
||||
"jsRegexpEscaper",
|
||||
jsRegexpEscaper,
|
||||
- "\\0\x01\x02\x03\x04\x05\x06\x07" +
|
||||
- "\x08\\t\\n\\x0b\\f\\r\x0E\x0F" +
|
||||
- "\x10\x11\x12\x13\x14\x15\x16\x17" +
|
||||
- "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
|
||||
- ` !\x22#\$%\x26\x27\(\)\*\x2b,\-\.\/` +
|
||||
- `0123456789:;\x3c=\x3e\?` +
|
||||
+ `\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007` +
|
||||
+ `\u0008\t\n\u000b\f\r\u000e\u000f` +
|
||||
+ `\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017` +
|
||||
+ `\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f` +
|
||||
+ ` !\u0022#\$%\u0026\u0027\(\)\*\u002b,\-\.\/` +
|
||||
+ `0123456789:;\u003c=\u003e\?` +
|
||||
`@ABCDEFGHIJKLMNO` +
|
||||
`PQRSTUVWXYZ\[\\\]\^_` +
|
||||
"`abcdefghijklmno" +
|
||||
diff --git a/src/html/template/template_test.go b/src/html/template/template_test.go
|
||||
index 13e6ba4..86bd4db 100644
|
||||
--- a/src/html/template/template_test.go
|
||||
+++ b/src/html/template/template_test.go
|
||||
@@ -6,6 +6,7 @@ package template_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
+ "encoding/json"
|
||||
. "html/template"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -121,6 +122,44 @@ func TestNumbers(t *testing.T) {
|
||||
c.mustExecute(c.root, nil, "12.34 7.5")
|
||||
}
|
||||
|
||||
+func TestStringsInScriptsWithJsonContentTypeAreCorrectlyEscaped(t *testing.T) {
|
||||
+ // See #33671 and #37634 for more context on this.
|
||||
+ tests := []struct{ name, in string }{
|
||||
+ {"empty", ""},
|
||||
+ {"invalid", string(rune(-1))},
|
||||
+ {"null", "\u0000"},
|
||||
+ {"unit separator", "\u001F"},
|
||||
+ {"tab", "\t"},
|
||||
+ {"gt and lt", "<>"},
|
||||
+ {"quotes", `'"`},
|
||||
+ {"ASCII letters", "ASCII letters"},
|
||||
+ {"Unicode", "ʕ⊙ϖ⊙ʔ"},
|
||||
+ {"Pizza", "P"},
|
||||
+ }
|
||||
+ const (
|
||||
+ prefix = `<script type="application/ld+json">`
|
||||
+ suffix = `</script>`
|
||||
+ templ = prefix + `"{{.}}"` + suffix
|
||||
+ )
|
||||
+ tpl := Must(New("JS string is JSON string").Parse(templ))
|
||||
+ for _, tt := range tests {
|
||||
+ t.Run(tt.name, func(t *testing.T) {
|
||||
+ var buf bytes.Buffer
|
||||
+ if err := tpl.Execute(&buf, tt.in); err != nil {
|
||||
+ t.Fatalf("Cannot render template: %v", err)
|
||||
+ }
|
||||
+ trimmed := bytes.TrimSuffix(bytes.TrimPrefix(buf.Bytes(), []byte(prefix)), []byte(suffix))
|
||||
+ var got string
|
||||
+ if err := json.Unmarshal(trimmed, &got); err != nil {
|
||||
+ t.Fatalf("Cannot parse JS string %q as JSON: %v", trimmed[1:len(trimmed)-1], err)
|
||||
+ }
|
||||
+ if got != tt.in {
|
||||
+ t.Errorf("Serialization changed the string value: got %q want %q", got, tt.in)
|
||||
+ }
|
||||
+ })
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
type testCase struct {
|
||||
t *testing.T
|
||||
root *Template
|
||||
diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go
|
||||
index 77294ed..b8a809e 100644
|
||||
--- a/src/text/template/exec_test.go
|
||||
+++ b/src/text/template/exec_test.go
|
||||
@@ -911,9 +911,9 @@ func TestJSEscaping(t *testing.T) {
|
||||
{`Go "jump" \`, `Go \"jump\" \\`},
|
||||
{`Yukihiro says "今日は世界"`, `Yukihiro says \"今日は世界\"`},
|
||||
{"unprintable \uFDFF", `unprintable \uFDFF`},
|
||||
- {`<html>`, `\x3Chtml\x3E`},
|
||||
- {`no = in attributes`, `no \x3D in attributes`},
|
||||
- {`' does not become HTML entity`, `\x26#x27; does not become HTML entity`},
|
||||
+ {`<html>`, `\u003Chtml\u003E`},
|
||||
+ {`no = in attributes`, `no \u003D in attributes`},
|
||||
+ {`' does not become HTML entity`, `\u0026#x27; does not become HTML entity`},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
s := JSEscapeString(tc.in)
|
||||
diff --git a/src/text/template/funcs.go b/src/text/template/funcs.go
|
||||
index 46125bc..f3de9fb 100644
|
||||
--- a/src/text/template/funcs.go
|
||||
|
||||
393
meta/recipes-devtools/go/go-1.14/CVE-2023-24538_3.patch
Normal file
393
meta/recipes-devtools/go/go-1.14/CVE-2023-24538_3.patch
Normal file
@@ -0,0 +1,393 @@
|
||||
From 7ddce23c7d5b728acf8482f5006497c7b9915f8a Mon Sep 17 00:00:00 2001
|
||||
From: Ariel Mashraki <ariel@mashraki.co.il>
|
||||
Date: Wed, 22 Apr 2020 22:17:56 +0300
|
||||
Subject: [PATCH 3/6] text/template: add CommentNode to template parse tree
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Fixes #34652
|
||||
|
||||
Change-Id: Icf6e3eda593fed826736f34f95a9d66f5450cc98
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/229398
|
||||
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
|
||||
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
|
||||
TryBot-Result: Gobot Gobot <gobot@golang.org>
|
||||
|
||||
Dependency Patch #3
|
||||
|
||||
Upstream-Status: Backport from https://github.com/golang/go/commit/c8ea03828b0645b1fd5725888e44873b75fcfbb6
|
||||
CVE: CVE-2023-24538
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
api/next.txt | 19 +++++++++++++++++++
|
||||
src/html/template/escape.go | 2 ++
|
||||
src/html/template/template_test.go | 16 ++++++++++++++++
|
||||
src/text/template/exec.go | 1 +
|
||||
src/text/template/parse/lex.go | 8 +++++++-
|
||||
src/text/template/parse/lex_test.go | 7 +++++--
|
||||
src/text/template/parse/node.go | 33 +++++++++++++++++++++++++++++++++
|
||||
src/text/template/parse/parse.go | 22 +++++++++++++++++++---
|
||||
src/text/template/parse/parse_test.go | 25 +++++++++++++++++++++++++
|
||||
9 files changed, 127 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/api/next.txt b/api/next.txt
|
||||
index e69de29..076f39e 100644
|
||||
--- a/api/next.txt
|
||||
+++ b/api/next.txt
|
||||
@@ -0,0 +1,19 @@
|
||||
+pkg unicode, const Version = "13.0.0"
|
||||
+pkg unicode, var Chorasmian *RangeTable
|
||||
+pkg unicode, var Dives_Akuru *RangeTable
|
||||
+pkg unicode, var Khitan_Small_Script *RangeTable
|
||||
+pkg unicode, var Yezidi *RangeTable
|
||||
+pkg text/template/parse, const NodeComment = 20
|
||||
+pkg text/template/parse, const NodeComment NodeType
|
||||
+pkg text/template/parse, const ParseComments = 1
|
||||
+pkg text/template/parse, const ParseComments Mode
|
||||
+pkg text/template/parse, method (*CommentNode) Copy() Node
|
||||
+pkg text/template/parse, method (*CommentNode) String() string
|
||||
+pkg text/template/parse, method (CommentNode) Position() Pos
|
||||
+pkg text/template/parse, method (CommentNode) Type() NodeType
|
||||
+pkg text/template/parse, type CommentNode struct
|
||||
+pkg text/template/parse, type CommentNode struct, Text string
|
||||
+pkg text/template/parse, type CommentNode struct, embedded NodeType
|
||||
+pkg text/template/parse, type CommentNode struct, embedded Pos
|
||||
+pkg text/template/parse, type Mode uint
|
||||
+pkg text/template/parse, type Tree struct, Mode Mode
|
||||
diff --git a/src/html/template/escape.go b/src/html/template/escape.go
|
||||
index f12dafa..8739735 100644
|
||||
--- a/src/html/template/escape.go
|
||||
+++ b/src/html/template/escape.go
|
||||
@@ -124,6 +124,8 @@ func (e *escaper) escape(c context, n parse.Node) context {
|
||||
switch n := n.(type) {
|
||||
case *parse.ActionNode:
|
||||
return e.escapeAction(c, n)
|
||||
+ case *parse.CommentNode:
|
||||
+ return c
|
||||
case *parse.IfNode:
|
||||
return e.escapeBranch(c, &n.BranchNode, "if")
|
||||
case *parse.ListNode:
|
||||
diff --git a/src/html/template/template_test.go b/src/html/template/template_test.go
|
||||
index 86bd4db..1f2c888 100644
|
||||
--- a/src/html/template/template_test.go
|
||||
+++ b/src/html/template/template_test.go
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
. "html/template"
|
||||
"strings"
|
||||
"testing"
|
||||
+ "text/template/parse"
|
||||
)
|
||||
|
||||
func TestTemplateClone(t *testing.T) {
|
||||
@@ -160,6 +161,21 @@ func TestStringsInScriptsWithJsonContentTypeAreCorrectlyEscaped(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
+func TestSkipEscapeComments(t *testing.T) {
|
||||
+ c := newTestCase(t)
|
||||
+ tr := parse.New("root")
|
||||
+ tr.Mode = parse.ParseComments
|
||||
+ newT, err := tr.Parse("{{/* A comment */}}{{ 1 }}{{/* Another comment */}}", "", "", make(map[string]*parse.Tree))
|
||||
+ if err != nil {
|
||||
+ t.Fatalf("Cannot parse template text: %v", err)
|
||||
+ }
|
||||
+ c.root, err = c.root.AddParseTree("root", newT)
|
||||
+ if err != nil {
|
||||
+ t.Fatalf("Cannot add parse tree to template: %v", err)
|
||||
+ }
|
||||
+ c.mustExecute(c.root, nil, "1")
|
||||
+}
|
||||
+
|
||||
type testCase struct {
|
||||
t *testing.T
|
||||
root *Template
|
||||
diff --git a/src/text/template/exec.go b/src/text/template/exec.go
|
||||
index ac3e741..7ac5175 100644
|
||||
--- a/src/text/template/exec.go
|
||||
+++ b/src/text/template/exec.go
|
||||
@@ -256,6 +256,7 @@ func (s *state) walk(dot reflect.Value, node parse.Node) {
|
||||
if len(node.Pipe.Decl) == 0 {
|
||||
s.printValue(node, val)
|
||||
}
|
||||
+ case *parse.CommentNode:
|
||||
case *parse.IfNode:
|
||||
s.walkIfOrWith(parse.NodeIf, dot, node.Pipe, node.List, node.ElseList)
|
||||
case *parse.ListNode:
|
||||
diff --git a/src/text/template/parse/lex.go b/src/text/template/parse/lex.go
|
||||
index 30371f2..e41373a 100644
|
||||
--- a/src/text/template/parse/lex.go
|
||||
+++ b/src/text/template/parse/lex.go
|
||||
@@ -41,6 +41,7 @@ const (
|
||||
itemBool // boolean constant
|
||||
itemChar // printable ASCII character; grab bag for comma etc.
|
||||
itemCharConstant // character constant
|
||||
+ itemComment // comment text
|
||||
itemComplex // complex constant (1+2i); imaginary is just a number
|
||||
itemAssign // equals ('=') introducing an assignment
|
||||
itemDeclare // colon-equals (':=') introducing a declaration
|
||||
@@ -112,6 +113,7 @@ type lexer struct {
|
||||
leftDelim string // start of action
|
||||
rightDelim string // end of action
|
||||
trimRightDelim string // end of action with trim marker
|
||||
+ emitComment bool // emit itemComment tokens.
|
||||
pos Pos // current position in the input
|
||||
start Pos // start position of this item
|
||||
width Pos // width of last rune read from input
|
||||
@@ -203,7 +205,7 @@ func (l *lexer) drain() {
|
||||
}
|
||||
|
||||
// lex creates a new scanner for the input string.
|
||||
-func lex(name, input, left, right string) *lexer {
|
||||
+func lex(name, input, left, right string, emitComment bool) *lexer {
|
||||
if left == "" {
|
||||
left = leftDelim
|
||||
}
|
||||
@@ -216,6 +218,7 @@ func lex(name, input, left, right string) *lexer {
|
||||
leftDelim: left,
|
||||
rightDelim: right,
|
||||
trimRightDelim: rightTrimMarker + right,
|
||||
+ emitComment: emitComment,
|
||||
items: make(chan item),
|
||||
line: 1,
|
||||
startLine: 1,
|
||||
@@ -323,6 +326,9 @@ func lexComment(l *lexer) stateFn {
|
||||
if !delim {
|
||||
return l.errorf("comment ends before closing delimiter")
|
||||
}
|
||||
+ if l.emitComment {
|
||||
+ l.emit(itemComment)
|
||||
+ }
|
||||
if trimSpace {
|
||||
l.pos += trimMarkerLen
|
||||
}
|
||||
diff --git a/src/text/template/parse/lex_test.go b/src/text/template/parse/lex_test.go
|
||||
index 563c4fc..f6d5f28 100644
|
||||
--- a/src/text/template/parse/lex_test.go
|
||||
+++ b/src/text/template/parse/lex_test.go
|
||||
@@ -15,6 +15,7 @@ var itemName = map[itemType]string{
|
||||
itemBool: "bool",
|
||||
itemChar: "char",
|
||||
itemCharConstant: "charconst",
|
||||
+ itemComment: "comment",
|
||||
itemComplex: "complex",
|
||||
itemDeclare: ":=",
|
||||
itemEOF: "EOF",
|
||||
@@ -90,6 +91,7 @@ var lexTests = []lexTest{
|
||||
{"text", `now is the time`, []item{mkItem(itemText, "now is the time"), tEOF}},
|
||||
{"text with comment", "hello-{{/* this is a comment */}}-world", []item{
|
||||
mkItem(itemText, "hello-"),
|
||||
+ mkItem(itemComment, "/* this is a comment */"),
|
||||
mkItem(itemText, "-world"),
|
||||
tEOF,
|
||||
}},
|
||||
@@ -311,6 +313,7 @@ var lexTests = []lexTest{
|
||||
}},
|
||||
{"trimming spaces before and after comment", "hello- {{- /* hello */ -}} -world", []item{
|
||||
mkItem(itemText, "hello-"),
|
||||
+ mkItem(itemComment, "/* hello */"),
|
||||
mkItem(itemText, "-world"),
|
||||
tEOF,
|
||||
}},
|
||||
@@ -389,7 +392,7 @@ var lexTests = []lexTest{
|
||||
|
||||
// collect gathers the emitted items into a slice.
|
||||
func collect(t *lexTest, left, right string) (items []item) {
|
||||
- l := lex(t.name, t.input, left, right)
|
||||
+ l := lex(t.name, t.input, left, right, true)
|
||||
for {
|
||||
item := l.nextItem()
|
||||
items = append(items, item)
|
||||
@@ -529,7 +532,7 @@ func TestPos(t *testing.T) {
|
||||
func TestShutdown(t *testing.T) {
|
||||
// We need to duplicate template.Parse here to hold on to the lexer.
|
||||
const text = "erroneous{{define}}{{else}}1234"
|
||||
- lexer := lex("foo", text, "{{", "}}")
|
||||
+ lexer := lex("foo", text, "{{", "}}", false)
|
||||
_, err := New("root").parseLexer(lexer)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error")
|
||||
diff --git a/src/text/template/parse/node.go b/src/text/template/parse/node.go
|
||||
index 1c116ea..a9dad5e 100644
|
||||
--- a/src/text/template/parse/node.go
|
||||
+++ b/src/text/template/parse/node.go
|
||||
@@ -70,6 +70,7 @@ const (
|
||||
NodeTemplate // A template invocation action.
|
||||
NodeVariable // A $ variable.
|
||||
NodeWith // A with action.
|
||||
+ NodeComment // A comment.
|
||||
)
|
||||
|
||||
// Nodes.
|
||||
@@ -149,6 +150,38 @@ func (t *TextNode) Copy() Node {
|
||||
return &TextNode{tr: t.tr, NodeType: NodeText, Pos: t.Pos, Text: append([]byte{}, t.Text...)}
|
||||
}
|
||||
|
||||
+// CommentNode holds a comment.
|
||||
+type CommentNode struct {
|
||||
+ NodeType
|
||||
+ Pos
|
||||
+ tr *Tree
|
||||
+ Text string // Comment text.
|
||||
+}
|
||||
+
|
||||
+func (t *Tree) newComment(pos Pos, text string) *CommentNode {
|
||||
+ return &CommentNode{tr: t, NodeType: NodeComment, Pos: pos, Text: text}
|
||||
+}
|
||||
+
|
||||
+func (c *CommentNode) String() string {
|
||||
+ var sb strings.Builder
|
||||
+ c.writeTo(&sb)
|
||||
+ return sb.String()
|
||||
+}
|
||||
+
|
||||
+func (c *CommentNode) writeTo(sb *strings.Builder) {
|
||||
+ sb.WriteString("{{")
|
||||
+ sb.WriteString(c.Text)
|
||||
+ sb.WriteString("}}")
|
||||
+}
|
||||
+
|
||||
+func (c *CommentNode) tree() *Tree {
|
||||
+ return c.tr
|
||||
+}
|
||||
+
|
||||
+func (c *CommentNode) Copy() Node {
|
||||
+ return &CommentNode{tr: c.tr, NodeType: NodeComment, Pos: c.Pos, Text: c.Text}
|
||||
+}
|
||||
+
|
||||
// PipeNode holds a pipeline with optional declaration
|
||||
type PipeNode struct {
|
||||
NodeType
|
||||
diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go
|
||||
index c9b80f4..496d8bf 100644
|
||||
--- a/src/text/template/parse/parse.go
|
||||
+++ b/src/text/template/parse/parse.go
|
||||
@@ -21,6 +21,7 @@ type Tree struct {
|
||||
Name string // name of the template represented by the tree.
|
||||
ParseName string // name of the top-level template during parsing, for error messages.
|
||||
Root *ListNode // top-level root of the tree.
|
||||
+ Mode Mode // parsing mode.
|
||||
text string // text parsed to create the template (or its parent)
|
||||
// Parsing only; cleared after parse.
|
||||
funcs []map[string]interface{}
|
||||
@@ -29,8 +30,16 @@ type Tree struct {
|
||||
peekCount int
|
||||
vars []string // variables defined at the moment.
|
||||
treeSet map[string]*Tree
|
||||
+ mode Mode
|
||||
}
|
||||
|
||||
+// A mode value is a set of flags (or 0). Modes control parser behavior.
|
||||
+type Mode uint
|
||||
+
|
||||
+const (
|
||||
+ ParseComments Mode = 1 << iota // parse comments and add them to AST
|
||||
+)
|
||||
+
|
||||
// Copy returns a copy of the Tree. Any parsing state is discarded.
|
||||
func (t *Tree) Copy() *Tree {
|
||||
if t == nil {
|
||||
@@ -220,7 +229,8 @@ func (t *Tree) stopParse() {
|
||||
func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]interface{}) (tree *Tree, err error) {
|
||||
defer t.recover(&err)
|
||||
t.ParseName = t.Name
|
||||
- t.startParse(funcs, lex(t.Name, text, leftDelim, rightDelim), treeSet)
|
||||
+ emitComment := t.Mode&ParseComments != 0
|
||||
+ t.startParse(funcs, lex(t.Name, text, leftDelim, rightDelim, emitComment), treeSet)
|
||||
t.text = text
|
||||
t.parse()
|
||||
t.add()
|
||||
@@ -240,12 +250,14 @@ func (t *Tree) add() {
|
||||
}
|
||||
}
|
||||
|
||||
-// IsEmptyTree reports whether this tree (node) is empty of everything but space.
|
||||
+// IsEmptyTree reports whether this tree (node) is empty of everything but space or comments.
|
||||
func IsEmptyTree(n Node) bool {
|
||||
switch n := n.(type) {
|
||||
case nil:
|
||||
return true
|
||||
case *ActionNode:
|
||||
+ case *CommentNode:
|
||||
+ return true
|
||||
case *IfNode:
|
||||
case *ListNode:
|
||||
for _, node := range n.Nodes {
|
||||
@@ -276,6 +288,7 @@ func (t *Tree) parse() {
|
||||
if t.nextNonSpace().typ == itemDefine {
|
||||
newT := New("definition") // name will be updated once we know it.
|
||||
newT.text = t.text
|
||||
+ newT.Mode = t.Mode
|
||||
newT.ParseName = t.ParseName
|
||||
newT.startParse(t.funcs, t.lex, t.treeSet)
|
||||
newT.parseDefinition()
|
||||
@@ -331,13 +344,15 @@ func (t *Tree) itemList() (list *ListNode, next Node) {
|
||||
}
|
||||
|
||||
// textOrAction:
|
||||
-// text | action
|
||||
+// text | comment | action
|
||||
func (t *Tree) textOrAction() Node {
|
||||
switch token := t.nextNonSpace(); token.typ {
|
||||
case itemText:
|
||||
return t.newText(token.pos, token.val)
|
||||
case itemLeftDelim:
|
||||
return t.action()
|
||||
+ case itemComment:
|
||||
+ return t.newComment(token.pos, token.val)
|
||||
default:
|
||||
t.unexpected(token, "input")
|
||||
}
|
||||
@@ -539,6 +554,7 @@ func (t *Tree) blockControl() Node {
|
||||
|
||||
block := New(name) // name will be updated once we know it.
|
||||
block.text = t.text
|
||||
+ block.Mode = t.Mode
|
||||
block.ParseName = t.ParseName
|
||||
block.startParse(t.funcs, t.lex, t.treeSet)
|
||||
var end Node
|
||||
diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go
|
||||
index 4e09a78..d9c13c5 100644
|
||||
--- a/src/text/template/parse/parse_test.go
|
||||
+++ b/src/text/template/parse/parse_test.go
|
||||
@@ -348,6 +348,30 @@ func TestParseCopy(t *testing.T) {
|
||||
testParse(true, t)
|
||||
}
|
||||
|
||||
+func TestParseWithComments(t *testing.T) {
|
||||
+ textFormat = "%q"
|
||||
+ defer func() { textFormat = "%s" }()
|
||||
+ tests := [...]parseTest{
|
||||
+ {"comment", "{{/*\n\n\n*/}}", noError, "{{/*\n\n\n*/}}"},
|
||||
+ {"comment trim left", "x \r\n\t{{- /* hi */}}", noError, `"x"{{/* hi */}}`},
|
||||
+ {"comment trim right", "{{/* hi */ -}}\n\n\ty", noError, `{{/* hi */}}"y"`},
|
||||
+ {"comment trim left and right", "x \r\n\t{{- /* */ -}}\n\n\ty", noError, `"x"{{/* */}}"y"`},
|
||||
+ }
|
||||
+ for _, test := range tests {
|
||||
+ t.Run(test.name, func(t *testing.T) {
|
||||
+ tr := New(test.name)
|
||||
+ tr.Mode = ParseComments
|
||||
+ tmpl, err := tr.Parse(test.input, "", "", make(map[string]*Tree))
|
||||
+ if err != nil {
|
||||
+ t.Errorf("%q: expected error; got none", test.name)
|
||||
+ }
|
||||
+ if result := tmpl.Root.String(); result != test.result {
|
||||
+ t.Errorf("%s=(%q): got\n\t%v\nexpected\n\t%v", test.name, test.input, result, test.result)
|
||||
+ }
|
||||
+ })
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
type isEmptyTest struct {
|
||||
name string
|
||||
input string
|
||||
@@ -358,6 +382,7 @@ var isEmptyTests = []isEmptyTest{
|
||||
{"empty", ``, true},
|
||||
{"nonempty", `hello`, false},
|
||||
{"spaces only", " \t\n \t\n", true},
|
||||
+ {"comment only", "{{/* comment */}}", true},
|
||||
{"definition", `{{define "x"}}something{{end}}`, true},
|
||||
{"definitions and space", "{{define `x`}}something{{end}}\n\n{{define `y`}}something{{end}}\n\n", true},
|
||||
{"definitions and text", "{{define `x`}}something{{end}}\nx\n{{define `y`}}something{{end}}\ny\n", false},
|
||||
--
|
||||
2.7.4
|
||||
497
meta/recipes-devtools/go/go-1.14/CVE-2023-24538_4.patch
Normal file
497
meta/recipes-devtools/go/go-1.14/CVE-2023-24538_4.patch
Normal file
@@ -0,0 +1,497 @@
|
||||
From 760d88497091fb5d6d231a18e6f4e06ecb9af9b2 Mon Sep 17 00:00:00 2001
|
||||
From: Russ Cox <rsc@golang.org>
|
||||
Date: Thu, 10 Sep 2020 18:53:26 -0400
|
||||
Subject: [PATCH 4/6] text/template: allow newlines inside action delimiters
|
||||
|
||||
This allows multiline constructs like:
|
||||
|
||||
{{"hello" |
|
||||
printf}}
|
||||
|
||||
Now that unclosed actions can span multiple lines,
|
||||
track and report the start of the action when reporting errors.
|
||||
|
||||
Also clean up a few "unexpected <error message>" to be just "<error message>".
|
||||
|
||||
Fixes #29770.
|
||||
|
||||
Change-Id: I54c6c016029a8328b7902a4b6d85eab713ec3285
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/254257
|
||||
Trust: Russ Cox <rsc@golang.org>
|
||||
Run-TryBot: Russ Cox <rsc@golang.org>
|
||||
TryBot-Result: Go Bot <gobot@golang.org>
|
||||
Reviewed-by: Rob Pike <r@golang.org>
|
||||
|
||||
Dependency Patch #4
|
||||
|
||||
Upstream-Status: Backport from https://github.com/golang/go/commit/9384d34c58099657bb1b133beaf3ff37ada9b017
|
||||
CVE: CVE-2023-24538
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
src/text/template/doc.go | 21 ++++-----
|
||||
src/text/template/exec_test.go | 2 +-
|
||||
src/text/template/parse/lex.go | 84 +++++++++++++++++------------------
|
||||
src/text/template/parse/lex_test.go | 2 +-
|
||||
src/text/template/parse/parse.go | 59 +++++++++++++-----------
|
||||
src/text/template/parse/parse_test.go | 36 ++++++++++++---
|
||||
6 files changed, 117 insertions(+), 87 deletions(-)
|
||||
|
||||
diff --git a/src/text/template/doc.go b/src/text/template/doc.go
|
||||
index 4b0efd2..7b30294 100644
|
||||
--- a/src/text/template/doc.go
|
||||
+++ b/src/text/template/doc.go
|
||||
@@ -40,16 +40,17 @@ More intricate examples appear below.
|
||||
Text and spaces
|
||||
|
||||
By default, all text between actions is copied verbatim when the template is
|
||||
-executed. For example, the string " items are made of " in the example above appears
|
||||
-on standard output when the program is run.
|
||||
-
|
||||
-However, to aid in formatting template source code, if an action's left delimiter
|
||||
-(by default "{{") is followed immediately by a minus sign and ASCII space character
|
||||
-("{{- "), all trailing white space is trimmed from the immediately preceding text.
|
||||
-Similarly, if the right delimiter ("}}") is preceded by a space and minus sign
|
||||
-(" -}}"), all leading white space is trimmed from the immediately following text.
|
||||
-In these trim markers, the ASCII space must be present; "{{-3}}" parses as an
|
||||
-action containing the number -3.
|
||||
+executed. For example, the string " items are made of " in the example above
|
||||
+appears on standard output when the program is run.
|
||||
+
|
||||
+However, to aid in formatting template source code, if an action's left
|
||||
+delimiter (by default "{{") is followed immediately by a minus sign and white
|
||||
+space, all trailing white space is trimmed from the immediately preceding text.
|
||||
+Similarly, if the right delimiter ("}}") is preceded by white space and a minus
|
||||
+sign, all leading white space is trimmed from the immediately following text.
|
||||
+In these trim markers, the white space must be present:
|
||||
+"{{- 3}}" is like "{{3}}" but trims the immediately preceding text, while
|
||||
+"{{-3}}" parses as an action containing the number -3.
|
||||
|
||||
For instance, when executing the template whose source is
|
||||
|
||||
diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go
|
||||
index b8a809e..3309b33 100644
|
||||
--- a/src/text/template/exec_test.go
|
||||
+++ b/src/text/template/exec_test.go
|
||||
@@ -1295,7 +1295,7 @@ func TestUnterminatedStringError(t *testing.T) {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
str := err.Error()
|
||||
- if !strings.Contains(str, "X:3: unexpected unterminated raw quoted string") {
|
||||
+ if !strings.Contains(str, "X:3: unterminated raw quoted string") {
|
||||
t.Fatalf("unexpected error: %s", str)
|
||||
}
|
||||
}
|
||||
diff --git a/src/text/template/parse/lex.go b/src/text/template/parse/lex.go
|
||||
index e41373a..6784071 100644
|
||||
--- a/src/text/template/parse/lex.go
|
||||
+++ b/src/text/template/parse/lex.go
|
||||
@@ -92,15 +92,14 @@ const eof = -1
|
||||
// If the action begins "{{- " rather than "{{", then all space/tab/newlines
|
||||
// preceding the action are trimmed; conversely if it ends " -}}" the
|
||||
// leading spaces are trimmed. This is done entirely in the lexer; the
|
||||
-// parser never sees it happen. We require an ASCII space to be
|
||||
-// present to avoid ambiguity with things like "{{-3}}". It reads
|
||||
+// parser never sees it happen. We require an ASCII space (' ', \t, \r, \n)
|
||||
+// to be present to avoid ambiguity with things like "{{-3}}". It reads
|
||||
// better with the space present anyway. For simplicity, only ASCII
|
||||
-// space does the job.
|
||||
+// does the job.
|
||||
const (
|
||||
- spaceChars = " \t\r\n" // These are the space characters defined by Go itself.
|
||||
- leftTrimMarker = "- " // Attached to left delimiter, trims trailing spaces from preceding text.
|
||||
- rightTrimMarker = " -" // Attached to right delimiter, trims leading spaces from following text.
|
||||
- trimMarkerLen = Pos(len(leftTrimMarker))
|
||||
+ spaceChars = " \t\r\n" // These are the space characters defined by Go itself.
|
||||
+ trimMarker = '-' // Attached to left/right delimiter, trims trailing spaces from preceding/following text.
|
||||
+ trimMarkerLen = Pos(1 + 1) // marker plus space before or after
|
||||
)
|
||||
|
||||
// stateFn represents the state of the scanner as a function that returns the next state.
|
||||
@@ -108,19 +107,18 @@ type stateFn func(*lexer) stateFn
|
||||
|
||||
// lexer holds the state of the scanner.
|
||||
type lexer struct {
|
||||
- name string // the name of the input; used only for error reports
|
||||
- input string // the string being scanned
|
||||
- leftDelim string // start of action
|
||||
- rightDelim string // end of action
|
||||
- trimRightDelim string // end of action with trim marker
|
||||
- emitComment bool // emit itemComment tokens.
|
||||
- pos Pos // current position in the input
|
||||
- start Pos // start position of this item
|
||||
- width Pos // width of last rune read from input
|
||||
- items chan item // channel of scanned items
|
||||
- parenDepth int // nesting depth of ( ) exprs
|
||||
- line int // 1+number of newlines seen
|
||||
- startLine int // start line of this item
|
||||
+ name string // the name of the input; used only for error reports
|
||||
+ input string // the string being scanned
|
||||
+ leftDelim string // start of action
|
||||
+ rightDelim string // end of action
|
||||
+ emitComment bool // emit itemComment tokens.
|
||||
+ pos Pos // current position in the input
|
||||
+ start Pos // start position of this item
|
||||
+ width Pos // width of last rune read from input
|
||||
+ items chan item // channel of scanned items
|
||||
+ parenDepth int // nesting depth of ( ) exprs
|
||||
+ line int // 1+number of newlines seen
|
||||
+ startLine int // start line of this item
|
||||
}
|
||||
|
||||
// next returns the next rune in the input.
|
||||
@@ -213,15 +211,14 @@ func lex(name, input, left, right string, emitComment bool) *lexer {
|
||||
right = rightDelim
|
||||
}
|
||||
l := &lexer{
|
||||
- name: name,
|
||||
- input: input,
|
||||
- leftDelim: left,
|
||||
- rightDelim: right,
|
||||
- trimRightDelim: rightTrimMarker + right,
|
||||
- emitComment: emitComment,
|
||||
- items: make(chan item),
|
||||
- line: 1,
|
||||
- startLine: 1,
|
||||
+ name: name,
|
||||
+ input: input,
|
||||
+ leftDelim: left,
|
||||
+ rightDelim: right,
|
||||
+ emitComment: emitComment,
|
||||
+ items: make(chan item),
|
||||
+ line: 1,
|
||||
+ startLine: 1,
|
||||
}
|
||||
go l.run()
|
||||
return l
|
||||
@@ -251,7 +248,7 @@ func lexText(l *lexer) stateFn {
|
||||
ldn := Pos(len(l.leftDelim))
|
||||
l.pos += Pos(x)
|
||||
trimLength := Pos(0)
|
||||
- if strings.HasPrefix(l.input[l.pos+ldn:], leftTrimMarker) {
|
||||
+ if hasLeftTrimMarker(l.input[l.pos+ldn:]) {
|
||||
trimLength = rightTrimLength(l.input[l.start:l.pos])
|
||||
}
|
||||
l.pos -= trimLength
|
||||
@@ -280,7 +277,7 @@ func rightTrimLength(s string) Pos {
|
||||
|
||||
// atRightDelim reports whether the lexer is at a right delimiter, possibly preceded by a trim marker.
|
||||
func (l *lexer) atRightDelim() (delim, trimSpaces bool) {
|
||||
- if strings.HasPrefix(l.input[l.pos:], l.trimRightDelim) { // With trim marker.
|
||||
+ if hasRightTrimMarker(l.input[l.pos:]) && strings.HasPrefix(l.input[l.pos+trimMarkerLen:], l.rightDelim) { // With trim marker.
|
||||
return true, true
|
||||
}
|
||||
if strings.HasPrefix(l.input[l.pos:], l.rightDelim) { // Without trim marker.
|
||||
@@ -297,7 +294,7 @@ func leftTrimLength(s string) Pos {
|
||||
// lexLeftDelim scans the left delimiter, which is known to be present, possibly with a trim marker.
|
||||
func lexLeftDelim(l *lexer) stateFn {
|
||||
l.pos += Pos(len(l.leftDelim))
|
||||
- trimSpace := strings.HasPrefix(l.input[l.pos:], leftTrimMarker)
|
||||
+ trimSpace := hasLeftTrimMarker(l.input[l.pos:])
|
||||
afterMarker := Pos(0)
|
||||
if trimSpace {
|
||||
afterMarker = trimMarkerLen
|
||||
@@ -342,7 +339,7 @@ func lexComment(l *lexer) stateFn {
|
||||
|
||||
// lexRightDelim scans the right delimiter, which is known to be present, possibly with a trim marker.
|
||||
func lexRightDelim(l *lexer) stateFn {
|
||||
- trimSpace := strings.HasPrefix(l.input[l.pos:], rightTrimMarker)
|
||||
+ trimSpace := hasRightTrimMarker(l.input[l.pos:])
|
||||
if trimSpace {
|
||||
l.pos += trimMarkerLen
|
||||
l.ignore()
|
||||
@@ -369,7 +366,7 @@ func lexInsideAction(l *lexer) stateFn {
|
||||
return l.errorf("unclosed left paren")
|
||||
}
|
||||
switch r := l.next(); {
|
||||
- case r == eof || isEndOfLine(r):
|
||||
+ case r == eof:
|
||||
return l.errorf("unclosed action")
|
||||
case isSpace(r):
|
||||
l.backup() // Put space back in case we have " -}}".
|
||||
@@ -439,7 +436,7 @@ func lexSpace(l *lexer) stateFn {
|
||||
}
|
||||
// Be careful about a trim-marked closing delimiter, which has a minus
|
||||
// after a space. We know there is a space, so check for the '-' that might follow.
|
||||
- if strings.HasPrefix(l.input[l.pos-1:], l.trimRightDelim) {
|
||||
+ if hasRightTrimMarker(l.input[l.pos-1:]) && strings.HasPrefix(l.input[l.pos-1+trimMarkerLen:], l.rightDelim) {
|
||||
l.backup() // Before the space.
|
||||
if numSpaces == 1 {
|
||||
return lexRightDelim // On the delim, so go right to that.
|
||||
@@ -526,7 +523,7 @@ func lexFieldOrVariable(l *lexer, typ itemType) stateFn {
|
||||
// day to implement arithmetic.
|
||||
func (l *lexer) atTerminator() bool {
|
||||
r := l.peek()
|
||||
- if isSpace(r) || isEndOfLine(r) {
|
||||
+ if isSpace(r) {
|
||||
return true
|
||||
}
|
||||
switch r {
|
||||
@@ -657,15 +654,18 @@ Loop:
|
||||
|
||||
// isSpace reports whether r is a space character.
|
||||
func isSpace(r rune) bool {
|
||||
- return r == ' ' || r == '\t'
|
||||
-}
|
||||
-
|
||||
-// isEndOfLine reports whether r is an end-of-line character.
|
||||
-func isEndOfLine(r rune) bool {
|
||||
- return r == '\r' || r == '\n'
|
||||
+ return r == ' ' || r == '\t' || r == '\r' || r == '\n'
|
||||
}
|
||||
|
||||
// isAlphaNumeric reports whether r is an alphabetic, digit, or underscore.
|
||||
func isAlphaNumeric(r rune) bool {
|
||||
return r == '_' || unicode.IsLetter(r) || unicode.IsDigit(r)
|
||||
}
|
||||
+
|
||||
+func hasLeftTrimMarker(s string) bool {
|
||||
+ return len(s) >= 2 && s[0] == trimMarker && isSpace(rune(s[1]))
|
||||
+}
|
||||
+
|
||||
+func hasRightTrimMarker(s string) bool {
|
||||
+ return len(s) >= 2 && isSpace(rune(s[0])) && s[1] == trimMarker
|
||||
+}
|
||||
diff --git a/src/text/template/parse/lex_test.go b/src/text/template/parse/lex_test.go
|
||||
index f6d5f28..6510eed 100644
|
||||
--- a/src/text/template/parse/lex_test.go
|
||||
+++ b/src/text/template/parse/lex_test.go
|
||||
@@ -323,7 +323,7 @@ var lexTests = []lexTest{
|
||||
tLeft,
|
||||
mkItem(itemError, "unrecognized character in action: U+0001"),
|
||||
}},
|
||||
- {"unclosed action", "{{\n}}", []item{
|
||||
+ {"unclosed action", "{{", []item{
|
||||
tLeft,
|
||||
mkItem(itemError, "unclosed action"),
|
||||
}},
|
||||
diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go
|
||||
index 496d8bf..5e6e512 100644
|
||||
--- a/src/text/template/parse/parse.go
|
||||
+++ b/src/text/template/parse/parse.go
|
||||
@@ -24,13 +24,14 @@ type Tree struct {
|
||||
Mode Mode // parsing mode.
|
||||
text string // text parsed to create the template (or its parent)
|
||||
// Parsing only; cleared after parse.
|
||||
- funcs []map[string]interface{}
|
||||
- lex *lexer
|
||||
- token [3]item // three-token lookahead for parser.
|
||||
- peekCount int
|
||||
- vars []string // variables defined at the moment.
|
||||
- treeSet map[string]*Tree
|
||||
- mode Mode
|
||||
+ funcs []map[string]interface{}
|
||||
+ lex *lexer
|
||||
+ token [3]item // three-token lookahead for parser.
|
||||
+ peekCount int
|
||||
+ vars []string // variables defined at the moment.
|
||||
+ treeSet map[string]*Tree
|
||||
+ actionLine int // line of left delim starting action
|
||||
+ mode Mode
|
||||
}
|
||||
|
||||
// A mode value is a set of flags (or 0). Modes control parser behavior.
|
||||
@@ -187,6 +188,16 @@ func (t *Tree) expectOneOf(expected1, expected2 itemType, context string) item {
|
||||
|
||||
// unexpected complains about the token and terminates processing.
|
||||
func (t *Tree) unexpected(token item, context string) {
|
||||
+ if token.typ == itemError {
|
||||
+ extra := ""
|
||||
+ if t.actionLine != 0 && t.actionLine != token.line {
|
||||
+ extra = fmt.Sprintf(" in action started at %s:%d", t.ParseName, t.actionLine)
|
||||
+ if strings.HasSuffix(token.val, " action") {
|
||||
+ extra = extra[len(" in action"):] // avoid "action in action"
|
||||
+ }
|
||||
+ }
|
||||
+ t.errorf("%s%s", token, extra)
|
||||
+ }
|
||||
t.errorf("unexpected %s in %s", token, context)
|
||||
}
|
||||
|
||||
@@ -350,6 +361,8 @@ func (t *Tree) textOrAction() Node {
|
||||
case itemText:
|
||||
return t.newText(token.pos, token.val)
|
||||
case itemLeftDelim:
|
||||
+ t.actionLine = token.line
|
||||
+ defer t.clearActionLine()
|
||||
return t.action()
|
||||
case itemComment:
|
||||
return t.newComment(token.pos, token.val)
|
||||
@@ -359,6 +372,10 @@ func (t *Tree) textOrAction() Node {
|
||||
return nil
|
||||
}
|
||||
|
||||
+func (t *Tree) clearActionLine() {
|
||||
+ t.actionLine = 0
|
||||
+}
|
||||
+
|
||||
// Action:
|
||||
// control
|
||||
// command ("|" command)*
|
||||
@@ -384,12 +401,12 @@ func (t *Tree) action() (n Node) {
|
||||
t.backup()
|
||||
token := t.peek()
|
||||
// Do not pop variables; they persist until "end".
|
||||
- return t.newAction(token.pos, token.line, t.pipeline("command"))
|
||||
+ return t.newAction(token.pos, token.line, t.pipeline("command", itemRightDelim))
|
||||
}
|
||||
|
||||
// Pipeline:
|
||||
// declarations? command ('|' command)*
|
||||
-func (t *Tree) pipeline(context string) (pipe *PipeNode) {
|
||||
+func (t *Tree) pipeline(context string, end itemType) (pipe *PipeNode) {
|
||||
token := t.peekNonSpace()
|
||||
pipe = t.newPipeline(token.pos, token.line, nil)
|
||||
// Are there declarations or assignments?
|
||||
@@ -430,12 +447,9 @@ decls:
|
||||
}
|
||||
for {
|
||||
switch token := t.nextNonSpace(); token.typ {
|
||||
- case itemRightDelim, itemRightParen:
|
||||
+ case end:
|
||||
// At this point, the pipeline is complete
|
||||
t.checkPipeline(pipe, context)
|
||||
- if token.typ == itemRightParen {
|
||||
- t.backup()
|
||||
- }
|
||||
return
|
||||
case itemBool, itemCharConstant, itemComplex, itemDot, itemField, itemIdentifier,
|
||||
itemNumber, itemNil, itemRawString, itemString, itemVariable, itemLeftParen:
|
||||
@@ -464,7 +478,7 @@ func (t *Tree) checkPipeline(pipe *PipeNode, context string) {
|
||||
|
||||
func (t *Tree) parseControl(allowElseIf bool, context string) (pos Pos, line int, pipe *PipeNode, list, elseList *ListNode) {
|
||||
defer t.popVars(len(t.vars))
|
||||
- pipe = t.pipeline(context)
|
||||
+ pipe = t.pipeline(context, itemRightDelim)
|
||||
var next Node
|
||||
list, next = t.itemList()
|
||||
switch next.Type() {
|
||||
@@ -550,7 +564,7 @@ func (t *Tree) blockControl() Node {
|
||||
|
||||
token := t.nextNonSpace()
|
||||
name := t.parseTemplateName(token, context)
|
||||
- pipe := t.pipeline(context)
|
||||
+ pipe := t.pipeline(context, itemRightDelim)
|
||||
|
||||
block := New(name) // name will be updated once we know it.
|
||||
block.text = t.text
|
||||
@@ -580,7 +594,7 @@ func (t *Tree) templateControl() Node {
|
||||
if t.nextNonSpace().typ != itemRightDelim {
|
||||
t.backup()
|
||||
// Do not pop variables; they persist until "end".
|
||||
- pipe = t.pipeline(context)
|
||||
+ pipe = t.pipeline(context, itemRightDelim)
|
||||
}
|
||||
return t.newTemplate(token.pos, token.line, name, pipe)
|
||||
}
|
||||
@@ -614,13 +628,12 @@ func (t *Tree) command() *CommandNode {
|
||||
switch token := t.next(); token.typ {
|
||||
case itemSpace:
|
||||
continue
|
||||
- case itemError:
|
||||
- t.errorf("%s", token.val)
|
||||
case itemRightDelim, itemRightParen:
|
||||
t.backup()
|
||||
case itemPipe:
|
||||
+ // nothing here; break loop below
|
||||
default:
|
||||
- t.errorf("unexpected %s in operand", token)
|
||||
+ t.unexpected(token, "operand")
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -675,8 +688,6 @@ func (t *Tree) operand() Node {
|
||||
// A nil return means the next item is not a term.
|
||||
func (t *Tree) term() Node {
|
||||
switch token := t.nextNonSpace(); token.typ {
|
||||
- case itemError:
|
||||
- t.errorf("%s", token.val)
|
||||
case itemIdentifier:
|
||||
if !t.hasFunction(token.val) {
|
||||
t.errorf("function %q not defined", token.val)
|
||||
@@ -699,11 +710,7 @@ func (t *Tree) term() Node {
|
||||
}
|
||||
return number
|
||||
case itemLeftParen:
|
||||
- pipe := t.pipeline("parenthesized pipeline")
|
||||
- if token := t.next(); token.typ != itemRightParen {
|
||||
- t.errorf("unclosed right paren: unexpected %s", token)
|
||||
- }
|
||||
- return pipe
|
||||
+ return t.pipeline("parenthesized pipeline", itemRightParen)
|
||||
case itemString, itemRawString:
|
||||
s, err := strconv.Unquote(token.val)
|
||||
if err != nil {
|
||||
diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go
|
||||
index d9c13c5..220f984 100644
|
||||
--- a/src/text/template/parse/parse_test.go
|
||||
+++ b/src/text/template/parse/parse_test.go
|
||||
@@ -250,6 +250,13 @@ var parseTests = []parseTest{
|
||||
{"comment trim left and right", "x \r\n\t{{- /* */ -}}\n\n\ty", noError, `"x""y"`},
|
||||
{"block definition", `{{block "foo" .}}hello{{end}}`, noError,
|
||||
`{{template "foo" .}}`},
|
||||
+
|
||||
+ {"newline in assignment", "{{ $x \n := \n 1 \n }}", noError, "{{$x := 1}}"},
|
||||
+ {"newline in empty action", "{{\n}}", hasError, "{{\n}}"},
|
||||
+ {"newline in pipeline", "{{\n\"x\"\n|\nprintf\n}}", noError, `{{"x" | printf}}`},
|
||||
+ {"newline in comment", "{{/*\nhello\n*/}}", noError, ""},
|
||||
+ {"newline in comment", "{{-\n/*\nhello\n*/\n-}}", noError, ""},
|
||||
+
|
||||
// Errors.
|
||||
{"unclosed action", "hello{{range", hasError, ""},
|
||||
{"unmatched end", "{{end}}", hasError, ""},
|
||||
@@ -426,23 +433,38 @@ var errorTests = []parseTest{
|
||||
// Check line numbers are accurate.
|
||||
{"unclosed1",
|
||||
"line1\n{{",
|
||||
- hasError, `unclosed1:2: unexpected unclosed action in command`},
|
||||
+ hasError, `unclosed1:2: unclosed action`},
|
||||
{"unclosed2",
|
||||
"line1\n{{define `x`}}line2\n{{",
|
||||
- hasError, `unclosed2:3: unexpected unclosed action in command`},
|
||||
+ hasError, `unclosed2:3: unclosed action`},
|
||||
+ {"unclosed3",
|
||||
+ "line1\n{{\"x\"\n\"y\"\n",
|
||||
+ hasError, `unclosed3:4: unclosed action started at unclosed3:2`},
|
||||
+ {"unclosed4",
|
||||
+ "{{\n\n\n\n\n",
|
||||
+ hasError, `unclosed4:6: unclosed action started at unclosed4:1`},
|
||||
+ {"var1",
|
||||
+ "line1\n{{\nx\n}}",
|
||||
+ hasError, `var1:3: function "x" not defined`},
|
||||
// Specific errors.
|
||||
{"function",
|
||||
"{{foo}}",
|
||||
hasError, `function "foo" not defined`},
|
||||
- {"comment",
|
||||
+ {"comment1",
|
||||
"{{/*}}",
|
||||
- hasError, `unclosed comment`},
|
||||
+ hasError, `comment1:1: unclosed comment`},
|
||||
+ {"comment2",
|
||||
+ "{{/*\nhello\n}}",
|
||||
+ hasError, `comment2:1: unclosed comment`},
|
||||
{"lparen",
|
||||
"{{.X (1 2 3}}",
|
||||
hasError, `unclosed left paren`},
|
||||
{"rparen",
|
||||
- "{{.X 1 2 3)}}",
|
||||
- hasError, `unexpected ")"`},
|
||||
+ "{{.X 1 2 3 ) }}",
|
||||
+ hasError, `unexpected ")" in command`},
|
||||
+ {"rparen2",
|
||||
+ "{{(.X 1 2 3",
|
||||
+ hasError, `unclosed action`},
|
||||
{"space",
|
||||
"{{`x`3}}",
|
||||
hasError, `in operand`},
|
||||
@@ -488,7 +510,7 @@ var errorTests = []parseTest{
|
||||
hasError, `missing value for parenthesized pipeline`},
|
||||
{"multilinerawstring",
|
||||
"{{ $v := `\n` }} {{",
|
||||
- hasError, `multilinerawstring:2: unexpected unclosed action`},
|
||||
+ hasError, `multilinerawstring:2: unclosed action`},
|
||||
{"rangeundefvar",
|
||||
"{{range $k}}{{end}}",
|
||||
hasError, `undefined variable`},
|
||||
--
|
||||
2.7.4
|
||||
585
meta/recipes-devtools/go/go-1.14/CVE-2023-24538_5.patch
Normal file
585
meta/recipes-devtools/go/go-1.14/CVE-2023-24538_5.patch
Normal file
@@ -0,0 +1,585 @@
|
||||
From e0e6bca6ddc0e6d9fa3a5b644af9b446924fbf83 Mon Sep 17 00:00:00 2001
|
||||
From: Russ Cox <rsc@golang.org>
|
||||
Date: Thu, 20 May 2021 12:46:33 -0400
|
||||
Subject: [PATCH 5/6] html/template, text/template: implement break and
|
||||
continue for range loops
|
||||
|
||||
Break and continue for range loops was accepted as a proposal in June 2017.
|
||||
It was implemented in CL 66410 (Oct 2017)
|
||||
but then rolled back in CL 92155 (Feb 2018)
|
||||
because html/template changes had not been implemented.
|
||||
|
||||
This CL reimplements break and continue in text/template
|
||||
and then adds support for them in html/template as well.
|
||||
|
||||
Fixes #20531.
|
||||
|
||||
Change-Id: I05330482a976f1c078b4b49c2287bd9031bb7616
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/321491
|
||||
Trust: Russ Cox <rsc@golang.org>
|
||||
Run-TryBot: Russ Cox <rsc@golang.org>
|
||||
TryBot-Result: Go Bot <gobot@golang.org>
|
||||
Reviewed-by: Rob Pike <r@golang.org>
|
||||
|
||||
Dependency Patch #5
|
||||
|
||||
Upstream-Status: Backport from https://github.com/golang/go/commit/d0dd26a88c019d54f22463daae81e785f5867565
|
||||
CVE: CVE-2023-24538
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
src/html/template/context.go | 4 ++
|
||||
src/html/template/escape.go | 71 ++++++++++++++++++++++++++++++++++-
|
||||
src/html/template/escape_test.go | 24 ++++++++++++
|
||||
src/text/template/doc.go | 8 ++++
|
||||
src/text/template/exec.go | 24 +++++++++++-
|
||||
src/text/template/exec_test.go | 2 +
|
||||
src/text/template/parse/lex.go | 13 ++++++-
|
||||
src/text/template/parse/lex_test.go | 2 +
|
||||
src/text/template/parse/node.go | 36 ++++++++++++++++++
|
||||
src/text/template/parse/parse.go | 42 ++++++++++++++++++++-
|
||||
src/text/template/parse/parse_test.go | 8 ++++
|
||||
11 files changed, 230 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/src/html/template/context.go b/src/html/template/context.go
|
||||
index f7d4849..aaa7d08 100644
|
||||
--- a/src/html/template/context.go
|
||||
+++ b/src/html/template/context.go
|
||||
@@ -6,6 +6,7 @@ package template
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
+ "text/template/parse"
|
||||
)
|
||||
|
||||
// context describes the state an HTML parser must be in when it reaches the
|
||||
@@ -22,6 +23,7 @@ type context struct {
|
||||
jsCtx jsCtx
|
||||
attr attr
|
||||
element element
|
||||
+ n parse.Node // for range break/continue
|
||||
err *Error
|
||||
}
|
||||
|
||||
@@ -141,6 +143,8 @@ const (
|
||||
// stateError is an infectious error state outside any valid
|
||||
// HTML/CSS/JS construct.
|
||||
stateError
|
||||
+ // stateDead marks unreachable code after a {{break}} or {{continue}}.
|
||||
+ stateDead
|
||||
)
|
||||
|
||||
// isComment is true for any state that contains content meant for template
|
||||
diff --git a/src/html/template/escape.go b/src/html/template/escape.go
|
||||
index 8739735..6dea79c 100644
|
||||
--- a/src/html/template/escape.go
|
||||
+++ b/src/html/template/escape.go
|
||||
@@ -97,6 +97,15 @@ type escaper struct {
|
||||
actionNodeEdits map[*parse.ActionNode][]string
|
||||
templateNodeEdits map[*parse.TemplateNode]string
|
||||
textNodeEdits map[*parse.TextNode][]byte
|
||||
+ // rangeContext holds context about the current range loop.
|
||||
+ rangeContext *rangeContext
|
||||
+}
|
||||
+
|
||||
+// rangeContext holds information about the current range loop.
|
||||
+type rangeContext struct {
|
||||
+ outer *rangeContext // outer loop
|
||||
+ breaks []context // context at each break action
|
||||
+ continues []context // context at each continue action
|
||||
}
|
||||
|
||||
// makeEscaper creates a blank escaper for the given set.
|
||||
@@ -109,6 +118,7 @@ func makeEscaper(n *nameSpace) escaper {
|
||||
map[*parse.ActionNode][]string{},
|
||||
map[*parse.TemplateNode]string{},
|
||||
map[*parse.TextNode][]byte{},
|
||||
+ nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,8 +134,16 @@ func (e *escaper) escape(c context, n parse.Node) context {
|
||||
switch n := n.(type) {
|
||||
case *parse.ActionNode:
|
||||
return e.escapeAction(c, n)
|
||||
+ case *parse.BreakNode:
|
||||
+ c.n = n
|
||||
+ e.rangeContext.breaks = append(e.rangeContext.breaks, c)
|
||||
+ return context{state: stateDead}
|
||||
case *parse.CommentNode:
|
||||
return c
|
||||
+ case *parse.ContinueNode:
|
||||
+ c.n = n
|
||||
+ e.rangeContext.continues = append(e.rangeContext.breaks, c)
|
||||
+ return context{state: stateDead}
|
||||
case *parse.IfNode:
|
||||
return e.escapeBranch(c, &n.BranchNode, "if")
|
||||
case *parse.ListNode:
|
||||
@@ -427,6 +445,12 @@ func join(a, b context, node parse.Node, nodeName string) context {
|
||||
if b.state == stateError {
|
||||
return b
|
||||
}
|
||||
+ if a.state == stateDead {
|
||||
+ return b
|
||||
+ }
|
||||
+ if b.state == stateDead {
|
||||
+ return a
|
||||
+ }
|
||||
if a.eq(b) {
|
||||
return a
|
||||
}
|
||||
@@ -466,14 +490,27 @@ func join(a, b context, node parse.Node, nodeName string) context {
|
||||
|
||||
// escapeBranch escapes a branch template node: "if", "range" and "with".
|
||||
func (e *escaper) escapeBranch(c context, n *parse.BranchNode, nodeName string) context {
|
||||
+ if nodeName == "range" {
|
||||
+ e.rangeContext = &rangeContext{outer: e.rangeContext}
|
||||
+ }
|
||||
c0 := e.escapeList(c, n.List)
|
||||
- if nodeName == "range" && c0.state != stateError {
|
||||
+ if nodeName == "range" {
|
||||
+ if c0.state != stateError {
|
||||
+ c0 = joinRange(c0, e.rangeContext)
|
||||
+ }
|
||||
+ e.rangeContext = e.rangeContext.outer
|
||||
+ if c0.state == stateError {
|
||||
+ return c0
|
||||
+ }
|
||||
+
|
||||
// The "true" branch of a "range" node can execute multiple times.
|
||||
// We check that executing n.List once results in the same context
|
||||
// as executing n.List twice.
|
||||
+ e.rangeContext = &rangeContext{outer: e.rangeContext}
|
||||
c1, _ := e.escapeListConditionally(c0, n.List, nil)
|
||||
c0 = join(c0, c1, n, nodeName)
|
||||
if c0.state == stateError {
|
||||
+ e.rangeContext = e.rangeContext.outer
|
||||
// Make clear that this is a problem on loop re-entry
|
||||
// since developers tend to overlook that branch when
|
||||
// debugging templates.
|
||||
@@ -481,11 +518,39 @@ func (e *escaper) escapeBranch(c context, n *parse.BranchNode, nodeName string)
|
||||
c0.err.Description = "on range loop re-entry: " + c0.err.Description
|
||||
return c0
|
||||
}
|
||||
+ c0 = joinRange(c0, e.rangeContext)
|
||||
+ e.rangeContext = e.rangeContext.outer
|
||||
+ if c0.state == stateError {
|
||||
+ return c0
|
||||
+ }
|
||||
}
|
||||
c1 := e.escapeList(c, n.ElseList)
|
||||
return join(c0, c1, n, nodeName)
|
||||
}
|
||||
|
||||
+func joinRange(c0 context, rc *rangeContext) context {
|
||||
+ // Merge contexts at break and continue statements into overall body context.
|
||||
+ // In theory we could treat breaks differently from continues, but for now it is
|
||||
+ // enough to treat them both as going back to the start of the loop (which may then stop).
|
||||
+ for _, c := range rc.breaks {
|
||||
+ c0 = join(c0, c, c.n, "range")
|
||||
+ if c0.state == stateError {
|
||||
+ c0.err.Line = c.n.(*parse.BreakNode).Line
|
||||
+ c0.err.Description = "at range loop break: " + c0.err.Description
|
||||
+ return c0
|
||||
+ }
|
||||
+ }
|
||||
+ for _, c := range rc.continues {
|
||||
+ c0 = join(c0, c, c.n, "range")
|
||||
+ if c0.state == stateError {
|
||||
+ c0.err.Line = c.n.(*parse.ContinueNode).Line
|
||||
+ c0.err.Description = "at range loop continue: " + c0.err.Description
|
||||
+ return c0
|
||||
+ }
|
||||
+ }
|
||||
+ return c0
|
||||
+}
|
||||
+
|
||||
// escapeList escapes a list template node.
|
||||
func (e *escaper) escapeList(c context, n *parse.ListNode) context {
|
||||
if n == nil {
|
||||
@@ -493,6 +558,9 @@ func (e *escaper) escapeList(c context, n *parse.ListNode) context {
|
||||
}
|
||||
for _, m := range n.Nodes {
|
||||
c = e.escape(c, m)
|
||||
+ if c.state == stateDead {
|
||||
+ break
|
||||
+ }
|
||||
}
|
||||
return c
|
||||
}
|
||||
@@ -503,6 +571,7 @@ func (e *escaper) escapeList(c context, n *parse.ListNode) context {
|
||||
// which is the same as whether e was updated.
|
||||
func (e *escaper) escapeListConditionally(c context, n *parse.ListNode, filter func(*escaper, context) bool) (context, bool) {
|
||||
e1 := makeEscaper(e.ns)
|
||||
+ e1.rangeContext = e.rangeContext
|
||||
// Make type inferences available to f.
|
||||
for k, v := range e.output {
|
||||
e1.output[k] = v
|
||||
diff --git a/src/html/template/escape_test.go b/src/html/template/escape_test.go
|
||||
index c709660..fa2b84a 100644
|
||||
--- a/src/html/template/escape_test.go
|
||||
+++ b/src/html/template/escape_test.go
|
||||
@@ -920,6 +920,22 @@ func TestErrors(t *testing.T) {
|
||||
"<a href='/foo?{{range .Items}}&{{.K}}={{.V}}{{end}}'>",
|
||||
"",
|
||||
},
|
||||
+ {
|
||||
+ "{{range .Items}}<a{{if .X}}{{end}}>{{end}}",
|
||||
+ "",
|
||||
+ },
|
||||
+ {
|
||||
+ "{{range .Items}}<a{{if .X}}{{end}}>{{continue}}{{end}}",
|
||||
+ "",
|
||||
+ },
|
||||
+ {
|
||||
+ "{{range .Items}}<a{{if .X}}{{end}}>{{break}}{{end}}",
|
||||
+ "",
|
||||
+ },
|
||||
+ {
|
||||
+ "{{range .Items}}<a{{if .X}}{{end}}>{{if .X}}{{break}}{{end}}{{end}}",
|
||||
+ "",
|
||||
+ },
|
||||
// Error cases.
|
||||
{
|
||||
"{{if .Cond}}<a{{end}}",
|
||||
@@ -956,6 +972,14 @@ func TestErrors(t *testing.T) {
|
||||
"z:2:8: on range loop re-entry: {{range}} branches",
|
||||
},
|
||||
{
|
||||
+ "{{range .Items}}<a{{if .X}}{{break}}{{end}}>{{end}}",
|
||||
+ "z:1:29: at range loop break: {{range}} branches end in different contexts",
|
||||
+ },
|
||||
+ {
|
||||
+ "{{range .Items}}<a{{if .X}}{{continue}}{{end}}>{{end}}",
|
||||
+ "z:1:29: at range loop continue: {{range}} branches end in different contexts",
|
||||
+ },
|
||||
+ {
|
||||
"<a b=1 c={{.H}}",
|
||||
"z: ends in a non-text context: {stateAttr delimSpaceOrTagEnd",
|
||||
},
|
||||
diff --git a/src/text/template/doc.go b/src/text/template/doc.go
|
||||
index 7b30294..0228b15 100644
|
||||
--- a/src/text/template/doc.go
|
||||
+++ b/src/text/template/doc.go
|
||||
@@ -112,6 +112,14 @@ data, defined in detail in the corresponding sections that follow.
|
||||
T0 is executed; otherwise, dot is set to the successive elements
|
||||
of the array, slice, or map and T1 is executed.
|
||||
|
||||
+ {{break}}
|
||||
+ The innermost {{range pipeline}} loop is ended early, stopping the
|
||||
+ current iteration and bypassing all remaining iterations.
|
||||
+
|
||||
+ {{continue}}
|
||||
+ The current iteration of the innermost {{range pipeline}} loop is
|
||||
+ stopped, and the loop starts the next iteration.
|
||||
+
|
||||
{{template "name"}}
|
||||
The template with the specified name is executed with nil data.
|
||||
|
||||
diff --git a/src/text/template/exec.go b/src/text/template/exec.go
|
||||
index 7ac5175..6cb140a 100644
|
||||
--- a/src/text/template/exec.go
|
||||
+++ b/src/text/template/exec.go
|
||||
@@ -5,6 +5,7 @@
|
||||
package template
|
||||
|
||||
import (
|
||||
+ "errors"
|
||||
"fmt"
|
||||
"internal/fmtsort"
|
||||
"io"
|
||||
@@ -244,6 +245,12 @@ func (t *Template) DefinedTemplates() string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
+// Sentinel errors for use with panic to signal early exits from range loops.
|
||||
+var (
|
||||
+ walkBreak = errors.New("break")
|
||||
+ walkContinue = errors.New("continue")
|
||||
+)
|
||||
+
|
||||
// Walk functions step through the major pieces of the template structure,
|
||||
// generating output as they go.
|
||||
func (s *state) walk(dot reflect.Value, node parse.Node) {
|
||||
@@ -256,7 +263,11 @@ func (s *state) walk(dot reflect.Value, node parse.Node) {
|
||||
if len(node.Pipe.Decl) == 0 {
|
||||
s.printValue(node, val)
|
||||
}
|
||||
+ case *parse.BreakNode:
|
||||
+ panic(walkBreak)
|
||||
case *parse.CommentNode:
|
||||
+ case *parse.ContinueNode:
|
||||
+ panic(walkContinue)
|
||||
case *parse.IfNode:
|
||||
s.walkIfOrWith(parse.NodeIf, dot, node.Pipe, node.List, node.ElseList)
|
||||
case *parse.ListNode:
|
||||
@@ -335,6 +346,11 @@ func isTrue(val reflect.Value) (truth, ok bool) {
|
||||
|
||||
func (s *state) walkRange(dot reflect.Value, r *parse.RangeNode) {
|
||||
s.at(r)
|
||||
+ defer func() {
|
||||
+ if r := recover(); r != nil && r != walkBreak {
|
||||
+ panic(r)
|
||||
+ }
|
||||
+ }()
|
||||
defer s.pop(s.mark())
|
||||
val, _ := indirect(s.evalPipeline(dot, r.Pipe))
|
||||
// mark top of stack before any variables in the body are pushed.
|
||||
@@ -348,8 +364,14 @@ func (s *state) walkRange(dot reflect.Value, r *parse.RangeNode) {
|
||||
if len(r.Pipe.Decl) > 1 {
|
||||
s.setTopVar(2, index)
|
||||
}
|
||||
+ defer s.pop(mark)
|
||||
+ defer func() {
|
||||
+ // Consume panic(walkContinue)
|
||||
+ if r := recover(); r != nil && r != walkContinue {
|
||||
+ panic(r)
|
||||
+ }
|
||||
+ }()
|
||||
s.walk(elem, r.List)
|
||||
- s.pop(mark)
|
||||
}
|
||||
switch val.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go
|
||||
index 3309b33..a639f44 100644
|
||||
--- a/src/text/template/exec_test.go
|
||||
+++ b/src/text/template/exec_test.go
|
||||
@@ -563,6 +563,8 @@ var execTests = []execTest{
|
||||
{"range empty no else", "{{range .SIEmpty}}-{{.}}-{{end}}", "", tVal, true},
|
||||
{"range []int else", "{{range .SI}}-{{.}}-{{else}}EMPTY{{end}}", "-3--4--5-", tVal, true},
|
||||
{"range empty else", "{{range .SIEmpty}}-{{.}}-{{else}}EMPTY{{end}}", "EMPTY", tVal, true},
|
||||
+ {"range []int break else", "{{range .SI}}-{{.}}-{{break}}NOTREACHED{{else}}EMPTY{{end}}", "-3-", tVal, true},
|
||||
+ {"range []int continue else", "{{range .SI}}-{{.}}-{{continue}}NOTREACHED{{else}}EMPTY{{end}}", "-3--4--5-", tVal, true},
|
||||
{"range []bool", "{{range .SB}}-{{.}}-{{end}}", "-true--false-", tVal, true},
|
||||
{"range []int method", "{{range .SI | .MAdd .I}}-{{.}}-{{end}}", "-20--21--22-", tVal, true},
|
||||
{"range map", "{{range .MSI}}-{{.}}-{{end}}", "-1--3--2-", tVal, true},
|
||||
diff --git a/src/text/template/parse/lex.go b/src/text/template/parse/lex.go
|
||||
index 6784071..95e3377 100644
|
||||
--- a/src/text/template/parse/lex.go
|
||||
+++ b/src/text/template/parse/lex.go
|
||||
@@ -62,6 +62,8 @@ const (
|
||||
// Keywords appear after all the rest.
|
||||
itemKeyword // used only to delimit the keywords
|
||||
itemBlock // block keyword
|
||||
+ itemBreak // break keyword
|
||||
+ itemContinue // continue keyword
|
||||
itemDot // the cursor, spelled '.'
|
||||
itemDefine // define keyword
|
||||
itemElse // else keyword
|
||||
@@ -76,6 +78,8 @@ const (
|
||||
var key = map[string]itemType{
|
||||
".": itemDot,
|
||||
"block": itemBlock,
|
||||
+ "break": itemBreak,
|
||||
+ "continue": itemContinue,
|
||||
"define": itemDefine,
|
||||
"else": itemElse,
|
||||
"end": itemEnd,
|
||||
@@ -119,6 +123,8 @@ type lexer struct {
|
||||
parenDepth int // nesting depth of ( ) exprs
|
||||
line int // 1+number of newlines seen
|
||||
startLine int // start line of this item
|
||||
+ breakOK bool // break keyword allowed
|
||||
+ continueOK bool // continue keyword allowed
|
||||
}
|
||||
|
||||
// next returns the next rune in the input.
|
||||
@@ -461,7 +467,12 @@ Loop:
|
||||
}
|
||||
switch {
|
||||
case key[word] > itemKeyword:
|
||||
- l.emit(key[word])
|
||||
+ item := key[word]
|
||||
+ if item == itemBreak && !l.breakOK || item == itemContinue && !l.continueOK {
|
||||
+ l.emit(itemIdentifier)
|
||||
+ } else {
|
||||
+ l.emit(item)
|
||||
+ }
|
||||
case word[0] == '.':
|
||||
l.emit(itemField)
|
||||
case word == "true", word == "false":
|
||||
diff --git a/src/text/template/parse/lex_test.go b/src/text/template/parse/lex_test.go
|
||||
index 6510eed..df6aabf 100644
|
||||
--- a/src/text/template/parse/lex_test.go
|
||||
+++ b/src/text/template/parse/lex_test.go
|
||||
@@ -35,6 +35,8 @@ var itemName = map[itemType]string{
|
||||
// keywords
|
||||
itemDot: ".",
|
||||
itemBlock: "block",
|
||||
+ itemBreak: "break",
|
||||
+ itemContinue: "continue",
|
||||
itemDefine: "define",
|
||||
itemElse: "else",
|
||||
itemIf: "if",
|
||||
diff --git a/src/text/template/parse/node.go b/src/text/template/parse/node.go
|
||||
index a9dad5e..c398da0 100644
|
||||
--- a/src/text/template/parse/node.go
|
||||
+++ b/src/text/template/parse/node.go
|
||||
@@ -71,6 +71,8 @@ const (
|
||||
NodeVariable // A $ variable.
|
||||
NodeWith // A with action.
|
||||
NodeComment // A comment.
|
||||
+ NodeBreak // A break action.
|
||||
+ NodeContinue // A continue action.
|
||||
)
|
||||
|
||||
// Nodes.
|
||||
@@ -907,6 +909,40 @@ func (i *IfNode) Copy() Node {
|
||||
return i.tr.newIf(i.Pos, i.Line, i.Pipe.CopyPipe(), i.List.CopyList(), i.ElseList.CopyList())
|
||||
}
|
||||
|
||||
+// BreakNode represents a {{break}} action.
|
||||
+type BreakNode struct {
|
||||
+ tr *Tree
|
||||
+ NodeType
|
||||
+ Pos
|
||||
+ Line int
|
||||
+}
|
||||
+
|
||||
+func (t *Tree) newBreak(pos Pos, line int) *BreakNode {
|
||||
+ return &BreakNode{tr: t, NodeType: NodeBreak, Pos: pos, Line: line}
|
||||
+}
|
||||
+
|
||||
+func (b *BreakNode) Copy() Node { return b.tr.newBreak(b.Pos, b.Line) }
|
||||
+func (b *BreakNode) String() string { return "{{break}}" }
|
||||
+func (b *BreakNode) tree() *Tree { return b.tr }
|
||||
+func (b *BreakNode) writeTo(sb *strings.Builder) { sb.WriteString("{{break}}") }
|
||||
+
|
||||
+// ContinueNode represents a {{continue}} action.
|
||||
+type ContinueNode struct {
|
||||
+ tr *Tree
|
||||
+ NodeType
|
||||
+ Pos
|
||||
+ Line int
|
||||
+}
|
||||
+
|
||||
+func (t *Tree) newContinue(pos Pos, line int) *ContinueNode {
|
||||
+ return &ContinueNode{tr: t, NodeType: NodeContinue, Pos: pos, Line: line}
|
||||
+}
|
||||
+
|
||||
+func (c *ContinueNode) Copy() Node { return c.tr.newContinue(c.Pos, c.Line) }
|
||||
+func (c *ContinueNode) String() string { return "{{continue}}" }
|
||||
+func (c *ContinueNode) tree() *Tree { return c.tr }
|
||||
+func (c *ContinueNode) writeTo(sb *strings.Builder) { sb.WriteString("{{continue}}") }
|
||||
+
|
||||
// RangeNode represents a {{range}} action and its commands.
|
||||
type RangeNode struct {
|
||||
BranchNode
|
||||
diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go
|
||||
index 5e6e512..7f78b56 100644
|
||||
--- a/src/text/template/parse/parse.go
|
||||
+++ b/src/text/template/parse/parse.go
|
||||
@@ -31,6 +31,7 @@ type Tree struct {
|
||||
vars []string // variables defined at the moment.
|
||||
treeSet map[string]*Tree
|
||||
actionLine int // line of left delim starting action
|
||||
+ rangeDepth int
|
||||
mode Mode
|
||||
}
|
||||
|
||||
@@ -223,6 +224,8 @@ func (t *Tree) startParse(funcs []map[string]interface{}, lex *lexer, treeSet ma
|
||||
t.vars = []string{"$"}
|
||||
t.funcs = funcs
|
||||
t.treeSet = treeSet
|
||||
+ lex.breakOK = !t.hasFunction("break")
|
||||
+ lex.continueOK = !t.hasFunction("continue")
|
||||
}
|
||||
|
||||
// stopParse terminates parsing.
|
||||
@@ -385,6 +388,10 @@ func (t *Tree) action() (n Node) {
|
||||
switch token := t.nextNonSpace(); token.typ {
|
||||
case itemBlock:
|
||||
return t.blockControl()
|
||||
+ case itemBreak:
|
||||
+ return t.breakControl(token.pos, token.line)
|
||||
+ case itemContinue:
|
||||
+ return t.continueControl(token.pos, token.line)
|
||||
case itemElse:
|
||||
return t.elseControl()
|
||||
case itemEnd:
|
||||
@@ -404,6 +411,32 @@ func (t *Tree) action() (n Node) {
|
||||
return t.newAction(token.pos, token.line, t.pipeline("command", itemRightDelim))
|
||||
}
|
||||
|
||||
+// Break:
|
||||
+// {{break}}
|
||||
+// Break keyword is past.
|
||||
+func (t *Tree) breakControl(pos Pos, line int) Node {
|
||||
+ if token := t.next(); token.typ != itemRightDelim {
|
||||
+ t.unexpected(token, "in {{break}}")
|
||||
+ }
|
||||
+ if t.rangeDepth == 0 {
|
||||
+ t.errorf("{{break}} outside {{range}}")
|
||||
+ }
|
||||
+ return t.newBreak(pos, line)
|
||||
+}
|
||||
+
|
||||
+// Continue:
|
||||
+// {{continue}}
|
||||
+// Continue keyword is past.
|
||||
+func (t *Tree) continueControl(pos Pos, line int) Node {
|
||||
+ if token := t.next(); token.typ != itemRightDelim {
|
||||
+ t.unexpected(token, "in {{continue}}")
|
||||
+ }
|
||||
+ if t.rangeDepth == 0 {
|
||||
+ t.errorf("{{continue}} outside {{range}}")
|
||||
+ }
|
||||
+ return t.newContinue(pos, line)
|
||||
+}
|
||||
+
|
||||
// Pipeline:
|
||||
// declarations? command ('|' command)*
|
||||
func (t *Tree) pipeline(context string, end itemType) (pipe *PipeNode) {
|
||||
@@ -479,8 +512,14 @@ func (t *Tree) checkPipeline(pipe *PipeNode, context string) {
|
||||
func (t *Tree) parseControl(allowElseIf bool, context string) (pos Pos, line int, pipe *PipeNode, list, elseList *ListNode) {
|
||||
defer t.popVars(len(t.vars))
|
||||
pipe = t.pipeline(context, itemRightDelim)
|
||||
+ if context == "range" {
|
||||
+ t.rangeDepth++
|
||||
+ }
|
||||
var next Node
|
||||
list, next = t.itemList()
|
||||
+ if context == "range" {
|
||||
+ t.rangeDepth--
|
||||
+ }
|
||||
switch next.Type() {
|
||||
case nodeEnd: //done
|
||||
case nodeElse:
|
||||
@@ -522,7 +561,8 @@ func (t *Tree) ifControl() Node {
|
||||
// {{range pipeline}} itemList {{else}} itemList {{end}}
|
||||
// Range keyword is past.
|
||||
func (t *Tree) rangeControl() Node {
|
||||
- return t.newRange(t.parseControl(false, "range"))
|
||||
+ r := t.newRange(t.parseControl(false, "range"))
|
||||
+ return r
|
||||
}
|
||||
|
||||
// With:
|
||||
diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go
|
||||
index 220f984..ba45636 100644
|
||||
--- a/src/text/template/parse/parse_test.go
|
||||
+++ b/src/text/template/parse/parse_test.go
|
||||
@@ -230,6 +230,10 @@ var parseTests = []parseTest{
|
||||
`{{range $x := .SI}}{{.}}{{end}}`},
|
||||
{"range 2 vars", "{{range $x, $y := .SI}}{{.}}{{end}}", noError,
|
||||
`{{range $x, $y := .SI}}{{.}}{{end}}`},
|
||||
+ {"range with break", "{{range .SI}}{{.}}{{break}}{{end}}", noError,
|
||||
+ `{{range .SI}}{{.}}{{break}}{{end}}`},
|
||||
+ {"range with continue", "{{range .SI}}{{.}}{{continue}}{{end}}", noError,
|
||||
+ `{{range .SI}}{{.}}{{continue}}{{end}}`},
|
||||
{"constants", "{{range .SI 1 -3.2i true false 'a' nil}}{{end}}", noError,
|
||||
`{{range .SI 1 -3.2i true false 'a' nil}}{{end}}`},
|
||||
{"template", "{{template `x`}}", noError,
|
||||
@@ -279,6 +283,10 @@ var parseTests = []parseTest{
|
||||
{"adjacent args", "{{printf 3`x`}}", hasError, ""},
|
||||
{"adjacent args with .", "{{printf `x`.}}", hasError, ""},
|
||||
{"extra end after if", "{{if .X}}a{{else if .Y}}b{{end}}{{end}}", hasError, ""},
|
||||
+ {"break outside range", "{{range .}}{{end}} {{break}}", hasError, ""},
|
||||
+ {"continue outside range", "{{range .}}{{end}} {{continue}}", hasError, ""},
|
||||
+ {"break in range else", "{{range .}}{{else}}{{break}}{{end}}", hasError, ""},
|
||||
+ {"continue in range else", "{{range .}}{{else}}{{continue}}{{end}}", hasError, ""},
|
||||
// Other kinds of assignments and operators aren't available yet.
|
||||
{"bug0a", "{{$x := 0}}{{$x}}", noError, "{{$x := 0}}{{$x}}"},
|
||||
{"bug0b", "{{$x += 1}}{{$x}}", hasError, ""},
|
||||
--
|
||||
2.7.4
|
||||
@@ -1,7 +1,7 @@
|
||||
From 16f4882984569f179d73967c9eee679bb9b098c5 Mon Sep 17 00:00:00 2001
|
||||
From: Roland Shoemaker <bracewell@google.com>
|
||||
Date: Mon, 20 Mar 2023 11:01:13 -0700
|
||||
Subject: [PATCH 3/3] html/template: disallow actions in JS template literals
|
||||
Subject: [PATCH 6/6] html/template: disallow actions in JS template literals
|
||||
|
||||
ECMAScript 6 introduced template literals[0][1] which are delimited with
|
||||
backticks. These need to be escaped in a similar fashion to the
|
||||
@@ -52,12 +52,15 @@ CVE: CVE-2023-24538
|
||||
Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com>
|
||||
---
|
||||
src/html/template/context.go | 2 ++
|
||||
src/html/template/error.go | 13 +++++++++++++
|
||||
src/html/template/escape.go | 11 +++++++++++
|
||||
src/html/template/error.go | 13 ++++++++
|
||||
src/html/template/escape.go | 11 +++++++
|
||||
src/html/template/escape_test.go | 66 ++++++++++++++++++++++-----------------
|
||||
src/html/template/js.go | 2 ++
|
||||
src/html/template/jsctx_string.go | 9 +++++++++
|
||||
src/html/template/transition.go | 7 ++++++-
|
||||
6 files changed, 43 insertions(+), 1 deletion(-)
|
||||
src/html/template/js_test.go | 2 +-
|
||||
src/html/template/jsctx_string.go | 9 ++++++
|
||||
src/html/template/state_string.go | 37 ++++++++++++++++++++--
|
||||
src/html/template/transition.go | 7 ++++-
|
||||
9 files changed, 116 insertions(+), 33 deletions(-)
|
||||
|
||||
diff --git a/src/html/template/context.go b/src/html/template/context.go
|
||||
index f7d4849..0b65313 100644
|
||||
@@ -125,6 +128,104 @@ index f12dafa..29ca5b3 100644
|
||||
case stateJSRegexp:
|
||||
s = append(s, "_html_template_jsregexpescaper")
|
||||
case stateCSS:
|
||||
diff --git a/src/html/template/escape_test.go b/src/html/template/escape_test.go
|
||||
index fa2b84a..1b150e9 100644
|
||||
--- a/src/html/template/escape_test.go
|
||||
+++ b/src/html/template/escape_test.go
|
||||
@@ -681,35 +681,31 @@ func TestEscape(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
- tmpl := New(test.name)
|
||||
- tmpl = Must(tmpl.Parse(test.input))
|
||||
- // Check for bug 6459: Tree field was not set in Parse.
|
||||
- if tmpl.Tree != tmpl.text.Tree {
|
||||
- t.Errorf("%s: tree not set properly", test.name)
|
||||
- continue
|
||||
- }
|
||||
- b := new(bytes.Buffer)
|
||||
- if err := tmpl.Execute(b, data); err != nil {
|
||||
- t.Errorf("%s: template execution failed: %s", test.name, err)
|
||||
- continue
|
||||
- }
|
||||
- if w, g := test.output, b.String(); w != g {
|
||||
- t.Errorf("%s: escaped output: want\n\t%q\ngot\n\t%q", test.name, w, g)
|
||||
- continue
|
||||
- }
|
||||
- b.Reset()
|
||||
- if err := tmpl.Execute(b, pdata); err != nil {
|
||||
- t.Errorf("%s: template execution failed for pointer: %s", test.name, err)
|
||||
- continue
|
||||
- }
|
||||
- if w, g := test.output, b.String(); w != g {
|
||||
- t.Errorf("%s: escaped output for pointer: want\n\t%q\ngot\n\t%q", test.name, w, g)
|
||||
- continue
|
||||
- }
|
||||
- if tmpl.Tree != tmpl.text.Tree {
|
||||
- t.Errorf("%s: tree mismatch", test.name)
|
||||
- continue
|
||||
- }
|
||||
+ t.Run(test.name, func(t *testing.T) {
|
||||
+ tmpl := New(test.name)
|
||||
+ tmpl = Must(tmpl.Parse(test.input))
|
||||
+ // Check for bug 6459: Tree field was not set in Parse.
|
||||
+ if tmpl.Tree != tmpl.text.Tree {
|
||||
+ t.Fatalf("%s: tree not set properly", test.name)
|
||||
+ }
|
||||
+ b := new(strings.Builder)
|
||||
+ if err := tmpl.Execute(b, data); err != nil {
|
||||
+ t.Fatalf("%s: template execution failed: %s", test.name, err)
|
||||
+ }
|
||||
+ if w, g := test.output, b.String(); w != g {
|
||||
+ t.Fatalf("%s: escaped output: want\n\t%q\ngot\n\t%q", test.name, w, g)
|
||||
+ }
|
||||
+ b.Reset()
|
||||
+ if err := tmpl.Execute(b, pdata); err != nil {
|
||||
+ t.Fatalf("%s: template execution failed for pointer: %s", test.name, err)
|
||||
+ }
|
||||
+ if w, g := test.output, b.String(); w != g {
|
||||
+ t.Fatalf("%s: escaped output for pointer: want\n\t%q\ngot\n\t%q", test.name, w, g)
|
||||
+ }
|
||||
+ if tmpl.Tree != tmpl.text.Tree {
|
||||
+ t.Fatalf("%s: tree mismatch", test.name)
|
||||
+ }
|
||||
+ })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -936,6 +932,10 @@ func TestErrors(t *testing.T) {
|
||||
"{{range .Items}}<a{{if .X}}{{end}}>{{if .X}}{{break}}{{end}}{{end}}",
|
||||
"",
|
||||
},
|
||||
+ {
|
||||
+ "<script>var a = `${a+b}`</script>`",
|
||||
+ "",
|
||||
+ },
|
||||
// Error cases.
|
||||
{
|
||||
"{{if .Cond}}<a{{end}}",
|
||||
@@ -1082,6 +1082,10 @@ func TestErrors(t *testing.T) {
|
||||
// html is allowed since it is the last command in the pipeline, but urlquery is not.
|
||||
`predefined escaper "urlquery" disallowed in template`,
|
||||
},
|
||||
+ {
|
||||
+ "<script>var tmpl = `asd {{.}}`;</script>",
|
||||
+ `{{.}} appears in a JS template literal`,
|
||||
+ },
|
||||
}
|
||||
for _, test := range tests {
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -1304,6 +1308,10 @@ func TestEscapeText(t *testing.T) {
|
||||
context{state: stateJSSqStr, delim: delimDoubleQuote, attr: attrScript},
|
||||
},
|
||||
{
|
||||
+ "<a onclick=\"`foo",
|
||||
+ context{state: stateJSBqStr, delim: delimDoubleQuote, attr: attrScript},
|
||||
+ },
|
||||
+ {
|
||||
`<A ONCLICK="'`,
|
||||
context{state: stateJSSqStr, delim: delimDoubleQuote, attr: attrScript},
|
||||
},
|
||||
diff --git a/src/html/template/js.go b/src/html/template/js.go
|
||||
index ea9c183..b888eaf 100644
|
||||
--- a/src/html/template/js.go
|
||||
@@ -145,6 +246,19 @@ index ea9c183..b888eaf 100644
|
||||
'+': `\u002b`,
|
||||
'/': `\/`,
|
||||
'<': `\u003c`,
|
||||
diff --git a/src/html/template/js_test.go b/src/html/template/js_test.go
|
||||
index d7ee47b..7d963ae 100644
|
||||
--- a/src/html/template/js_test.go
|
||||
+++ b/src/html/template/js_test.go
|
||||
@@ -292,7 +292,7 @@ func TestEscapersOnLower7AndSelectHighCodepoints(t *testing.T) {
|
||||
`0123456789:;\u003c=\u003e?` +
|
||||
`@ABCDEFGHIJKLMNO` +
|
||||
`PQRSTUVWXYZ[\\]^_` +
|
||||
- "`abcdefghijklmno" +
|
||||
+ "\\u0060abcdefghijklmno" +
|
||||
"pqrstuvwxyz{|}~\u007f" +
|
||||
"\u00A0\u0100\\u2028\\u2029\ufeff\U0001D11E",
|
||||
},
|
||||
diff --git a/src/html/template/jsctx_string.go b/src/html/template/jsctx_string.go
|
||||
index dd1d87e..2394893 100644
|
||||
--- a/src/html/template/jsctx_string.go
|
||||
@@ -165,6 +279,55 @@ index dd1d87e..2394893 100644
|
||||
const _jsCtx_name = "jsCtxRegexpjsCtxDivOpjsCtxUnknown"
|
||||
|
||||
var _jsCtx_index = [...]uint8{0, 11, 21, 33}
|
||||
diff --git a/src/html/template/state_string.go b/src/html/template/state_string.go
|
||||
index 05104be..6fb1a6e 100644
|
||||
--- a/src/html/template/state_string.go
|
||||
+++ b/src/html/template/state_string.go
|
||||
@@ -4,9 +4,42 @@ package template
|
||||
|
||||
import "strconv"
|
||||
|
||||
-const _state_name = "stateTextstateTagstateAttrNamestateAfterNamestateBeforeValuestateHTMLCmtstateRCDATAstateAttrstateURLstateSrcsetstateJSstateJSDqStrstateJSSqStrstateJSRegexpstateJSBlockCmtstateJSLineCmtstateCSSstateCSSDqStrstateCSSSqStrstateCSSDqURLstateCSSSqURLstateCSSURLstateCSSBlockCmtstateCSSLineCmtstateError"
|
||||
+func _() {
|
||||
+ // An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
+ // Re-run the stringer command to generate them again.
|
||||
+ var x [1]struct{}
|
||||
+ _ = x[stateText-0]
|
||||
+ _ = x[stateTag-1]
|
||||
+ _ = x[stateAttrName-2]
|
||||
+ _ = x[stateAfterName-3]
|
||||
+ _ = x[stateBeforeValue-4]
|
||||
+ _ = x[stateHTMLCmt-5]
|
||||
+ _ = x[stateRCDATA-6]
|
||||
+ _ = x[stateAttr-7]
|
||||
+ _ = x[stateURL-8]
|
||||
+ _ = x[stateSrcset-9]
|
||||
+ _ = x[stateJS-10]
|
||||
+ _ = x[stateJSDqStr-11]
|
||||
+ _ = x[stateJSSqStr-12]
|
||||
+ _ = x[stateJSBqStr-13]
|
||||
+ _ = x[stateJSRegexp-14]
|
||||
+ _ = x[stateJSBlockCmt-15]
|
||||
+ _ = x[stateJSLineCmt-16]
|
||||
+ _ = x[stateCSS-17]
|
||||
+ _ = x[stateCSSDqStr-18]
|
||||
+ _ = x[stateCSSSqStr-19]
|
||||
+ _ = x[stateCSSDqURL-20]
|
||||
+ _ = x[stateCSSSqURL-21]
|
||||
+ _ = x[stateCSSURL-22]
|
||||
+ _ = x[stateCSSBlockCmt-23]
|
||||
+ _ = x[stateCSSLineCmt-24]
|
||||
+ _ = x[stateError-25]
|
||||
+ _ = x[stateDead-26]
|
||||
+}
|
||||
+
|
||||
+const _state_name = "stateTextstateTagstateAttrNamestateAfterNamestateBeforeValuestateHTMLCmtstateRCDATAstateAttrstateURLstateSrcsetstateJSstateJSDqStrstateJSSqStrstateJSBqStrstateJSRegexpstateJSBlockCmtstateJSLineCmtstateCSSstateCSSDqStrstateCSSSqStrstateCSSDqURLstateCSSSqURLstateCSSURLstateCSSBlockCmtstateCSSLineCmtstateErrorstateDead"
|
||||
|
||||
-var _state_index = [...]uint16{0, 9, 17, 30, 44, 60, 72, 83, 92, 100, 111, 118, 130, 142, 155, 170, 184, 192, 205, 218, 231, 244, 255, 271, 286, 296}
|
||||
+var _state_index = [...]uint16{0, 9, 17, 30, 44, 60, 72, 83, 92, 100, 111, 118, 130, 142, 154, 167, 182, 196, 204, 217, 230, 243, 256, 267, 283, 298, 308, 317}
|
||||
|
||||
func (i state) String() string {
|
||||
if i >= state(len(_state_index)-1) {
|
||||
diff --git a/src/html/template/transition.go b/src/html/template/transition.go
|
||||
index 06df679..92eb351 100644
|
||||
--- a/src/html/template/transition.go
|
||||
212
meta/recipes-devtools/go/go-1.14/CVE-2023-29406.patch
Normal file
212
meta/recipes-devtools/go/go-1.14/CVE-2023-29406.patch
Normal file
@@ -0,0 +1,212 @@
|
||||
From 5fa6923b1ea891400153d04ddf1545e23b40041b Mon Sep 17 00:00:00 2001
|
||||
From: Damien Neil <dneil@google.com>
|
||||
Date: Wed, 28 Jun 2023 13:20:08 -0700
|
||||
Subject: [PATCH] [release-branch.go1.19] net/http: validate Host header before
|
||||
sending
|
||||
|
||||
Verify that the Host header we send is valid.
|
||||
Avoids surprising behavior such as a Host of "go.dev\r\nX-Evil:oops"
|
||||
adding an X-Evil header to HTTP/1 requests.
|
||||
|
||||
Add a test, skip the test for HTTP/2. HTTP/2 is not vulnerable to
|
||||
header injection in the way HTTP/1 is, but x/net/http2 doesn't validate
|
||||
the header and will go into a retry loop when the server rejects it.
|
||||
CL 506995 adds the necessary validation to x/net/http2.
|
||||
|
||||
Updates #60374
|
||||
Fixes #61075
|
||||
For CVE-2023-29406
|
||||
|
||||
Change-Id: I05cb6866a9bead043101954dfded199258c6dd04
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/506996
|
||||
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
|
||||
TryBot-Result: Gopher Robot <gobot@golang.org>
|
||||
Run-TryBot: Damien Neil <dneil@google.com>
|
||||
(cherry picked from commit 499458f7ca04087958987a33c2703c3ef03e27e2)
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/507358
|
||||
Run-TryBot: Tatiana Bradley <tatianabradley@google.com>
|
||||
Reviewed-by: Roland Shoemaker <roland@golang.org>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/5fa6923b1ea891400153d04ddf1545e23b40041b]
|
||||
CVE: CVE-2023-29406
|
||||
Signed-off-by: Vivek Kumbhar <vkumbhar@mvista.com>
|
||||
---
|
||||
src/net/http/http_test.go | 29 ---------------------
|
||||
src/net/http/request.go | 47 ++++++++--------------------------
|
||||
src/net/http/request_test.go | 11 ++------
|
||||
src/net/http/transport_test.go | 18 +++++++++++++
|
||||
4 files changed, 31 insertions(+), 74 deletions(-)
|
||||
|
||||
diff --git a/src/net/http/http_test.go b/src/net/http/http_test.go
|
||||
index f4ea52d..ea38cb4 100644
|
||||
--- a/src/net/http/http_test.go
|
||||
+++ b/src/net/http/http_test.go
|
||||
@@ -49,35 +49,6 @@ func TestForeachHeaderElement(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
-func TestCleanHost(t *testing.T) {
|
||||
- tests := []struct {
|
||||
- in, want string
|
||||
- }{
|
||||
- {"www.google.com", "www.google.com"},
|
||||
- {"www.google.com foo", "www.google.com"},
|
||||
- {"www.google.com/foo", "www.google.com"},
|
||||
- {" first character is a space", ""},
|
||||
- {"[1::6]:8080", "[1::6]:8080"},
|
||||
-
|
||||
- // Punycode:
|
||||
- {"гофер.рф/foo", "xn--c1ae0ajs.xn--p1ai"},
|
||||
- {"bücher.de", "xn--bcher-kva.de"},
|
||||
- {"bücher.de:8080", "xn--bcher-kva.de:8080"},
|
||||
- // Verify we convert to lowercase before punycode:
|
||||
- {"BÜCHER.de", "xn--bcher-kva.de"},
|
||||
- {"BÜCHER.de:8080", "xn--bcher-kva.de:8080"},
|
||||
- // Verify we normalize to NFC before punycode:
|
||||
- {"gophér.nfc", "xn--gophr-esa.nfc"}, // NFC input; no work needed
|
||||
- {"goph\u0065\u0301r.nfd", "xn--gophr-esa.nfd"}, // NFD input
|
||||
- }
|
||||
- for _, tt := range tests {
|
||||
- got := cleanHost(tt.in)
|
||||
- if tt.want != got {
|
||||
- t.Errorf("cleanHost(%q) = %q, want %q", tt.in, got, tt.want)
|
||||
- }
|
||||
- }
|
||||
-}
|
||||
-
|
||||
// Test that cmd/go doesn't link in the HTTP server.
|
||||
//
|
||||
// This catches accidental dependencies between the HTTP transport and
|
||||
diff --git a/src/net/http/request.go b/src/net/http/request.go
|
||||
index cb2edd2..2706300 100644
|
||||
--- a/src/net/http/request.go
|
||||
+++ b/src/net/http/request.go
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
- "net"
|
||||
"net/http/httptrace"
|
||||
"net/textproto"
|
||||
"net/url"
|
||||
@@ -26,7 +25,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
-
|
||||
+
|
||||
+ "golang.org/x/net/http/httpguts"
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
|
||||
@@ -557,12 +557,19 @@ func (r *Request) write(w io.Writer, usingProxy bool, extraHeaders Header, waitF
|
||||
// is not given, use the host from the request URL.
|
||||
//
|
||||
// Clean the host, in case it arrives with unexpected stuff in it.
|
||||
- host := cleanHost(r.Host)
|
||||
+ host := r.Host
|
||||
if host == "" {
|
||||
if r.URL == nil {
|
||||
return errMissingHost
|
||||
}
|
||||
- host = cleanHost(r.URL.Host)
|
||||
+ host = r.URL.Host
|
||||
+ }
|
||||
+ host, err = httpguts.PunycodeHostPort(host)
|
||||
+ if err != nil {
|
||||
+ return err
|
||||
+ }
|
||||
+ if !httpguts.ValidHostHeader(host) {
|
||||
+ return errors.New("http: invalid Host header")
|
||||
}
|
||||
|
||||
// According to RFC 6874, an HTTP client, proxy, or other
|
||||
@@ -717,38 +724,6 @@ func idnaASCII(v string) (string, error) {
|
||||
return idna.Lookup.ToASCII(v)
|
||||
}
|
||||
|
||||
-// cleanHost cleans up the host sent in request's Host header.
|
||||
-//
|
||||
-// It both strips anything after '/' or ' ', and puts the value
|
||||
-// into Punycode form, if necessary.
|
||||
-//
|
||||
-// Ideally we'd clean the Host header according to the spec:
|
||||
-// https://tools.ietf.org/html/rfc7230#section-5.4 (Host = uri-host [ ":" port ]")
|
||||
-// https://tools.ietf.org/html/rfc7230#section-2.7 (uri-host -> rfc3986's host)
|
||||
-// https://tools.ietf.org/html/rfc3986#section-3.2.2 (definition of host)
|
||||
-// But practically, what we are trying to avoid is the situation in
|
||||
-// issue 11206, where a malformed Host header used in the proxy context
|
||||
-// would create a bad request. So it is enough to just truncate at the
|
||||
-// first offending character.
|
||||
-func cleanHost(in string) string {
|
||||
- if i := strings.IndexAny(in, " /"); i != -1 {
|
||||
- in = in[:i]
|
||||
- }
|
||||
- host, port, err := net.SplitHostPort(in)
|
||||
- if err != nil { // input was just a host
|
||||
- a, err := idnaASCII(in)
|
||||
- if err != nil {
|
||||
- return in // garbage in, garbage out
|
||||
- }
|
||||
- return a
|
||||
- }
|
||||
- a, err := idnaASCII(host)
|
||||
- if err != nil {
|
||||
- return in // garbage in, garbage out
|
||||
- }
|
||||
- return net.JoinHostPort(a, port)
|
||||
-}
|
||||
-
|
||||
// removeZone removes IPv6 zone identifier from host.
|
||||
// E.g., "[fe80::1%en0]:8080" to "[fe80::1]:8080"
|
||||
func removeZone(host string) string {
|
||||
diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go
|
||||
index 461d66e..0d417ff 100644
|
||||
--- a/src/net/http/request_test.go
|
||||
+++ b/src/net/http/request_test.go
|
||||
@@ -676,15 +676,8 @@ func TestRequestBadHost(t *testing.T) {
|
||||
}
|
||||
req.Host = "foo.com with spaces"
|
||||
req.URL.Host = "foo.com with spaces"
|
||||
- req.Write(logWrites{t, &got})
|
||||
- want := []string{
|
||||
- "GET /after HTTP/1.1\r\n",
|
||||
- "Host: foo.com\r\n",
|
||||
- "User-Agent: " + DefaultUserAgent + "\r\n",
|
||||
- "\r\n",
|
||||
- }
|
||||
- if !reflect.DeepEqual(got, want) {
|
||||
- t.Errorf("Writes = %q\n Want = %q", got, want)
|
||||
+ if err := req.Write(logWrites{t, &got}); err == nil {
|
||||
+ t.Errorf("Writing request with invalid Host: succeded, want error")
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go
|
||||
index fa0c370..0afb6b9 100644
|
||||
--- a/src/net/http/transport_test.go
|
||||
+++ b/src/net/http/transport_test.go
|
||||
@@ -6249,3 +6249,21 @@ func TestIssue32441(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
+
|
||||
+func TestRequestSanitization(t *testing.T) {
|
||||
+ setParallel(t)
|
||||
+ defer afterTest(t)
|
||||
+
|
||||
+ ts := newClientServerTest(t, h1Mode, HandlerFunc(func(rw ResponseWriter, req *Request) {
|
||||
+ if h, ok := req.Header["X-Evil"]; ok {
|
||||
+ t.Errorf("request has X-Evil header: %q", h)
|
||||
+ }
|
||||
+ })).ts
|
||||
+ defer ts.Close()
|
||||
+ req, _ := NewRequest("GET", ts.URL, nil)
|
||||
+ req.Host = "go.dev\r\nX-Evil:evil"
|
||||
+ resp, _ := ts.Client().Do(req)
|
||||
+ if resp != nil {
|
||||
+ resp.Body.Close()
|
||||
+ }
|
||||
+}
|
||||
--
|
||||
2.25.1
|
||||
175
meta/recipes-devtools/go/go-1.14/CVE-2023-29409.patch
Normal file
175
meta/recipes-devtools/go/go-1.14/CVE-2023-29409.patch
Normal file
@@ -0,0 +1,175 @@
|
||||
From 2300f7ef07718f6be4d8aa8486c7de99836e233f Mon Sep 17 00:00:00 2001
|
||||
From: Roland Shoemaker <bracewell@google.com>
|
||||
Date: Wed, 7 Jun 2023 15:27:13 -0700
|
||||
Subject: [PATCH] [release-branch.go1.19] crypto/tls: restrict RSA keys in
|
||||
certificates to <= 8192 bits
|
||||
|
||||
Extremely large RSA keys in certificate chains can cause a client/server
|
||||
to expend significant CPU time verifying signatures. Limit this by
|
||||
restricting the size of RSA keys transmitted during handshakes to <=
|
||||
8192 bits.
|
||||
|
||||
Based on a survey of publicly trusted RSA keys, there are currently only
|
||||
three certificates in circulation with keys larger than this, and all
|
||||
three appear to be test certificates that are not actively deployed. It
|
||||
is possible there are larger keys in use in private PKIs, but we target
|
||||
the web PKI, so causing breakage here in the interests of increasing the
|
||||
default safety of users of crypto/tls seems reasonable.
|
||||
|
||||
Thanks to Mateusz Poliwczak for reporting this issue.
|
||||
|
||||
Updates #61460
|
||||
Fixes #61579
|
||||
Fixes CVE-2023-29409
|
||||
|
||||
Change-Id: Ie35038515a649199a36a12fc2c5df3af855dca6c
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1912161
|
||||
Reviewed-by: Damien Neil <dneil@google.com>
|
||||
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
|
||||
Run-TryBot: Roland Shoemaker <bracewell@google.com>
|
||||
(cherry picked from commit d865c715d92887361e4bd5596e19e513f27781b7)
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1965487
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/514915
|
||||
Run-TryBot: David Chase <drchase@google.com>
|
||||
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
|
||||
TryBot-Bypass: David Chase <drchase@google.com>
|
||||
|
||||
Upstream-Status: Backport [https://github.com/golang/go/commit/2300f7ef07718f6be4d8aa8486c7de99836e233f]
|
||||
CVE: CVE-2023-29409
|
||||
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
|
||||
---
|
||||
src/crypto/tls/handshake_client.go | 8 +++
|
||||
src/crypto/tls/handshake_client_test.go | 78 +++++++++++++++++++++++++
|
||||
src/crypto/tls/handshake_server.go | 4 ++
|
||||
3 files changed, 90 insertions(+)
|
||||
|
||||
diff --git a/src/crypto/tls/handshake_client.go b/src/crypto/tls/handshake_client.go
|
||||
index 4fb528c..ba33ea1 100644
|
||||
--- a/src/crypto/tls/handshake_client.go
|
||||
+++ b/src/crypto/tls/handshake_client.go
|
||||
@@ -788,6 +788,10 @@ func (hs *clientHandshakeState) sendFinished(out []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
+// maxRSAKeySize is the maximum RSA key size in bits that we are willing
|
||||
+// to verify the signatures of during a TLS handshake.
|
||||
+const maxRSAKeySize = 8192
|
||||
+
|
||||
// verifyServerCertificate parses and verifies the provided chain, setting
|
||||
// c.verifiedChains and c.peerCertificates or sending the appropriate alert.
|
||||
func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
|
||||
@@ -798,6 +802,10 @@ func (c *Conn) verifyServerCertificate(certificates [][]byte) error {
|
||||
c.sendAlert(alertBadCertificate)
|
||||
return errors.New("tls: failed to parse certificate from server: " + err.Error())
|
||||
}
|
||||
+ if cert.PublicKeyAlgorithm == x509.RSA && cert.PublicKey.(*rsa.PublicKey).N.BitLen() > maxRSAKeySize {
|
||||
+ c.sendAlert(alertBadCertificate)
|
||||
+ return fmt.Errorf("tls: server sent certificate containing RSA key larger than %d bits", maxRSAKeySize)
|
||||
+ }
|
||||
certs[i] = cert
|
||||
}
|
||||
|
||||
diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go
|
||||
index 6bd3c37..8d20b2b 100644
|
||||
--- a/src/crypto/tls/handshake_client_test.go
|
||||
+++ b/src/crypto/tls/handshake_client_test.go
|
||||
@@ -1984,3 +1984,81 @@ func TestCloseClientConnectionOnIdleServer(t *testing.T) {
|
||||
t.Errorf("Error expected, but no error returned")
|
||||
}
|
||||
}
|
||||
+
|
||||
+// discardConn wraps a net.Conn but discards all writes, but reports that they happened.
|
||||
+type discardConn struct {
|
||||
+ net.Conn
|
||||
+}
|
||||
+
|
||||
+func (dc *discardConn) Write(data []byte) (int, error) {
|
||||
+ return len(data), nil
|
||||
+}
|
||||
+
|
||||
+// largeRSAKeyCertPEM contains a 8193 bit RSA key
|
||||
+const largeRSAKeyCertPEM = `-----BEGIN CERTIFICATE-----
|
||||
+MIIInjCCBIWgAwIBAgIBAjANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDEwd0ZXN0
|
||||
+aW5nMB4XDTIzMDYwNzIxMjMzNloXDTIzMDYwNzIzMjMzNlowEjEQMA4GA1UEAxMH
|
||||
+dGVzdGluZzCCBCIwDQYJKoZIhvcNAQEBBQADggQPADCCBAoCggQBAWdHsf6Rh2Ca
|
||||
+n2SQwn4t4OQrOjbLLdGE1pM6TBKKrHUFy62uEL8atNjlcfXIsa4aEu3xNGiqxqur
|
||||
+ZectlkZbm0FkaaQ1Wr9oikDY3KfjuaXdPdO/XC/h8AKNxlDOylyXwUSK/CuYb+1j
|
||||
+gy8yF5QFvVfwW/xwTlHmhUeSkVSQPosfQ6yXNNsmMzkd+ZPWLrfq4R+wiNtwYGu0
|
||||
+WSBcI/M9o8/vrNLnIppoiBJJ13j9CR1ToEAzOFh9wwRWLY10oZhoh1ONN1KQURx4
|
||||
+qedzvvP2DSjZbUccdvl2rBGvZpzfOiFdm1FCnxB0c72Cqx+GTHXBFf8bsa7KHky9
|
||||
+sNO1GUanbq17WoDNgwbY6H51bfShqv0CErxatwWox3we4EcAmFHPVTCYL1oWVMGo
|
||||
+a3Eth91NZj+b/nGhF9lhHKGzXSv9brmLLkfvM1jA6XhNhA7BQ5Vz67lj2j3XfXdh
|
||||
+t/BU5pBXbL4Ut4mIhT1YnKXAjX2/LF5RHQTE8Vwkx5JAEKZyUEGOReD/B+7GOrLp
|
||||
+HduMT9vZAc5aR2k9I8qq1zBAzsL69lyQNAPaDYd1BIAjUety9gAYaSQffCgAgpRO
|
||||
+Gt+DYvxS+7AT/yEd5h74MU2AH7KrAkbXOtlwupiGwhMVTstncDJWXMJqbBhyHPF8
|
||||
+3UmZH0hbL4PYmzSj9LDWQQXI2tv6vrCpfts3Cqhqxz9vRpgY7t1Wu6l/r+KxYYz3
|
||||
+1pcGpPvRmPh0DJm7cPTiXqPnZcPt+ulSaSdlxmd19OnvG5awp0fXhxryZVwuiT8G
|
||||
+VDkhyARrxYrdjlINsZJZbQjO0t8ketXAELJOnbFXXzeCOosyOHkLwsqOO96AVJA8
|
||||
+45ZVL5m95ClGy0RSrjVIkXsxTAMVG6SPAqKwk6vmTdRGuSPS4rhgckPVDHmccmuq
|
||||
+dfnT2YkX+wB2/M3oCgU+s30fAHGkbGZ0pCdNbFYFZLiH0iiMbTDl/0L/z7IdK0nH
|
||||
+GLHVE7apPraKC6xl6rPWsD2iSfrmtIPQa0+rqbIVvKP5JdfJ8J4alI+OxFw/znQe
|
||||
+V0/Rez0j22Fe119LZFFSXhRv+ZSvcq20xDwh00mzcumPWpYuCVPozA18yIhC9tNn
|
||||
+ALHndz0tDseIdy9vC71jQWy9iwri3ueN0DekMMF8JGzI1Z6BAFzgyAx3DkHtwHg7
|
||||
+B7qD0jPG5hJ5+yt323fYgJsuEAYoZ8/jzZ01pkX8bt+UsVN0DGnSGsI2ktnIIk3J
|
||||
+l+8krjmUy6EaW79nITwoOqaeHOIp8m3UkjEcoKOYrzHRKqRy+A09rY+m/cAQaafW
|
||||
+4xp0Zv7qZPLwnu0jsqB4jD8Ll9yPB02ndsoV6U5PeHzTkVhPml19jKUAwFfs7TJg
|
||||
+kXy+/xFhYVUCAwEAATANBgkqhkiG9w0BAQsFAAOCBAIAAQnZY77pMNeypfpba2WK
|
||||
+aDasT7dk2JqP0eukJCVPTN24Zca+xJNPdzuBATm/8SdZK9lddIbjSnWRsKvTnO2r
|
||||
+/rYdlPf3jM5uuJtb8+Uwwe1s+gszelGS9G/lzzq+ehWicRIq2PFcs8o3iQMfENiv
|
||||
+qILJ+xjcrvms5ZPDNahWkfRx3KCg8Q+/at2n5p7XYjMPYiLKHnDC+RE2b1qT20IZ
|
||||
+FhuK/fTWLmKbfYFNNga6GC4qcaZJ7x0pbm4SDTYp0tkhzcHzwKhidfNB5J2vNz6l
|
||||
+Ur6wiYwamFTLqcOwWo7rdvI+sSn05WQBv0QZlzFX+OAu0l7WQ7yU+noOxBhjvHds
|
||||
+14+r9qcQZg2q9kG+evopYZqYXRUNNlZKo9MRBXhfrISulFAc5lRFQIXMXnglvAu+
|
||||
+Ipz2gomEAOcOPNNVldhKAU94GAMJd/KfN0ZP7gX3YvPzuYU6XDhag5RTohXLm18w
|
||||
+5AF+ES3DOQ6ixu3DTf0D+6qrDuK+prdX8ivcdTQVNOQ+MIZeGSc6NWWOTaMGJ3lg
|
||||
+aZIxJUGdo6E7GBGiC1YTjgFKFbHzek1LRTh/LX3vbSudxwaG0HQxwsU9T4DWiMqa
|
||||
+Fkf2KteLEUA6HrR+0XlAZrhwoqAmrJ+8lCFX3V0gE9lpENfVHlFXDGyx10DpTB28
|
||||
+DdjnY3F7EPWNzwf9P3oNT69CKW3Bk6VVr3ROOJtDxVu1ioWo3TaXltQ0VOnap2Pu
|
||||
+sa5wfrpfwBDuAS9JCDg4ttNp2nW3F7tgXC6xPqw5pvGwUppEw9XNrqV8TZrxduuv
|
||||
+rQ3NyZ7KSzIpmFlD3UwV/fGfz3UQmHS6Ng1evrUID9DjfYNfRqSGIGjDfxGtYD+j
|
||||
+Z1gLJZuhjJpNtwBkKRtlNtrCWCJK2hidK/foxwD7kwAPo2I9FjpltxCRywZUs07X
|
||||
+KwXTfBR9v6ij1LV6K58hFS+8ezZyZ05CeVBFkMQdclTOSfuPxlMkQOtjp8QWDj+F
|
||||
+j/MYziT5KBkHvcbrjdRtUJIAi4N7zCsPZtjik918AK1WBNRVqPbrgq/XSEXMfuvs
|
||||
+6JbfK0B76vdBDRtJFC1JsvnIrGbUztxXzyQwFLaR/AjVJqpVlysLWzPKWVX6/+SJ
|
||||
+u1NQOl2E8P6ycyBsuGnO89p0S4F8cMRcI2X1XQsZ7/q0NBrOMaEp5T3SrWo9GiQ3
|
||||
+o2SBdbs3Y6MBPBtTu977Z/0RO63J3M5i2tjUiDfrFy7+VRLKr7qQ7JibohyB8QaR
|
||||
+9tedgjn2f+of7PnP/PEl1cCphUZeHM7QKUMPT8dbqwmKtlYY43EHXcvNOT5IBk3X
|
||||
+9lwJoZk/B2i+ZMRNSP34ztAwtxmasPt6RAWGQpWCn9qmttAHAnMfDqe7F7jVR6rS
|
||||
+u58=
|
||||
+-----END CERTIFICATE-----`
|
||||
+
|
||||
+func TestHandshakeRSATooBig(t *testing.T) {
|
||||
+ testCert, _ := pem.Decode([]byte(largeRSAKeyCertPEM))
|
||||
+
|
||||
+ c := &Conn{conn: &discardConn{}, config: testConfig.Clone()}
|
||||
+
|
||||
+ expectedErr := "tls: server sent certificate containing RSA key larger than 8192 bits"
|
||||
+ err := c.verifyServerCertificate([][]byte{testCert.Bytes})
|
||||
+ if err == nil || err.Error() != expectedErr {
|
||||
+ t.Errorf("Conn.verifyServerCertificate unexpected error: want %q, got %q", expectedErr, err)
|
||||
+ }
|
||||
+
|
||||
+ expectedErr = "tls: client sent certificate containing RSA key larger than 8192 bits"
|
||||
+ err = c.processCertsFromClient(Certificate{Certificate: [][]byte{testCert.Bytes}})
|
||||
+ if err == nil || err.Error() != expectedErr {
|
||||
+ t.Errorf("Conn.processCertsFromClient unexpected error: want %q, got %q", expectedErr, err)
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/crypto/tls/handshake_server.go b/src/crypto/tls/handshake_server.go
|
||||
index b16415a..2e36840 100644
|
||||
--- a/src/crypto/tls/handshake_server.go
|
||||
+++ b/src/crypto/tls/handshake_server.go
|
||||
@@ -738,6 +738,10 @@ func (c *Conn) processCertsFromClient(certificate Certificate) error {
|
||||
c.sendAlert(alertBadCertificate)
|
||||
return errors.New("tls: failed to parse client certificate: " + err.Error())
|
||||
}
|
||||
+ if certs[i].PublicKeyAlgorithm == x509.RSA && certs[i].PublicKey.(*rsa.PublicKey).N.BitLen() > maxRSAKeySize {
|
||||
+ c.sendAlert(alertBadCertificate)
|
||||
+ return fmt.Errorf("tls: client sent certificate containing RSA key larger than %d bits", maxRSAKeySize)
|
||||
+ }
|
||||
}
|
||||
|
||||
if len(certs) == 0 && requiresClientCert(c.config.ClientAuth) {
|
||||
--
|
||||
2.25.1
|
||||
|
||||
262
meta/recipes-devtools/go/go-1.14/CVE-2023-39318.patch
Normal file
262
meta/recipes-devtools/go/go-1.14/CVE-2023-39318.patch
Normal file
@@ -0,0 +1,262 @@
|
||||
From 023b542edf38e2a1f87fcefb9f75ff2f99401b4c Mon Sep 17 00:00:00 2001
|
||||
From: Roland Shoemaker <bracewell@google.com>
|
||||
Date: Thu, 3 Aug 2023 12:24:13 -0700
|
||||
Subject: [PATCH] [release-branch.go1.20] html/template: support HTML-like
|
||||
comments in script contexts
|
||||
|
||||
Per Appendix B.1.1 of the ECMAScript specification, support HTML-like
|
||||
comments in script contexts. Also per section 12.5, support hashbang
|
||||
comments. This brings our parsing in-line with how browsers treat these
|
||||
comment types.
|
||||
|
||||
Thanks to Takeshi Kaneko (GMO Cybersecurity by Ierae, Inc.) for
|
||||
reporting this issue.
|
||||
|
||||
Fixes #62196
|
||||
Fixes #62395
|
||||
Fixes CVE-2023-39318
|
||||
|
||||
Change-Id: Id512702c5de3ae46cf648e268cb10e1eb392a181
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1976593
|
||||
Run-TryBot: Roland Shoemaker <bracewell@google.com>
|
||||
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
|
||||
Reviewed-by: Damien Neil <dneil@google.com>
|
||||
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
|
||||
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2014620
|
||||
Reviewed-on: https://go-review.googlesource.com/c/go/+/526098
|
||||
Run-TryBot: Cherry Mui <cherryyz@google.com>
|
||||
TryBot-Result: Gopher Robot <gobot@golang.org>
|
||||
|
||||
Upstream-Status: Backport from [https://github.com/golang/go/commit/023b542edf38e2a1f87fcefb9f75ff2f99401b4c]
|
||||
CVE: CVE-2023-39318
|
||||
Signed-off-by: Siddharth Doshi <sdoshi@mvista.com>
|
||||
---
|
||||
src/html/template/context.go | 6 ++-
|
||||
src/html/template/escape.go | 5 +-
|
||||
src/html/template/escape_test.go | 10 ++++
|
||||
src/html/template/state_string.go | 26 +++++-----
|
||||
src/html/template/transition.go | 80 ++++++++++++++++++++-----------
|
||||
5 files changed, 84 insertions(+), 43 deletions(-)
|
||||
|
||||
diff --git a/src/html/template/context.go b/src/html/template/context.go
|
||||
index 0b65313..4eb7891 100644
|
||||
--- a/src/html/template/context.go
|
||||
+++ b/src/html/template/context.go
|
||||
@@ -124,6 +124,10 @@ const (
|
||||
stateJSBlockCmt
|
||||
// stateJSLineCmt occurs inside a JavaScript // line comment.
|
||||
stateJSLineCmt
|
||||
+ // stateJSHTMLOpenCmt occurs inside a JavaScript <!-- HTML-like comment.
|
||||
+ stateJSHTMLOpenCmt
|
||||
+ // stateJSHTMLCloseCmt occurs inside a JavaScript --> HTML-like comment.
|
||||
+ stateJSHTMLCloseCmt
|
||||
// stateCSS occurs inside a <style> element or style attribute.
|
||||
stateCSS
|
||||
// stateCSSDqStr occurs inside a CSS double quoted string.
|
||||
@@ -149,7 +153,7 @@ const (
|
||||
// authors & maintainers, not for end-users or machines.
|
||||
func isComment(s state) bool {
|
||||
switch s {
|
||||
- case stateHTMLCmt, stateJSBlockCmt, stateJSLineCmt, stateCSSBlockCmt, stateCSSLineCmt:
|
||||
+ case stateHTMLCmt, stateJSBlockCmt, stateJSLineCmt, stateJSHTMLOpenCmt, stateJSHTMLCloseCmt, stateCSSBlockCmt, stateCSSLineCmt:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
diff --git a/src/html/template/escape.go b/src/html/template/escape.go
|
||||
index 435f912..ad2ec69 100644
|
||||
--- a/src/html/template/escape.go
|
||||
+++ b/src/html/template/escape.go
|
||||
@@ -698,9 +698,12 @@ func (e *escaper) escapeText(c context, n *parse.TextNode) context {
|
||||
if c.state != c1.state && isComment(c1.state) && c1.delim == delimNone {
|
||||
// Preserve the portion between written and the comment start.
|
||||
cs := i1 - 2
|
||||
- if c1.state == stateHTMLCmt {
|
||||
+ if c1.state == stateHTMLCmt || c1.state == stateJSHTMLOpenCmt {
|
||||
// "<!--" instead of "/*" or "//"
|
||||
cs -= 2
|
||||
+ } else if c1.state == stateJSHTMLCloseCmt {
|
||||
+ // "-->" instead of "/*" or "//"
|
||||
+ cs -= 1
|
||||
}
|
||||
b.Write(s[written:cs])
|
||||
written = i1
|
||||
diff --git a/src/html/template/escape_test.go b/src/html/template/escape_test.go
|
||||
index f550691..5f41e52 100644
|
||||
--- a/src/html/template/escape_test.go
|
||||
+++ b/src/html/template/escape_test.go
|
||||
@@ -503,6 +503,16 @@ func TestEscape(t *testing.T) {
|
||||
"<script>var a/*b*///c\nd</script>",
|
||||
"<script>var a \nd</script>",
|
||||
},
|
||||
+ {
|
||||
+ "JS HTML-like comments",
|
||||
+ "<script>before <!-- beep\nbetween\nbefore-->boop\n</script>",
|
||||
+ "<script>before \nbetween\nbefore\n</script>",
|
||||
+ },
|
||||
+ {
|
||||
+ "JS hashbang comment",
|
||||
+ "<script>#! beep\n</script>",
|
||||
+ "<script>\n</script>",
|
||||
+ },
|
||||
{
|
||||
"CSS comments",
|
||||
"<style>p// paragraph\n" +
|
||||
diff --git a/src/html/template/state_string.go b/src/html/template/state_string.go
|
||||
index 05104be..b5cfe70 100644
|
||||
--- a/src/html/template/state_string.go
|
||||
+++ b/src/html/template/state_string.go
|
||||
@@ -25,21 +25,23 @@ func _() {
|
||||
_ = x[stateJSRegexp-14]
|
||||
_ = x[stateJSBlockCmt-15]
|
||||
_ = x[stateJSLineCmt-16]
|
||||
- _ = x[stateCSS-17]
|
||||
- _ = x[stateCSSDqStr-18]
|
||||
- _ = x[stateCSSSqStr-19]
|
||||
- _ = x[stateCSSDqURL-20]
|
||||
- _ = x[stateCSSSqURL-21]
|
||||
- _ = x[stateCSSURL-22]
|
||||
- _ = x[stateCSSBlockCmt-23]
|
||||
- _ = x[stateCSSLineCmt-24]
|
||||
- _ = x[stateError-25]
|
||||
- _ = x[stateDead-26]
|
||||
+ _ = x[stateJSHTMLOpenCmt-17]
|
||||
+ _ = x[stateJSHTMLCloseCmt-18]
|
||||
+ _ = x[stateCSS-19]
|
||||
+ _ = x[stateCSSDqStr-20]
|
||||
+ _ = x[stateCSSSqStr-21]
|
||||
+ _ = x[stateCSSDqURL-22]
|
||||
+ _ = x[stateCSSSqURL-23]
|
||||
+ _ = x[stateCSSURL-24]
|
||||
+ _ = x[stateCSSBlockCmt-25]
|
||||
+ _ = x[stateCSSLineCmt-26]
|
||||
+ _ = x[stateError-27]
|
||||
+ _ = x[stateDead-28]
|
||||
}
|
||||
|
||||
-const _state_name = "stateTextstateTagstateAttrNamestateAfterNamestateBeforeValuestateHTMLCmtstateRCDATAstateAttrstateURLstateSrcsetstateJSstateJSDqStrstateJSSqStrstateJSBqStrstateJSRegexpstateJSBlockCmtstateJSLineCmtstateCSSstateCSSDqStrstateCSSSqStrstateCSSDqURLstateCSSSqURLstateCSSURLstateCSSBlockCmtstateCSSLineCmtstateErrorstateDead"
|
||||
+const _state_name = "stateTextstateTagstateAttrNamestateAfterNamestateBeforeValuestateHTMLCmtstateRCDATAstateAttrstateURLstateSrcsetstateJSstateJSDqStrstateJSSqStrstateJSBqStrstateJSRegexpstateJSBlockCmtstateJSLineCmtstateJSHTMLOpenCmtstateJSHTMLCloseCmtstateCSSstateCSSDqStrstateCSSSqStrstateCSSDqURLstateCSSSqURLstateCSSURLstateCSSBlockCmtstateCSSLineCmtstateErrorstateDead"
|
||||
|
||||
-var _state_index = [...]uint16{0, 9, 17, 30, 44, 60, 72, 83, 92, 100, 111, 118, 130, 142, 154, 167, 182, 196, 204, 217, 230, 243, 256, 267, 283, 298, 308, 317}
|
||||
+var _state_index = [...]uint16{0, 9, 17, 30, 44, 60, 72, 83, 92, 100, 111, 118, 130, 142, 154, 167, 182, 196, 214, 233, 241, 254, 267, 280, 293, 304, 320, 335, 345, 354}
|
||||
|
||||
func (i state) String() string {
|
||||
if i >= state(len(_state_index)-1) {
|
||||
diff --git a/src/html/template/transition.go b/src/html/template/transition.go
|
||||
index 92eb351..12aa4c4 100644
|
||||
--- a/src/html/template/transition.go
|
||||
+++ b/src/html/template/transition.go
|
||||
@@ -14,32 +14,34 @@ import (
|
||||
// the updated context and the number of bytes consumed from the front of the
|
||||
// input.
|
||||
var transitionFunc = [...]func(context, []byte) (context, int){
|
||||
- stateText: tText,
|
||||
- stateTag: tTag,
|
||||
- stateAttrName: tAttrName,
|
||||
- stateAfterName: tAfterName,
|
||||
- stateBeforeValue: tBeforeValue,
|
||||
- stateHTMLCmt: tHTMLCmt,
|
||||
- stateRCDATA: tSpecialTagEnd,
|
||||
- stateAttr: tAttr,
|
||||
- stateURL: tURL,
|
||||
- stateSrcset: tURL,
|
||||
- stateJS: tJS,
|
||||
- stateJSDqStr: tJSDelimited,
|
||||
- stateJSSqStr: tJSDelimited,
|
||||
- stateJSBqStr: tJSDelimited,
|
||||
- stateJSRegexp: tJSDelimited,
|
||||
- stateJSBlockCmt: tBlockCmt,
|
||||
- stateJSLineCmt: tLineCmt,
|
||||
- stateCSS: tCSS,
|
||||
- stateCSSDqStr: tCSSStr,
|
||||
- stateCSSSqStr: tCSSStr,
|
||||
- stateCSSDqURL: tCSSStr,
|
||||
- stateCSSSqURL: tCSSStr,
|
||||
- stateCSSURL: tCSSStr,
|
||||
- stateCSSBlockCmt: tBlockCmt,
|
||||
- stateCSSLineCmt: tLineCmt,
|
||||
- stateError: tError,
|
||||
+ stateText: tText,
|
||||
+ stateTag: tTag,
|
||||
+ stateAttrName: tAttrName,
|
||||
+ stateAfterName: tAfterName,
|
||||
+ stateBeforeValue: tBeforeValue,
|
||||
+ stateHTMLCmt: tHTMLCmt,
|
||||
+ stateRCDATA: tSpecialTagEnd,
|
||||
+ stateAttr: tAttr,
|
||||
+ stateURL: tURL,
|
||||
+ stateSrcset: tURL,
|
||||
+ stateJS: tJS,
|
||||
+ stateJSDqStr: tJSDelimited,
|
||||
+ stateJSSqStr: tJSDelimited,
|
||||
+ stateJSBqStr: tJSDelimited,
|
||||
+ stateJSRegexp: tJSDelimited,
|
||||
+ stateJSBlockCmt: tBlockCmt,
|
||||
+ stateJSLineCmt: tLineCmt,
|
||||
+ stateJSHTMLOpenCmt: tLineCmt,
|
||||
+ stateJSHTMLCloseCmt: tLineCmt,
|
||||
+ stateCSS: tCSS,
|
||||
+ stateCSSDqStr: tCSSStr,
|
||||
+ stateCSSSqStr: tCSSStr,
|
||||
+ stateCSSDqURL: tCSSStr,
|
||||
+ stateCSSSqURL: tCSSStr,
|
||||
+ stateCSSURL: tCSSStr,
|
||||
+ stateCSSBlockCmt: tBlockCmt,
|
||||
+ stateCSSLineCmt: tLineCmt,
|
||||
+ stateError: tError,
|
||||
}
|
||||
|
||||
var commentStart = []byte("<!--")
|
||||
@@ -263,7 +265,7 @@ func tURL(c context, s []byte) (context, int) {
|
||||
|
||||
// tJS is the context transition function for the JS state.
|
||||
func tJS(c context, s []byte) (context, int) {
|
||||
- i := bytes.IndexAny(s, "\"`'/")
|
||||
+ i := bytes.IndexAny(s, "\"`'/<-#")
|
||||
if i == -1 {
|
||||
// Entire input is non string, comment, regexp tokens.
|
||||
c.jsCtx = nextJSCtx(s, c.jsCtx)
|
||||
@@ -293,6 +295,26 @@ func tJS(c context, s []byte) (context, int) {
|
||||
err: errorf(ErrSlashAmbig, nil, 0, "'/' could start a division or regexp: %.32q", s[i:]),
|
||||
}, len(s)
|
||||
}
|
||||
+ // ECMAScript supports HTML style comments for legacy reasons, see Appendix
|
||||
+ // B.1.1 "HTML-like Comments". The handling of these comments is somewhat
|
||||
+ // confusing. Multi-line comments are not supported, i.e. anything on lines
|
||||
+ // between the opening and closing tokens is not considered a comment, but
|
||||
+ // anything following the opening or closing token, on the same line, is
|
||||
+ // ignored. As such we simply treat any line prefixed with "<!--" or "-->"
|
||||
+ // as if it were actually prefixed with "//" and move on.
|
||||
+ case '<':
|
||||
+ if i+3 < len(s) && bytes.Equal(commentStart, s[i:i+4]) {
|
||||
+ c.state, i = stateJSHTMLOpenCmt, i+3
|
||||
+ }
|
||||
+ case '-':
|
||||
+ if i+2 < len(s) && bytes.Equal(commentEnd, s[i:i+3]) {
|
||||
+ c.state, i = stateJSHTMLCloseCmt, i+2
|
||||
+ }
|
||||
+ // ECMAScript also supports "hashbang" comment lines, see Section 12.5.
|
||||
+ case '#':
|
||||
+ if i+1 < len(s) && s[i+1] == '!' {
|
||||
+ c.state, i = stateJSLineCmt, i+1
|
||||
+ }
|
||||
default:
|
||||
panic("unreachable")
|
||||
}
|
||||
@@ -372,12 +394,12 @@ func tBlockCmt(c context, s []byte) (context, int) {
|
||||
return c, i + 2
|
||||
}
|
||||
|
||||
-// tLineCmt is the context transition function for //comment states.
|
||||
+// tLineCmt is the context transition function for //comment states, and the JS HTML-like comment state.
|
||||
func tLineCmt(c context, s []byte) (context, int) {
|
||||
var lineTerminators string
|
||||
var endState state
|
||||
switch c.state {
|
||||
- case stateJSLineCmt:
|
||||
+ case stateJSLineCmt, stateJSHTMLOpenCmt, stateJSHTMLCloseCmt:
|
||||
lineTerminators, endState = "\n\r\u2028\u2029", stateJS
|
||||
case stateCSSLineCmt:
|
||||
lineTerminators, endState = "\n\f\r", stateCSS
|
||||
--
|
||||
2.24.4
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user