Whamcloud - gitweb
LU-11894 lnet: check for asymmetrical route messages 19/34119/4
authorSebastien Buisson <sbuisson@ddn.com>
Mon, 28 Jan 2019 15:16:42 +0000 (00:16 +0900)
committerOleg Drokin <green@whamcloud.com>
Sun, 3 Mar 2019 00:21:30 +0000 (00:21 +0000)
Asymmetrical routes can be an issue when debugging network,
and allowing them also opens the door to attacks where hostile
clients inject data to the servers.

In order to prevent asymmetrical routes, add a new lnet kernel
module option named 'lnet_drop_asym_route'. When set to non-zero,
lnet_parse() will check if the message received from a remote peer
is coming through a router that would normally be used by this node
to reach the remote peer. If it is not the case, then it means we
are dealing with an asymmetrical route message, and the message will
be dropped.

The check for asymmetrical route can also be switched on/off with
the command 'lnetctl set drop_asym_route 0|1'. And this parameter is
exported/imported in Yaml.

Signed-off-by: Sebastien Buisson <sbuisson@ddn.com>
Change-Id: I06fb23d9e46984d79c14fa9b53b2fa04ce3c50c5
Reviewed-on: https://review.whamcloud.com/34119
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Olaf Weber <olaf.weber@hpe.com>
Reviewed-by: Chris Horn <hornc@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/include/lnet/lib-lnet.h
lnet/lnet/api-ni.c
lnet/lnet/lib-move.c
lnet/utils/lnetconfig/liblnetconfig.c
lnet/utils/lnetconfig/liblnetconfig.h
lnet/utils/lnetctl.c
lustre/doc/lnetctl.8

index 8bca9f2..473610c 100644 (file)
@@ -561,6 +561,7 @@ extern unsigned int lnet_numa_range;
 extern unsigned int lnet_health_sensitivity;
 extern unsigned int lnet_recovery_interval;
 extern unsigned int lnet_peer_discovery_disabled;
+extern unsigned int lnet_drop_asym_route;
 extern int portal_rotor;
 
 int lnet_notify(struct lnet_ni *ni, lnet_nid_t peer, int alive,
index 55d2779..186be3d 100644 (file)
@@ -160,6 +160,25 @@ module_param_call(lnet_peer_discovery_disabled, discovery_set, param_get_int,
 MODULE_PARM_DESC(lnet_peer_discovery_disabled,
                "Set to 1 to disable peer discovery on this node.");
 
+unsigned int lnet_drop_asym_route;
+static int drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp);
+
+static struct kernel_param_ops param_ops_drop_asym_route = {
+       .set = drop_asym_route_set,
+       .get = param_get_int,
+};
+
+#define param_check_drop_asym_route(name, p)   \
+       __param_check(name, p, int)
+#ifdef HAVE_KERNEL_PARAM_OPS
+module_param(lnet_drop_asym_route, drop_asym_route, 0644);
+#else
+module_param_call(lnet_drop_asym_route, drop_asym_route_set, param_get_int,
+                 &param_ops_drop_asym_route, 0644);
+#endif
+MODULE_PARM_DESC(lnet_drop_asym_route,
+                "Set to 1 to drop asymmetrical route messages.");
+
 unsigned lnet_transaction_timeout = 50;
 static int transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp);
 #ifdef HAVE_KERNEL_PARAM_OPS
@@ -339,6 +358,38 @@ discovery_set(const char *val, cfs_kernel_param_arg_t *kp)
 }
 
 static int
+drop_asym_route_set(const char *val, cfs_kernel_param_arg_t *kp)
+{
+       int rc;
+       unsigned int *drop_asym_route = (unsigned int *)kp->arg;
+       unsigned long value;
+
+       rc = kstrtoul(val, 0, &value);
+       if (rc) {
+               CERROR("Invalid module parameter value for "
+                      "'lnet_drop_asym_route'\n");
+               return rc;
+       }
+
+       /*
+        * The purpose of locking the api_mutex here is to ensure that
+        * the correct value ends up stored properly.
+        */
+       mutex_lock(&the_lnet.ln_api_mutex);
+
+       if (value == *drop_asym_route) {
+               mutex_unlock(&the_lnet.ln_api_mutex);
+               return 0;
+       }
+
+       *drop_asym_route = value;
+
+       mutex_unlock(&the_lnet.ln_api_mutex);
+
+       return 0;
+}
+
+static int
 transaction_to_set(const char *val, cfs_kernel_param_arg_t *kp)
 {
        int rc;
index fafb6d4..41ab43a 100644 (file)
@@ -4223,6 +4223,52 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
                goto drop;
        }
 
