Skip to content

Commit 044f27c

Browse files
authored
Merge pull request #8089 from ja-pa/openocd-security-fix
openocd: patch security issue
2 parents f10c4af + 89789e3 commit 044f27c

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

utils/openocd/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
1010
PKG_NAME:=openocd
1111
PKG_SOURCE_VERSION:=0.10.0
1212
PKG_VERSION:=v$(PKG_SOURCE_VERSION)
13-
PKG_RELEASE:=1
13+
PKG_RELEASE:=2
1414

1515
PKG_SOURCE_URL:=@SF/openocd
1616
PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.bz2
@@ -20,6 +20,7 @@ PKG_LICENSE:=GPL-2.0
2020
PKG_LICENSE_FILES:=COPYING
2121

2222
PKG_MAINTAINER:=Paul Fertser <fercerpav@gmail.com>
23+
PKG_CPE_ID:=cpe:/a:openocd:open_on-chip_debugger
2324

2425
PKG_BUILD_PARALLEL:=1
2526
PKG_INSTALL:=1
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Subject: Bind to IPv4 localhost by default
2+
Origin: other, http://openocd.zylin.com/#/c/4331/2
3+
Last-Update: 2018-01-18
4+
5+
From f8630b0b15e30dc6c51270006a4e075c79cf466a Mon Sep 17 00:00:00 2001
6+
From: Paul Fertser <fercerpav@gmail.com>
7+
Date: Sat, 13 Jan 2018 16:22:10 +0300
8+
Subject: [PATCH] server: bind to IPv4 localhost by default
9+
10+
Since OpenOCD basically allows to perform arbitrary actions on behalf of
11+
the running user, it makes sense to restrict the exposure by default.
12+
13+
If you need network connectivity and your environment is safe enough,
14+
use "bindto 0.0.0.0" to switch to the old behaviour.
15+
16+
Change-Id: I4a4044b90d0ecb30118cea96fc92a7bcff0924e0
17+
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
18+
---
19+
20+
diff --git a/doc/openocd.texi b/doc/openocd.texi
21+
index 7f5b72e..5c7f465 100644
22+
--- a/doc/openocd.texi
23+
+++ b/doc/openocd.texi
24+
@@ -7017,7 +7017,7 @@
25+
26+
@deffn Command bindto [name]
27+
Specify address by name on which to listen for incoming TCP/IP connections.
28+
-By default, OpenOCD will listen on all available interfaces.
29+
+By default, OpenOCD will listen on the loopback interface only.
30+
@end deffn
31+
32+
@anchor{targetstatehandling}
33+
diff --git a/src/server/server.c b/src/server/server.c
34+
index 1e52e97..ea1e898 100644
35+
--- a/src/server/server.c
36+
+++ b/src/server/server.c
37+
@@ -259,7 +259,7 @@
38+
c->sin.sin_family = AF_INET;
39+
40+
if (bindto_name == NULL)
41+
- c->sin.sin_addr.s_addr = INADDR_ANY;
42+
+ c->sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
43+
else {
44+
hp = gethostbyname(bindto_name);
45+
if (hp == NULL) {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Subject: Prevent some forms of Cross Protocol Scripting attacks
2+
Author: Andreas Fritiofson <andreas.fritiofson@gmail.com>
3+
Origin: other, http://openocd.zylin.com/#/c/4335/
4+
Bug-Debian: https://bugs.debian.org/887488
5+
Last-Update: 2018-01-18
6+
7+
From 3a223ca3ebc7ac24d7726a0cd58e5695bc813657 Mon Sep 17 00:00:00 2001
8+
From: Andreas Fritiofson <andreas.fritiofson@gmail.com>
9+
Date: Sat, 13 Jan 2018 21:00:47 +0100
10+
Subject: [PATCH] CVE-2018-5704: Prevent some forms of Cross Protocol Scripting attacks
11+
12+
OpenOCD can be targeted by a Cross Protocol Scripting attack from
13+
a web browser running malicious code, such as the following PoC:
14+
15+
var x = new XMLHttpRequest();
16+
x.open("POST", "http://127.0.0.1:4444", true);
17+
x.send("exec xcalc\r\n");
18+
19+
This mitigation should provide some protection from browser-based
20+
attacks and is based on the corresponding fix in Redis:
21+
22+
https://github.com/antirez/redis/blob/8075572207b5aebb1385c4f233f5302544439325/src/networking.c#L1758
23+
24+
Change-Id: Ia96ebe19b74b5805dc228bf7364c7971a90a4581
25+
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
26+
Reported-by: Josef Gajdusek <atx@atx.name>
27+
---
28+
29+
diff --git a/src/server/startup.tcl b/src/server/startup.tcl
30+
index 64ace40..dd1b31e 100644
31+
--- a/src/server/startup.tcl
32+
+++ b/src/server/startup.tcl
33+
@@ -8,3 +8,14 @@
34+
# one target
35+
reset halt
36+
}
37+
+
38+
+proc prevent_cps {} {
39+
+ echo "Possible SECURITY ATTACK detected."
40+
+ echo "It looks like somebody is sending POST or Host: commands to OpenOCD."
41+
+ echo "This is likely due to an attacker attempting to use Cross Protocol Scripting"
42+
+ echo "to compromise your OpenOCD instance. Connection aborted."
43+
+ exit
44+
+}
45+
+
46+
+proc POST {args} { prevent_cps }
47+
+proc Host: {args} { prevent_cps }

0 commit comments

Comments
 (0)