Skip to content

Commit fcee292

Browse files
Dmitry Eremingregkh
authored andcommitted
staging: lustre: fix buffer overflow of string buffer
commit 9563fe8 upstream. Buffer overflow of string buffer due to non null terminated string. Use strlcpy() when it's justifiable. Use sizeof(var) instead of constants. Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com> Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-4629 Reviewed-on: http://review.whamcloud.com/9389 Reviewed-by: Andreas Dilger <andreas.dilger@intel.com> Reviewed-by: Oleg Drokin <oleg.drokin@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b48715d commit fcee292

13 files changed

Lines changed: 37 additions & 29 deletions

File tree

drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,8 +2621,8 @@ ksocknal_enumerate_interfaces(ksock_net_t *net)
26212621

26222622
net->ksnn_interfaces[j].ksni_ipaddr = ip;
26232623
net->ksnn_interfaces[j].ksni_netmask = mask;
2624-
strncpy(&net->ksnn_interfaces[j].ksni_name[0],
2625-
names[i], IFNAMSIZ);
2624+
strlcpy(net->ksnn_interfaces[j].ksni_name,
2625+
names[i], sizeof(net->ksnn_interfaces[j].ksni_name));
26262626
j++;
26272627
}
26282628

@@ -2805,8 +2805,9 @@ ksocknal_startup(lnet_ni_t *ni)
28052805
goto fail_1;
28062806
}
28072807

2808-
strncpy(&net->ksnn_interfaces[i].ksni_name[0],
2809-
ni->ni_interfaces[i], IFNAMSIZ);
2808+
strlcpy(net->ksnn_interfaces[i].ksni_name,
2809+
ni->ni_interfaces[i],
2810+
sizeof(net->ksnn_interfaces[i].ksni_name));
28102811
}
28112812
net->ksnn_ninterfaces = i;
28122813
}

drivers/staging/lustre/lnet/lnet/config.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,8 @@ lnet_parse_route(char *str, int *im_a_router)
650650
INIT_LIST_HEAD(&nets);
651651

652652
/* save a copy of the string for error messages */
653-
strncpy(cmd, str, sizeof(cmd) - 1);
654-
cmd[sizeof(cmd) - 1] = 0;
653+
strncpy(cmd, str, sizeof(cmd));
654+
cmd[sizeof(cmd) - 1] = '\0';
655655