+       if (lnet_drop_asym_route && for_me &&
+           LNET_NIDNET(src_nid) != LNET_NIDNET(from_nid)) {
+               struct lnet_net *net;
+               struct lnet_remotenet *rnet;
+               bool found = true;
+
+               /* we are dealing with a routed message,
+                * so see if route to reach src_nid goes through from_nid
+                */
+               lnet_net_lock(cpt);
+               net = lnet_get_net_locked(LNET_NIDNET(ni->ni_nid));
+               if (!net) {
+                       lnet_net_unlock(cpt);
+                       CERROR("net %s not found\n",
+                              libcfs_net2str(LNET_NIDNET(ni->ni_nid)));
+                       return -EPROTO;
+               }
+
+               rnet = lnet_find_rnet_locked(LNET_NIDNET(src_nid));
+               if (rnet) {
+                       struct lnet_peer_ni *gw = NULL;
+                       struct lnet_route *route;
+
+                       list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
+                               found = false;
+                               gw = route->lr_gateway;
+                               if (gw->lpni_net != net)
+                                       continue;
+                               if (gw->lpni_nid == from_nid) {
+                                       found = true;
+                                       break;
+                               }
+                       }
+               }
+               lnet_net_unlock(cpt);
+               if (!found) {
+                       /* we would not use from_nid to route a message to
+                        * src_nid
+                        * => asymmetric routing detected but forbidden
+                        */
+                       CERROR("%s, src %s: Dropping asymmetrical route %s\n",
+                              libcfs_nid2str(from_nid),
+                              libcfs_nid2str(src_nid), lnet_msgtyp2str(type));
+                       goto drop;
+               }
+       }
 
        msg = lnet_msg_alloc();
        if (msg == NULL) {
index a194ce0..a0db4ae 100644 (file)
@@ -2662,6 +2662,31 @@ int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc)
 
 }
 
+int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
+                                      struct cYAML **err_rc)
+{
+       int rc = LUSTRE_CFG_RC_NO_ERR;
+       char err_str[LNET_MAX_STR_LEN];
+       char val[LNET_MAX_STR_LEN];
+
+       snprintf(err_str, sizeof(err_str), "\"success\"");
+
+       snprintf(val, sizeof(val), "%u", (drop) ? 1 : 0);
+
+       rc = write_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
+                             1, strlen(val) + 1);
+       if (rc)
+               snprintf(err_str, sizeof(err_str),
+                        "\"cannot configure drop asym route: %s\"",
+                        strerror(errno));
+
+       cYAML_build_error(rc, seq_no, ADD_CMD, "drop_asym_route",
+                         err_str, err_rc);
+
+       return rc;
+
+}
+
 int lustre_lnet_config_numa_range(int range, int seq_no, struct cYAML **err_rc)
 {
        return ioctl_set_value(range, IOC_LIBCFS_SET_NUMA_RANGE,
@@ -3646,6 +3671,31 @@ int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
                                       err_rc, l_errno);
 }
 
