openssl安全漏洞解决方案
文章目录
概述
大部分联网产品都需要进行安全漏洞扫描,本项目网关设备通过安全漏洞扫描工具,扫描得到当前固件中openssl以及openssh存在安全漏洞,本文描述解决问题的思路和方法。
openssl官方会发布最新发现的安全漏洞以及对应的解决方案:可在[https://www.openssl.org/news/newslog.html]查看
处理安全漏洞的方式大致如下:
1、升级版本
2、当前版本打补丁
本项目使用openssl-1.0.1j+openssh7.3p1,截至20221226号,需要解决的高危安全漏洞有:CVE-2022-1292、CVE-2022-2068、CVE-2022-0778、CVE-2021-3712、CVE-2021-41617等,采用升级版本的方式解决。
项目背景
项目使用openssl-1.0.1j + openssh-7.3p1,系统测试时发现当前openssl库和openssh工具具有安全漏洞,需要对其打补丁或者升级操作。
openssl库可能有较多上层应用或库对其依赖,所以版本最好选择相近版本。
在openssl官网上查看版本更新log,得出:
1、1.0.1x版本在16年已经不维护了,所以更新1.0.1x版本方案被排除
2、openssl不同大版本之间差别较大(例如1.x和3.x),因此选择1.1.x来替代1.0.1x更合适。
1.1.1x版本距今一直维护,且最新的1.1.1q解决了上述安全漏洞。
openssh是一个独立的app,直接选择最新版本即可
综上:openssl_1.1.1q + openssh_9.1p1
openssl_1.0.x升级至openssl_1.1.1q
参考buildroot-2022.11/package/libopenssl
buildroot配置
BR2_PACKAGE_OPENSSL=y
BR2_PACKAGE_LIBOPENSSL=y
BR2_PACKAGE_LIBOPENSSL_TARGET_ARCH="linux-mips32"
# BR2_PACKAGE_LIBOPENSSL_BIN is not set
# BR2_PACKAGE_LIBOPENSSL_ENGINES is not set
BR2_PACKAGE_HAS_OPENSSL=y
BR2_PACKAGE_PROVIDES_OPENSSL="libopenssl"
BR2_PACKAGE_PROVIDES_HOST_OPENSSL="host-libopenssl"
BR2_PACKAGE_LIBOPENSSL_ENABLE_SEED=y
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
hostapd/wpa_supplicant编译报错
buildroot整编时发现升级openssl后,以前的hostapd和wpa_supplicant模块编译出错
原因:openssl未打开如下配置,导致相关接口未找到,出现链接错误
1153 BR2_PACKAGE_LIBOPENSSL_ENABLE_DES=y
1154 BR2_PACKAGE_LIBOPENSSL_ENABLE_MD4=y
1155 BR2_PACKAGE_LIBOPENSSL_ENABLE_MD2=y
1156 BR2_PACKAGE_LIBOPENSSL_ENABLE_RC4=y
1157 BR2_PACKAGE_LIBOPENSSL_ENABLE_BLAKE2=y
1158 BR2_PACKAGE_LIBOPENSSL_ENABLE_RMD160=y
1159 BR2_PACKAGE_LIBOPENSSL_ENABLE_WHIRLPOOL=y
1160 BR2_PACKAGE_LIBOPENSSL_ENABLE_SSL=y
1161 BR2_PACKAGE_LIBOPENSSL_ENABLE_SSL2=y
1162 BR2_PACKAGE_LIBOPENSSL_ENABLE_WEAK_SSL=y
1163 BR2_PACKAGE_LIBOPENSSL_ENABLE_PSK=y
1164 BR2_PACKAGE_LIBOPENSSL_DYNAMIC_ENGINE=y
1165 BR2_PACKAGE_LIBOPENSSL_ENABLE_COMP=y
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
本项目未用到wifi模块,所以直接裁掉hostapd和wpa_supplicant模块。根据自己项目实际选择解决方案。
升级完openssl后,sshd启动慢
现象
1、设备启动后,立即执行/usr/sbin/sshd [-d] 无log打印,且ssh client无法连接,4~5分后sshd正常启动,ssh client可以正常连接。之后再重新执行sshd一切都正常
2、设备启动后4~5分后,手动执行/usr/sbin/sshd 可以正常运行
解决
本项目内核版本linux-3.10.14
法1:升级内核
在openssh和openssl中增加打印,发现4~5分钟的耗时发生在:
openssh/sshd.c:
main
seed_rng
if (RAND_status() != 1)
openssl/crypto/rand/rand_lib.c:
RAND_status
return meth->status();
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
最终产生一个中断,进入内核
kernel/irq/handle.c
handle_irq_event_percpu
add_interrupt_randomness
if ((fast_pool->count & 1023) &&
!time_after(now, fast_pool->last + HZ)) //卡在了这里
- 1
- 2
- 3
- 4
- 5
不清楚为什么在kernel的add_interrupt_randomness中卡住,解决方式如下:
参考内核-随机数快速初始化补丁:https://patchwork.kernel.org/patch/6781261/
add_interrupt_randomness():
762 if ((fast_pool->count & 1023) &&
763 !time_after(now, fast_pool->last + HZ) &&
764 nonblocking_pool.initialized)
765 return;
- 1
- 2
- 3
- 4
- 5
- 6
重新烧录内核,问题解决。
但对于已出厂的产品,升级内核风险较大,有没有不升级内核解决的办法?答案是有的,见法2
法2:修改配置项
还原法1修改的内核代码,重新研究openssl-1.1.1q代码
在buildroot编译配置openssl时发现如下log:
Configuring OpenSSL version 1.1.1q (0x1010111fL) for linux-mips32
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile
- 1
- 2
- 3
- 4
其中“Using os-specific seed configuration”,推测openssl可以选择随机数获取seed的方式
查看grep seed ./Configure,得到:
my @known_seed_sources = qw(getrandom devrandom os egd none rdcpu librandom);
my @seed_sources = ();
elsif (/^--with-rand-seed=(.*)$/)
die "Unknown --with-rand-seed choice $x\n"
if ! grep { $x eq $_ } @known_seed_sources;
push @seed_sources, $x;
if (scalar(@seed_sources) == 0) {
print "Using os-specific seed configuration\n";
push @seed_sources, 'os';
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
即如果配置中没有—with-rand-seed=,则默认使用内核(OS)来产生随机数的seed,已知通过内核产生seed耗时较长,是否可以通过其他方式产生?答案是肯定的,修改如下:
buildroot方式:
buildroot配置文件增加:
BR2_PACKAGE_LIBOPENSSL_ENABLE_SEED=y
package/libopenssl/*.mk修改:
define LIBOPENSSL_CONFIGURE_CMDS中增加
--with-rand-seed=devrandom \
- 1
- 2
- 3
- 4
- 5
- 6
—with-rand-seed=devrandom即采用/dev/*random来产生随机数
重新编译openssl和ssh,烧录后解决问题。
单编方式:
在./Configure中增加一个:--with-rand-seed=devrandom即可
- 1
重新编译openssl和ssh,烧录后解决问题。
openssh_9.1p1
正常编译即可。但在使用时出现如下问题
scp无法使用
现象
buildroot编译方式可能出现该问题,报错如下:
PC端执行scp时报错:
sh: scp: not found
lost connection
- 1
- 2
- 3
解决
首先确定设备测scp存在,且env中的PATH正确,能够寻到scp,在此基础上:
查看openssh配置时—with-default-path=的值是什么,我这里该值是空的,导致了上述问题
修改package/openssh.mk 或者在配置时增加—with-default-path=/usr/bin即可
21 OPENSSH_CONF_OPTS = \
22 --sysconfdir=/etc/ssh \
23 --with-default-path=/usr/bin \
24 $(if $(BR2_PACKAGE_OPENSSH_SANDBOX),--with-sandbox,--without-sandbox) \
- 1
- 2
- 3
- 4
- 分享
- 举报

-
浏览量:1640次2020-01-09 09:50:03
-
浏览量:1862次2020-02-10 14:39:42
-
浏览量:37279次2019-07-18 16:11:02
-
浏览量:1543次2019-05-30 09:48:53
-
浏览量:1588次2022-10-20 17:13:08
-
浏览量:1949次2018-01-11 11:40:23
-
2020-12-12 22:07:09
-
浏览量:2347次2018-05-07 13:06:55
-
浏览量:2289次2019-09-16 16:15:15
-
浏览量:3460次2020-12-03 14:16:32
-
浏览量:3199次2018-05-07 16:22:35
-
浏览量:1089次2024-07-18 15:47:26
-
浏览量:2186次2019-11-18 14:31:41
-
浏览量:2644次2017-11-20 12:34:12
-
浏览量:2641次2020-12-15 19:49:25
-
浏览量:4923次2021-02-01 17:23:10
-
浏览量:1759次2020-06-23 16:51:48
-
浏览量:1991次2022-10-09 10:49:04
-
浏览量:3697次2022-01-31 09:00:24
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖
阿帅






举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明