656656
sep = str;
657657
for (;;) {
@@ -972,11 +972,13 @@ lnet_splitnets(char *source, struct list_head *nets)
972972
return 0;
973973

974974
offset += (int)(sep - tb->ltb_text);
975-
tb2 = lnet_new_text_buf(strlen(sep));
975+
len = strlen(sep);
976+
tb2 = lnet_new_text_buf(len);
976977
if (tb2 == NULL)
977978
return -ENOMEM;
978979

979-
strcpy(tb2->ltb_text, sep);
980+
strncpy(tb2->ltb_text, sep, len);
981+
tb2->ltb_text[len] = '\0';
980982
list_add_tail(&tb2->ltb_list, nets);
981983

982984
tb = tb2;
@@ -1021,8 +1023,8 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
10211023
tb = list_entry(raw_entries.next, struct lnet_text_buf_t,
10221024
ltb_list);
10231025

1024-
strncpy(source, tb->ltb_text, sizeof(source)-1);
1025-
source[sizeof(source)-1] = 0;
1026+
strncpy(source, tb->ltb_text, sizeof(source));
1027+
source[sizeof(source)-1] = '\0';
10261028

10271029
/* replace ltb_text with the network(s) add on match */
10281030
rc = lnet_match_network_tokens(tb->ltb_text, ipaddrs, nip);

drivers/staging/lustre/lnet/selftest/conrpc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ lstcon_sesrpc_prep(lstcon_node_t *nd, int transop,
612612
msrq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.mksn_reqst;
613613
msrq->mksn_sid = console_session.ses_id;
614614
msrq->mksn_force = console_session.ses_force;
615-
strncpy(msrq->mksn_name, console_session.ses_name,
616-
strlen(console_session.ses_name));
615+
strlcpy(msrq->mksn_name, console_session.ses_name,
616+
sizeof(msrq->mksn_name));
617617
break;
618618

619619
case LST_TRANS_SESEND:

drivers/staging/lustre/lnet/selftest/console.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,7 +1739,8 @@ lstcon_session_new(char *name, int key, unsigned feats,
17391739
console_session.ses_feats_updated = 0;
17401740
console_session.ses_timeout = (timeout <= 0) ?
17411741
LST_CONSOLE_TIMEOUT : timeout;
1742-
strcpy(console_session.ses_name, name);
1742+
strlcpy(console_session.ses_name, name,
1743+
sizeof(console_session.ses_name));
17431744

17441745
rc = lstcon_batch_add(LST_DEFAULT_BATCH);
17451746
if (rc != 0)
@@ -1959,7 +1960,8 @@ lstcon_acceptor_handle(srpc_server_rpc_t *rpc)
19591960
if (grp->grp_userland == 0)
19601961
grp->grp_userland = 1;
19611962

1962-
strcpy(jrep->join_session, console_session.ses_name);
1963+
strlcpy(jrep->join_session, console_session.ses_name,
1964+
sizeof(jrep->join_session));
19631965
jrep->join_timeout = console_session.ses_timeout;
19641966
jrep->join_status = 0;
19651967

drivers/staging/lustre/lustre/include/lustre_disk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
everything as string options */
6969

7070
#define LMD_MAGIC 0xbdacbd03
71+
#define LMD_PARAMS_MAXLEN 4096
7172

7273
/* gleaned from the mount command - no persistent info here */
7374
struct lustre_mount_data {

drivers/staging/lustre/lustre/libcfs/debug.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,9 @@ int libcfs_debug_init(unsigned long bufsize)
512512
}
513513

514514
if (libcfs_debug_file_path != NULL) {
515-
strncpy(libcfs_debug_file_path_arr,
516-
libcfs_debug_file_path, PATH_MAX-1);
517-
libcfs_debug_file_path_arr[PATH_MAX - 1] = '\0';
515+
strlcpy(libcfs_debug_file_path_arr,
516+
libcfs_debug_file_path,
517+
sizeof(libcfs_debug_file_path_arr));
518518
}
519519

520520
/* If libcfs_debug_mb is set to an invalid value or uninitialized

drivers/staging/lustre/lustre/libcfs/hash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,7 @@ cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits,
10621062
if (hs == NULL)
10631063
return NULL;
10641064

1065-
strncpy(hs->hs_name, name, len);
1066-
hs->hs_name[len - 1] = '\0';
1065+
strlcpy(hs->hs_name, name, len);
10671066
hs->hs_flags = flags;
10681067

10691068
atomic_set(&hs->hs_refcount, 1);

drivers/staging/lustre/lustre/libcfs/workitem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ cfs_wi_sched_create(char *name, struct cfs_cpt_table *cptab,
360360
if (sched == NULL)
361361
return -ENOMEM;
362362

363-
strncpy(sched->ws_name, name, CFS_WS_NAME_LEN);
364-
sched->ws_name[CFS_WS_NAME_LEN - 1] = '\0';
363+
strlcpy(sched->ws_name, name, CFS_WS_NAME_LEN);
364+
365365
sched->ws_cptab = cptab;
366366
sched->ws_cpt = cpt;
367367

drivers/staging/lustre/lustre/llite/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static int ll_send_mgc_param(struct obd_export *mgc, char *string)
641641
if (!msp)
642642
return -ENOMEM;
643643

644-
strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
644+
strlcpy(msp->mgs_param, string, sizeof(msp->mgs_param));
645645
rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
646646
sizeof(struct mgs_send_param), msp, NULL);
647647
if (rc)

drivers/staging/lustre/lustre/lov/lov_pool.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ int lov_pool_new(struct obd_device *obd, char *poolname)
412412
if (!new_pool)
413413
return -ENOMEM;
414414

415-
strncpy(new_pool->pool_name, poolname, LOV_MAXPOOLNAME);
416-
new_pool->pool_name[LOV_MAXPOOLNAME] = '\0';
415+
strlcpy(new_pool->pool_name, poolname, sizeof(new_pool->pool_name));
417416
new_pool->pool_lobd = obd;
418417
/* ref count init to 1 because when created a pool is always used
419418
* up to deletion

0 commit comments

Comments
 (0)