+int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
+                                    struct cYAML **err_rc)
+{
+       int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
+       char val[LNET_MAX_STR_LEN];
+       int drop_asym_route = -1, l_errno = 0;
+       char err_str[LNET_MAX_STR_LEN];
+
+       snprintf(err_str, sizeof(err_str), "\"out of memory\"");
+
+       rc = read_sysfs_file(modparam_path, "lnet_drop_asym_route", val,
+                            1, sizeof(val));
+       if (rc) {
+               l_errno = -errno;
+               snprintf(err_str, sizeof(err_str),
+                        "\"cannot get drop asym route setting: %d\"", rc);
+       } else {
+               drop_asym_route = atoi(val);
+       }
+
+       return build_global_yaml_entry(err_str, sizeof(err_str), seq_no,
+                                      "drop_asym_route", drop_asym_route,
+                                      show_rc, err_rc, l_errno);
+}
+
 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
                                struct cYAML **err_rc)
 {
@@ -4559,7 +4609,7 @@ static int handle_yaml_config_global_settings(struct cYAML *tree,
                                              struct cYAML **err_rc)
 {
        struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
-                    *sen, *recov;
+                    *sen, *recov, *drop_asym_route;
        int rc = 0;
 
        seq_no = cYAML_get_object_item(tree, "seq_no");
@@ -4584,6 +4634,13 @@ static int handle_yaml_config_global_settings(struct cYAML *tree,
                                                        : -1,
                                                  err_rc);
 
+       drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
+       if (drop_asym_route)
+               rc = lustre_lnet_config_drop_asym_route(
+                       drop_asym_route->cy_valueint,
+                       seq_no ? seq_no->cy_valueint : -1,
+                       err_rc);
+
        retry = cYAML_get_object_item(tree, "retry_count");
        if (retry)
                rc = lustre_lnet_config_retry_count(retry->cy_valueint,
@@ -4619,7 +4676,7 @@ static int handle_yaml_del_global_settings(struct cYAML *tree,
                                           struct cYAML **show_rc,
                                           struct cYAML **err_rc)
 {
-       struct cYAML *max_intf, *numa, *discovery, *seq_no;
+       struct cYAML *max_intf, *numa, *discovery, *seq_no, *drop_asym_route;
        int rc = 0;
 
        seq_no = cYAML_get_object_item(tree, "seq_no");
@@ -4645,6 +4702,12 @@ static int handle_yaml_del_global_settings(struct cYAML *tree,
                                                        : -1,
                                                  err_rc);
 
+       /* asymmetrical route messages are accepted by default */
+       drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
+       if (drop_asym_route)
+               rc = lustre_lnet_config_drop_asym_route(
+                       0, seq_no ? seq_no->cy_valueint : -1, err_rc);
+
        return rc;
 }
 
@@ -4653,7 +4716,7 @@ static int handle_yaml_show_global_settings(struct cYAML *tree,
                                            struct cYAML **err_rc)
 {
        struct cYAML *max_intf, *numa, *discovery, *retry, *tto, *seq_no,
-                    *sen, *recov;
+                    *sen, *recov, *drop_asym_route;
        int rc = 0;
 
        seq_no = cYAML_get_object_item(tree, "seq_no");
@@ -4675,6 +4738,12 @@ static int handle_yaml_show_global_settings(struct cYAML *tree,
                                                        : -1,
                                                show_rc, err_rc);
 
+       drop_asym_route = cYAML_get_object_item(tree, "drop_asym_route");
+       if (drop_asym_route)
+               rc = lustre_lnet_show_drop_asym_route(
+                       seq_no ? seq_no->cy_valueint : -1,
+                       show_rc, err_rc);
+
        retry = cYAML_get_object_item(tree, "retry_count");
        if (retry)
                rc = lustre_lnet_show_retry_count(seq_no ? seq_no->cy_valueint
index 504b797..8a5e6ac 100644 (file)
@@ -403,6 +403,30 @@ int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
                               struct cYAML **err_rc);
 
 /*
+ * lustre_lnet_config_drop_asym_route
+ *   Drop or accept asymmetrical route messages. Accept by default.
+ *
+ *   drop - non-0 drops, 0 accepts
+ *   seq_no - sequence number of the request
+ *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
+ *   caller
+ */
+int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
+                                      struct cYAML **err_rc);
+
+/*
+ * lustre_lnet_show_drop_asym_route
+ *    show current drop asym route setting
+ *
+ *   seq_no - sequence number of the request
+ *   show_rc - [OUT] struct cYAML tree containing NUMA range info
+ *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
+ *   caller
+ */
+int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
+                                    struct cYAML **err_rc);
+
+/*
  * lustre_lnet_config_buffers
  *   Send down an IOCTL to configure routing buffer sizes.  A value of 0 means
  *   default that particular buffer to default size. A value of -1 means
index 504e189..c503223 100644 (file)
@@ -62,6 +62,7 @@ static int jt_add_peer_nid(int argc, char **argv);
 static int jt_del_peer_nid(int argc, char **argv);
 static int jt_set_max_intf(int argc, char **argv);
 static int jt_set_discovery(int argc, char **argv);
+static int jt_set_drop_asym_route(int argc, char **argv);
 static int jt_list_peer(int argc, char **argv);
 /*static int jt_show_peer(int argc, char **argv);*/
 static int lnetctl_list_commands(int argc, char **argv);
@@ -193,6 +194,10 @@ command_t set_cmds[] = {
        {"discovery", jt_set_discovery, 0, "enable/disable peer discovery\n"
         "\t0 - disable peer discovery\n"
         "\t1 - enable peer discovery (default)\n"},
+       {"drop_asym_route", jt_set_drop_asym_route, 0,
+        "drop/accept asymmetrical route messages\n"
+        "\t0 - accept asymmetrical route messages (default)\n"
+        "\t1 - drop asymmetrical route messages\n"},
        {"retry_count", jt_set_retry_count, 0, "number of retries\n"
         "\t0 - turn of retries\n"
         "\t>0 - number of retries\n"},
@@ -501,6 +506,35 @@ static int jt_set_discovery(int argc, char **argv)
        return rc;
 }
 
+static int jt_set_drop_asym_route(int argc, char **argv)
+{
+       long int value;
+       int rc;
+       struct cYAML *err_rc = NULL;
+
+       rc = check_cmd(set_cmds, "set", "drop_asym_route", 2, argc, argv);
+       if (rc)
+               return rc;
+
+       rc = parse_long(argv[1], &value);
+       if (rc != 0) {
+               cYAML_build_error(-1, -1, "parser", "set",
+                                 "cannot parse drop_asym_route value",
+                                 &err_rc);
+               cYAML_print_tree2file(stderr, err_rc);
+               cYAML_free_tree(err_rc);
+               return -1;
+       }
+
+       rc = lustre_lnet_config_drop_asym_route(value, -1, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR)
+               cYAML_print_tree2file(stderr, err_rc);
+
+       cYAML_free_tree(err_rc);
+
+       return rc;
+}
+
 static int jt_set_tiny(int argc, char **argv)
 {
        long int value;
@@ -1235,6 +1269,12 @@ static int jt_show_global(int argc, char **argv)
                goto out;
        }
 
+       rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               goto out;
+       }
+
        rc = lustre_lnet_show_retry_count(-1, &show_rc, &err_rc);
        if (rc != LUSTRE_CFG_RC_NO_ERR) {
                cYAML_print_tree2file(stderr, err_rc);
@@ -1545,6 +1585,13 @@ static int jt_export(int argc, char **argv)
                err_rc = NULL;
        }
 
+       rc = lustre_lnet_show_drop_asym_route(-1, &show_rc, &err_rc);
+       if (rc != LUSTRE_CFG_RC_NO_ERR) {
+               cYAML_print_tree2file(stderr, err_rc);
+               cYAML_free_tree(err_rc);
+               err_rc = NULL;
+       }
+
        if (show_rc != NULL) {
                cYAML_print_tree2file(f, show_rc);
                cYAML_free_tree(show_rc);
index a1165da..401d03d 100644 (file)
@@ -245,6 +245,12 @@ When routing is disabled the values of the buffers that might have been changed
 are not remembered, and the next time routing is enabled the default buffer
 count will be used\.
 .
+.TP
+\fBlnetctl set\fR drop_asym_route \fI[0, 1]\fR
+0 value indicates to accept asymmetrical route messages\. 1 value indicates to
+drop them\. Asymmetrical route is when a message from a remote peer is coming
+through a router that would not be used by this node to reach the remote peer\.
+.
 .SS "Import and Export YAML Configuration Files"
 LNet configuration can be represented in YAML format\. A YAML configuration
 file can be passed to the lnetctl utility via the \fBimport\fR command\. The