lustre/mdc_lib: fix possible null pointer dereference
PATCH 1/2 lustre/mdc_lib: fix possible null pointer dereference
From: "Maxin B. John" <[email protected]>
cppcheck reported possible null pointer dereference in mdc_lib.c
[lustre/lustre/mdc/mdc_lib.c:233]: (error) Possible null pointer dereference : op_data - otherwise it is redundant to check if op_data is null at line 226
--- drivers/staging/lustre/lustre/mdc/mdc_lib.c | 41 ++++++++++++++------------- 1 file changed, 21 insertions(+), 20 deletions(-)
drivers/staging/lustre/lustre/mdc/mdc_lib.c +21 -20
@@ -223,29 +223,30 @@ void mdc_open_pack(struct ptlrpc_request *req, struct md_op_data *op_data, rec->cr_fsuid =from_kuid (&init_user_ns,current_fsuid ()); rec->cr_fsgid =from_kgid (&init_user_ns,current_fsgid ()); rec->cr_cap =cfs_curproc_cap_pack (); +if (op_data !=NULL ) { rec->cr_fid1 = op_data->op_fid1; rec->cr_fid2 = op_data->op_fid2; - } - rec->cr_mode = mode; - cr_flags =mds_pack_open_flags (flags, mode); - rec->cr_rdev = rdev; - rec->cr_time = op_data->op_mod_time; - rec->cr_suppgid1 = op_data->op_suppgids[0 ]; - rec->cr_suppgid2 = op_data->op_suppgids[1 ]; - rec->cr_bias = op_data->op_bias; - rec->cr_umask =current_umask (); - rec->cr_old_handle = op_data->op_handle; - -mdc_pack_capa (req, &RMF_CAPA1 , op_data->op_capa1); -/* the next buffer is child capa, which is used for replay, -* will be packed from the data in reply message. */ - -if (op_data->op_name) { - tmp =req_capsule_client_get (&req->rq_pill, &RMF_NAME ); -LOGL0 (op_data->op_name, op_data->op_namelen, tmp); -if (op_data->op_bias &MDS_CREATE_VOLATILE ) - cr_flags |=MDS_OPEN_VOLATILE ; + rec->cr_mode = mode; + cr_flags =mds_pack_open_flags (flags, mode); + rec->cr_rdev = rdev; + rec->cr_time = op_data->op_mod_time; + rec->cr_suppgid1 = op_data->op_suppgids[0 ]; + rec->cr_suppgid2 = op_data->op_suppgids[1 ]; + rec->cr_bias = op_data->op_bias; + rec->cr_umask =current_umask (); + rec->cr_old_handle = op_data->op_handle; + +mdc_pack_capa (req, &RMF_CAPA1 , op_data->op_capa1); +/* the next buffer is child capa, which is used for replay, +* will be packed from the data in reply message. */ + +if (op_data->op_name) { + tmp =req_capsule_client_get (&req->rq_pill, &RMF_NAME ); +LOGL0 (op_data->op_name, op_data->op_namelen, tmp); +if (op_data->op_bias &MDS_CREATE_VOLATILE ) + cr_flags |=MDS_OPEN_VOLATILE ; + } }if (lmm) {
Signature · 1 line
1.7.10.4
PATCH 2/2 lustre/lov_obd: fix possible null pointer dereference
From: "Maxin B. John" <[email protected]>
osc_obd can be NULL. cppcheck reported this:
[lustre/lustre/lov/lov_obd.c:283]: (error) Possible null pointer dereference:osc_obd - otherwise it is redundant to check if osc_obd is null at line 295
--- drivers/staging/lustre/lustre/lov/lov_obd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/lov/lov_obd.c +5 -4
@@ -279,8 +279,6 @@ static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)int rc; osc_obd =class_exp2obd (tgt->ltd_exp); -CDEBUG (D_CONFIG ,"%s: disconnecting target %s\n" , - obd->obd_name, osc_obd->obd_name);if (tgt->ltd_active) { tgt->ltd_active =0 ;
@@ -289,14 +287,17 @@ static int lov_disconnect_obd(struct obd_device *obd, struct lov_tgt_desc *tgt) } lov_proc_dir = obd->obd_proc_private; -if (lov_proc_dir) -lprocfs_remove_proc_entry (osc_obd->obd_name, lov_proc_dir);if (osc_obd) {/* Pass it on to our clients. * XXX This should be an argument to disconnect, * XXX not a back-door flag on the OBD. Ah well. */ +CDEBUG (D_CONFIG ,"%s: disconnecting target %s\n" , + obd->obd_name, osc_obd->obd_name); +if (lov_proc_dir) +lprocfs_remove_proc_entry (osc_obd->obd_name, + lov_proc_dir); osc_obd->obd_force = obd->obd_force; osc_obd->obd_fail = obd->obd_fail; osc_obd->obd_no_recov = obd->obd_no_recov;
Signature · 1 line
1.7.10.4
Greg KH
maintainerRe: [PATCH 2/2] lustre/lov_obd: fix possible null pointer dereference
Quoted 5 lines · Maxin B. John
From: "Maxin B. John" <[email protected]>
osc_obdcan be NULL. cppcheck reported this:
[lustre/lustre/lov/lov_obd.c:283]: (error) Possible null pointer dereference:osc_obd- otherwise it is redundant to check ifosc_obdis null at line 295
Same problem, osc_obd can never be NULL, please be more careful with your patches, and just remove pointless tests instead of papering over them with patches like this.
thanks.
greg k-h
Quoted 7 lines · Maxin B. John
From: "Maxin B. John" <[email protected]>
cppcheck reported possible null pointer dereference in
mdc_lib.c[
lustre/lustre/mdc/mdc_lib.c:233]: (error) Possible null pointer dereference :op_data- otherwise it is redundant to check ifop_datais null at line 226
There is only one caller and "op_data" is not NULL.
regards,
dan carpenter
Greg KH
maintainerQuoted 10 lines · Dan Carpenter
Quoted 7 lines · Maxin B. John
From: "Maxin B. John" <[email protected]>
cppcheck reported possible null pointer dereference in
mdc_lib.c[
lustre/lustre/mdc/mdc_lib.c:233]: (error) Possible null pointer dereference :op_data- otherwise it is redundant to check ifop_datais null at line 226There is only one caller and "
op_data" is not NULL.
I agree, John, please fix your tools. Or check the result and fix the code so that there isn't false-positives (by not checking for NULL at all here...)
thanks,
greg k-h
Hi,
Quoted 10 lines · Greg KH
Quoted 9 lines · Dan Carpenter
Quoted 7 lines · Maxin B. John
From: "Maxin B. John" <[email protected]>
cppcheck reported possible null pointer dereference in
mdc_lib.c[
lustre/lustre/mdc/mdc_lib.c:233]: (error) Possible null pointer dereference :op_data- otherwise it is redundant to check ifop_datais null at line 226
Quoted 5 lines
Quoted 1 line
There is only one caller and "
op_data" is not NULL.I agree, John, please fix your tools. Or check the result and fix the code so that there isn't false-positives (by not checking for NULL at all here...)
Thanks to Dan and Greg for the comments. Will try my best to avoid these kind of mistakes in future.
Quoted 2 lines
thanks,
greg k-h
Best Regards,
Maxin