Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame^] | 1 | From d13302656d9ff0807c5defe18623adc947f43a2b Mon Sep 17 00:00:00 2001 |
| 2 | From: Narpat Mali <narpat.mali@windriver.com> |
| 3 | Date: Wed, 8 Feb 2023 13:15:39 +0000 |
| 4 | Subject: [PATCH] agent: Disallow SET requests with any NULL varbind Merge pull |
| 5 | request #490 from fenner/set-null |
| 6 | |
| 7 | fixes: #474 and #475 |
| 8 | |
| 9 | CVE: CVE-2022-44792, CVE-2022-44793 |
| 10 | |
| 11 | Upstream-Status: Backport [https://github.com/net-snmp/net-snmp/commit/be804106fd0771a7d05236cff36e199af077af57] |
| 12 | |
| 13 | Signed-off-by: Narpat Mali <narpat.mali@windriver.com> |
| 14 | --- |
| 15 | agent/snmp_agent.c | 32 +++++++++++++++++++ |
| 16 | apps/snmpset.c | 1 + |
| 17 | .../default/T0142snmpv2csetnull_simple | 31 ++++++++++++++++++ |
| 18 | 3 files changed, 64 insertions(+) |
| 19 | create mode 100644 testing/fulltests/default/T0142snmpv2csetnull_simple |
| 20 | |
| 21 | diff --git a/agent/snmp_agent.c b/agent/snmp_agent.c |
| 22 | index 867d0c1..3f678fe 100644 |
| 23 | --- a/agent/snmp_agent.c |
| 24 | +++ b/agent/snmp_agent.c |
| 25 | @@ -3719,12 +3719,44 @@ netsnmp_handle_request(netsnmp_agent_session *asp, int status) |
| 26 | return 1; |
| 27 | } |
| 28 | |
| 29 | +static int |
| 30 | +check_set_pdu_for_null_varbind(netsnmp_agent_session *asp) |
| 31 | +{ |
| 32 | + int i; |
| 33 | + netsnmp_variable_list *v = NULL; |
| 34 | + |
| 35 | + for (i = 1, v = asp->pdu->variables; v != NULL; i++, v = v->next_variable) { |
| 36 | + if (v->type == ASN_NULL) { |
| 37 | + /* |
| 38 | + * Protect SET implementations that do not protect themselves |
| 39 | + * against wrong type. |
| 40 | + */ |
| 41 | + DEBUGMSGTL(("snmp_agent", "disallowing SET with NULL var for varbind %d\n", i)); |
| 42 | + asp->index = i; |
| 43 | + return SNMP_ERR_WRONGTYPE; |
| 44 | + } |
| 45 | + } |
| 46 | + return SNMP_ERR_NOERROR; |
| 47 | +} |
| 48 | + |
| 49 | int |
| 50 | handle_pdu(netsnmp_agent_session *asp) |
| 51 | { |
| 52 | int status, inclusives = 0; |
| 53 | netsnmp_variable_list *v = NULL; |
| 54 | |
| 55 | +#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 56 | + /* |
| 57 | + * Check for ASN_NULL in SET request |
| 58 | + */ |
| 59 | + if (asp->pdu->command == SNMP_MSG_SET) { |
| 60 | + status = check_set_pdu_for_null_varbind(asp); |
| 61 | + if (status != SNMP_ERR_NOERROR) { |
| 62 | + return status; |
| 63 | + } |
| 64 | + } |
| 65 | +#endif /* NETSNMP_NO_WRITE_SUPPORT */ |
| 66 | + |
| 67 | /* |
| 68 | * for illegal requests, mark all nodes as ASN_NULL |
| 69 | */ |
| 70 | diff --git a/apps/snmpset.c b/apps/snmpset.c |
| 71 | index 48e14bd..d542713 100644 |
| 72 | --- a/apps/snmpset.c |
| 73 | +++ b/apps/snmpset.c |
| 74 | @@ -182,6 +182,7 @@ main(int argc, char *argv[]) |
| 75 | case 'x': |
| 76 | case 'd': |
| 77 | case 'b': |
| 78 | + case 'n': /* undocumented */ |
| 79 | #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES |
| 80 | case 'I': |
| 81 | case 'U': |
| 82 | diff --git a/testing/fulltests/default/T0142snmpv2csetnull_simple b/testing/fulltests/default/T0142snmpv2csetnull_simple |
| 83 | new file mode 100644 |
| 84 | index 0000000..0f1b8f3 |
| 85 | --- /dev/null |
| 86 | +++ b/testing/fulltests/default/T0142snmpv2csetnull_simple |
| 87 | @@ -0,0 +1,31 @@ |
| 88 | +#!/bin/sh |
| 89 | + |
| 90 | +. ../support/simple_eval_tools.sh |
| 91 | + |
| 92 | +HEADER SNMPv2c set of system.sysContact.0 with NULL varbind |
| 93 | + |
| 94 | +SKIPIF NETSNMP_DISABLE_SET_SUPPORT |
| 95 | +SKIPIF NETSNMP_NO_WRITE_SUPPORT |
| 96 | +SKIPIF NETSNMP_DISABLE_SNMPV2C |
| 97 | +SKIPIFNOT USING_MIBII_SYSTEM_MIB_MODULE |
| 98 | + |
| 99 | +# |
| 100 | +# Begin test |
| 101 | +# |
| 102 | + |
| 103 | +# standard V2C configuration: testcomunnity |
| 104 | +snmp_write_access='all' |
| 105 | +. ./Sv2cconfig |
| 106 | +STARTAGENT |
| 107 | + |
| 108 | +CAPTURE "snmpget -On $SNMP_FLAGS -c testcommunity -v 2c $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT .1.3.6.1.2.1.1.4.0" |
| 109 | + |
| 110 | +CHECK ".1.3.6.1.2.1.1.4.0 = STRING:" |
| 111 | + |
| 112 | +CAPTURE "snmpset -On $SNMP_FLAGS -c testcommunity -v 2c $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT .1.3.6.1.2.1.1.4.0 n x" |
| 113 | + |
| 114 | +CHECK "Reason: wrongType" |
| 115 | + |
| 116 | +STOPAGENT |
| 117 | + |
| 118 | +FINISHED |
| 119 | -- |
| 120 | 2.34.1 |
| 121 | |