Fix an uninitialized read in smb3_qfs_tcon()
Subsystems (2)
Hi!
Attached find a patch that fixes another case where oparms.mode is uninitialized. This patch fixes it with a struct assignment, relying on the implicit initialization of unmentioned fields. Please note that the assignment does not explicitly mention "reconnect" anymore, relying on the implicit "false" value.
Is this kernel-style? Shall we just go through all of the oparms initializations, there are quite a few other cases that might have the mode uninitialized.
Regards,
Volker
From 848e2d42a731ed0612a5c5de188659b98734edce Mon Sep 17 00:00:00 2001
From: Volker Lendecke <[email protected]>
Date: Wed, 11 Jan 2023 12:37:58 +0100
Subject: [PATCH] cifs: Fix uninitialized memory read in smb3_qfs_tcon()
--- fs/cifs/smb2ops.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/cifs/smb2ops.c +7 -6
@@ -729,12 +729,13 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,struct cifs_fid fid;struct cached_fid *cfid =NULL ; - oparms.tcon = tcon; - oparms.desired_access =FILE_READ_ATTRIBUTES ; - oparms.disposition =FILE_OPEN ; - oparms.create_options =cifs_create_options (cifs_sb,0 ); - oparms.fid = &fid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .desired_access =FILE_READ_ATTRIBUTES , + .disposition =FILE_OPEN , + .create_options =cifs_create_options (cifs_sb,0 ), + .fid = &fid, + }; rc =open_cached_dir (xid, tcon,"" , cifs_sb, false, &cfid);if (rc ==0 )
Signature · 1 line
2.30.2
Hi Volker,
Quoted 5 lines · Volker Lendecke
Attached find a patch that fixes another case where oparms.mode is uninitialized. This patch fixes it with a struct assignment, relying on the implicit initialization of unmentioned fields. Please note that the assignment does not explicitly mention "reconnect" anymore, relying on the implicit "false" value.
OK - thanks.
Quoted 3 lines
Is this kernel-style? Shall we just go through all of the oparms initializations, there are quite a few other cases that might have the mode uninitialized.
Please go through all of them.
Perhaps initialise those structures as below
struct cifs_open_parms oparms = {};and then avoid any uninitialised data to be sent.
Patch looks good.
Am Thu, Feb 09, 2023 at 02:46:09PM -0300 schrieb Paulo Alcantara:
Quoted 1 line
Please go through all of them.
Attached. I've used an emacs macro, so I'm pretty convinced I did not change semantics, but this kind of sweeping change needs close review obviously.
Quoted 5 lines
Perhaps initialise those structures as below
struct cifs_open_parms oparms = {};and then avoid any uninitialised data to be sent.
For easier review I've not touched the variable declarations yet but only changed the initialization to use a struct init.
Quoted 1 line
Patch looks good.
Thanks,
Volker
From e1c035f8b7e2a989034af67a2b135fdd1c2d1bf7 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <[email protected]>
Date: Wed, 11 Jan 2023 12:37:58 +0100
Subject: [PATCH] cifs: Fix uninitialized memory reads for oparms.mode
Use a struct assignment with implicit member initialization
--- fs/cifs/cached_dir.c | 13 +-- fs/cifs/cifsacl.c | 34 ++++---- fs/cifs/cifssmb.c | 17 ++-- fs/cifs/dir.c | 19 ++-- fs/cifs/file.c | 35 ++++---- fs/cifs/inode.c | 53 +++++------ fs/cifs/link.c | 66 +++++++------- fs/cifs/smb1ops.c | 72 +++++++-------- fs/cifs/smb2inode.c | 17 ++-- fs/cifs/smb2ops.c | 204 +++++++++++++++++++++++-------------------- 10 files changed, 281 insertions(+), 249 deletions(-)
fs/cifs/cached_dir.c +7 -6
@@ -181,12 +181,13 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, rqst[0 ].rq_iov = open_iov; rqst[0 ].rq_nvec =SMB2_CREATE_IOV_SIZE ; - oparms.tcon = tcon; - oparms.create_options =cifs_create_options (cifs_sb,CREATE_NOT_FILE ); - oparms.desired_access =FILE_READ_ATTRIBUTES ; - oparms.disposition =FILE_OPEN ; - oparms.fid = pfid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .create_options =cifs_create_options (cifs_sb,CREATE_NOT_FILE ), + .desired_access =FILE_READ_ATTRIBUTES , + .disposition =FILE_OPEN , + .fid = pfid, + }; rc =SMB2_open_init (tcon, server, &rqst[0 ], &oplock, &oparms, utf16_path);
fs/cifs/cifsacl.c +18 -16
@@ -1428,14 +1428,15 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, tcon =tlink_tcon (tlink); xid =get_xid (); - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access =READ_CONTROL ; - oparms.create_options =cifs_create_options (cifs_sb,0 ); - oparms.disposition =FILE_OPEN ; - oparms.path = path; - oparms.fid = &fid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access =READ_CONTROL , + .create_options =cifs_create_options (cifs_sb,0 ), + .disposition =FILE_OPEN , + .path = path, + .fid = &fid, + }; rc =CIFS_open (xid, &oparms, &oplock,NULL );if (!rc) {
@@ -1494,14 +1495,15 @@ int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,else access_flags =WRITE_DAC ; - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access = access_flags; - oparms.create_options =cifs_create_options (cifs_sb,0 ); - oparms.disposition =FILE_OPEN ; - oparms.path = path; - oparms.fid = &fid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access = access_flags, + .create_options =cifs_create_options (cifs_sb,0 ), + .disposition =FILE_OPEN , + .path = path, + .fid = &fid, + }; rc =CIFS_open (xid, &oparms, &oplock,NULL );if (rc) {
fs/cifs/cifssmb.c +9 -8
@@ -5372,14 +5372,15 @@ CIFSSMBSetPathInfoFB(const unsigned int xid, struct cifs_tcon *tcon,struct cifs_fid fid;int rc; - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access =GENERIC_WRITE ; - oparms.create_options =cifs_create_options (cifs_sb,0 ); - oparms.disposition =FILE_OPEN ; - oparms.path = fileName; - oparms.fid = &fid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access =GENERIC_WRITE , + .create_options =cifs_create_options (cifs_sb,0 ), + .disposition =FILE_OPEN , + .path = fileName, + .fid = &fid, + }; rc =CIFS_open (xid, &oparms, &oplock,NULL );if (rc)
fs/cifs/dir.c +10 -9
@@ -304,15 +304,16 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry, unsignedif (!tcon->unix_ext && (mode &S_IWUGO ) ==0 ) create_options |=CREATE_OPTION_READONLY ; - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access = desired_access; - oparms.create_options =cifs_create_options (cifs_sb, create_options); - oparms.disposition = disposition; - oparms.path = full_path; - oparms.fid = fid; - oparms.reconnect = false; - oparms.mode = mode; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access = desired_access, + .create_options =cifs_create_options (cifs_sb, create_options), + .disposition = disposition, + .path = full_path, + .fid = fid, + .mode = mode, + }; rc = server->ops->open (xid, &oparms, oplock, buf);if (rc) {cifs_dbg (FYI ,"cifs_create returned 0x%x\n" , rc);
fs/cifs/file.c +19 -16
@@ -260,14 +260,15 @@ static int cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_if (f_flags &O_DIRECT ) create_options |=CREATE_NO_BUFFER ; - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access = desired_access; - oparms.create_options =cifs_create_options (cifs_sb, create_options); - oparms.disposition = disposition; - oparms.path = full_path; - oparms.fid = fid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access = desired_access, + .create_options =cifs_create_options (cifs_sb, create_options), + .disposition = disposition, + .path = full_path, + .fid = fid, + }; rc = server->ops->open (xid, &oparms, oplock, buf);if (rc)
@@ -848,14 +849,16 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)if (server->ops->get_lease_key) server->ops->get_lease_key (inode, &cfile->fid); - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access = desired_access; - oparms.create_options =cifs_create_options (cifs_sb, create_options); - oparms.disposition = disposition; - oparms.path = full_path; - oparms.fid = &cfile->fid; - oparms.reconnect = true; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access = desired_access, + .create_options =cifs_create_options (cifs_sb, create_options), + .disposition = disposition, + .path = full_path, + .fid = &cfile->fid, + .reconnect = true, + };/* * Can not refresh inode by passing in file_info buf to be returned by
fs/cifs/inode.c +28 -25
71 lines not on this page · raw message
fs/cifs/link.c +35 -31
90 lines not on this page · raw message
fs/cifs/smb1ops.c +38 -34
96 lines not on this page · raw message
fs/cifs/smb2inode.c +9 -8
@@ -105,14 +105,15 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, goto finished; } - vars->oparms.tcon = tcon; - vars->oparms.desired_access = desired_access; - vars->oparms.disposition = create_disposition; - vars->oparms.create_options =cifs_create_options (cifs_sb, create_options); - vars->oparms.fid = &fid; - vars->oparms.reconnect = false; - vars->oparms.mode = mode; - vars->oparms.cifs_sb = cifs_sb; + vars->oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .desired_access = desired_access, + .disposition = create_disposition, + .create_options =cifs_create_options (cifs_sb, create_options), + .fid = &fid, + .mode = mode, + .cifs_sb = cifs_sb, + }; rqst[num_rqst].rq_iov = &vars->open_iov[0 ]; rqst[num_rqst].rq_nvec =SMB2_CREATE_IOV_SIZE ;
fs/cifs/smb2ops.c +108 -96
288 lines not on this page · raw message
Signature · 1 line
2.30.2
Steve French
Appliedmerged into cifs-2.6.git for-next
Quoted 26 lines · Paulo Alcantara
Hi Volker,
Quoted 5 lines · Volker Lendecke
Attached find a patch that fixes another case where oparms.mode is uninitialized. This patch fixes it with a struct assignment, relying on the implicit initialization of unmentioned fields. Please note that the assignment does not explicitly mention "reconnect" anymore, relying on the implicit "false" value.
OK - thanks.
Quoted 3 lines
Is this kernel-style? Shall we just go through all of the oparms initializations, there are quite a few other cases that might have the mode uninitialized.
Please go through all of them.
Perhaps initialise those structures as below
struct cifs_open_parms oparms = {};and then avoid any uninitialised data to be sent.
Patch looks good.
Signature · 3 lines
Thanks, Steve
Am Thu, Feb 09, 2023 at 01:43:34PM -0600 schrieb Steve French:
Quoted 1 line
merged into cifs-2.6.git for-next
This was only the initial one. I have squashed all the other ones into my latter submission to this list. Do you want me to re-submit on top of for-next?
Thanks, Volker
A message that is not in the archive (sent off-list or not yet received): CAH2r5mvzVQKAT-a+MJ-qN=Ogn8PqNdMz=3zYntaq26UdgcY0Cg@mail.gmail.com
Am Fri, Feb 10, 2023 at 10:01:37PM -0600 schrieb Steve French:
Quoted 2 lines
Yes. On top of for next. They don't have to be squashed into one if it makes it harder to review.
Attached.
Volker
From 1da9f46cfa4d475b786873ee8e941155bf304f6d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <[email protected]>
Date: Wed, 11 Jan 2023 12:37:58 +0100
Subject: [PATCH] cifs: Fix uninitialized memory reads for oparms.mode
Use a struct assignment with implicit member initialization
--- fs/cifs/cached_dir.c | 13 +-- fs/cifs/cifsacl.c | 34 ++++---- fs/cifs/cifssmb.c | 17 ++-- fs/cifs/dir.c | 19 +++-- fs/cifs/file.c | 35 ++++---- fs/cifs/inode.c | 53 ++++++------ fs/cifs/link.c | 66 ++++++++------- fs/cifs/smb1ops.c | 72 ++++++++-------- fs/cifs/smb2inode.c | 17 ++-- fs/cifs/smb2ops.c | 191 +++++++++++++++++++++++-------------------- 10 files changed, 274 insertions(+), 243 deletions(-)
fs/cifs/cached_dir.c +7 -6
@@ -181,12 +181,13 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon, rqst[0 ].rq_iov = open_iov; rqst[0 ].rq_nvec =SMB2_CREATE_IOV_SIZE ; - oparms.tcon = tcon; - oparms.create_options =cifs_create_options (cifs_sb,CREATE_NOT_FILE ); - oparms.desired_access =FILE_READ_ATTRIBUTES ; - oparms.disposition =FILE_OPEN ; - oparms.fid = pfid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .create_options =cifs_create_options (cifs_sb,CREATE_NOT_FILE ), + .desired_access =FILE_READ_ATTRIBUTES , + .disposition =FILE_OPEN , + .fid = pfid, + }; rc =SMB2_open_init (tcon, server, &rqst[0 ], &oplock, &oparms, utf16_path);
fs/cifs/cifsacl.c +18 -16
@@ -1428,14 +1428,15 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, tcon =tlink_tcon (tlink); xid =get_xid (); - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access =READ_CONTROL ; - oparms.create_options =cifs_create_options (cifs_sb,0 ); - oparms.disposition =FILE_OPEN ; - oparms.path = path; - oparms.fid = &fid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access =READ_CONTROL , + .create_options =cifs_create_options (cifs_sb,0 ), + .disposition =FILE_OPEN , + .path = path, + .fid = &fid, + }; rc =CIFS_open (xid, &oparms, &oplock,NULL );if (!rc) {
@@ -1494,14 +1495,15 @@ int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,else access_flags =WRITE_DAC ; - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access = access_flags; - oparms.create_options =cifs_create_options (cifs_sb,0 ); - oparms.disposition =FILE_OPEN ; - oparms.path = path; - oparms.fid = &fid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access = access_flags, + .create_options =cifs_create_options (cifs_sb,0 ), + .disposition =FILE_OPEN , + .path = path, + .fid = &fid, + }; rc =CIFS_open (xid, &oparms, &oplock,NULL );if (rc) {
fs/cifs/cifssmb.c +9 -8
@@ -5372,14 +5372,15 @@ CIFSSMBSetPathInfoFB(const unsigned int xid, struct cifs_tcon *tcon,struct cifs_fid fid;int rc; - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access =GENERIC_WRITE ; - oparms.create_options =cifs_create_options (cifs_sb,0 ); - oparms.disposition =FILE_OPEN ; - oparms.path = fileName; - oparms.fid = &fid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access =GENERIC_WRITE , + .create_options =cifs_create_options (cifs_sb,0 ), + .disposition =FILE_OPEN , + .path = fileName, + .fid = &fid, + }; rc =CIFS_open (xid, &oparms, &oplock,NULL );if (rc)
fs/cifs/dir.c +10 -9
@@ -304,15 +304,16 @@ static int cifs_do_create(struct inode *inode, struct dentry *direntry, unsignedif (!tcon->unix_ext && (mode &S_IWUGO ) ==0 ) create_options |=CREATE_OPTION_READONLY ; - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access = desired_access; - oparms.create_options =cifs_create_options (cifs_sb, create_options); - oparms.disposition = disposition; - oparms.path = full_path; - oparms.fid = fid; - oparms.reconnect = false; - oparms.mode = mode; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access = desired_access, + .create_options =cifs_create_options (cifs_sb, create_options), + .disposition = disposition, + .path = full_path, + .fid = fid, + .mode = mode, + }; rc = server->ops->open (xid, &oparms, oplock, buf);if (rc) {cifs_dbg (FYI ,"cifs_create returned 0x%x\n" , rc);
fs/cifs/file.c +19 -16
@@ -260,14 +260,15 @@ static int cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_if (f_flags &O_DIRECT ) create_options |=CREATE_NO_BUFFER ; - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access = desired_access; - oparms.create_options =cifs_create_options (cifs_sb, create_options); - oparms.disposition = disposition; - oparms.path = full_path; - oparms.fid = fid; - oparms.reconnect = false; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access = desired_access, + .create_options =cifs_create_options (cifs_sb, create_options), + .disposition = disposition, + .path = full_path, + .fid = fid, + }; rc = server->ops->open (xid, &oparms, oplock, buf);if (rc)
@@ -848,14 +849,16 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)if (server->ops->get_lease_key) server->ops->get_lease_key (inode, &cfile->fid); - oparms.tcon = tcon; - oparms.cifs_sb = cifs_sb; - oparms.desired_access = desired_access; - oparms.create_options =cifs_create_options (cifs_sb, create_options); - oparms.disposition = disposition; - oparms.path = full_path; - oparms.fid = &cfile->fid; - oparms.reconnect = true; + oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .cifs_sb = cifs_sb, + .desired_access = desired_access, + .create_options =cifs_create_options (cifs_sb, create_options), + .disposition = disposition, + .path = full_path, + .fid = &cfile->fid, + .reconnect = true, + };/* * Can not refresh inode by passing in file_info buf to be returned by
fs/cifs/inode.c +28 -25
71 lines not on this page · raw message
fs/cifs/link.c +35 -31
90 lines not on this page · raw message
fs/cifs/smb1ops.c +38 -34
96 lines not on this page · raw message
fs/cifs/smb2inode.c +9 -8
@@ -105,14 +105,15 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, goto finished; } - vars->oparms.tcon = tcon; - vars->oparms.desired_access = desired_access; - vars->oparms.disposition = create_disposition; - vars->oparms.create_options =cifs_create_options (cifs_sb, create_options); - vars->oparms.fid = &fid; - vars->oparms.reconnect = false; - vars->oparms.mode = mode; - vars->oparms.cifs_sb = cifs_sb; + vars->oparms = (struct cifs_open_parms ) { + .tcon = tcon, + .desired_access = desired_access, + .disposition = create_disposition, + .create_options =cifs_create_options (cifs_sb, create_options), + .fid = &fid, + .mode = mode, + .cifs_sb = cifs_sb, + }; rqst[num_rqst].rq_iov = &vars->open_iov[0 ]; rqst[num_rqst].rq_nvec =SMB2_CREATE_IOV_SIZE ;
fs/cifs/smb2ops.c +101 -90
269 lines not on this page · raw message
Signature · 1 line
2.30.2
merged into cifs-2.6.git for-next (pending testing and any additional review)
Quoted 8 lines · Volker Lendecke
Am Fri, Feb 10, 2023 at 10:01:37PM -0600 schrieb Steve French:
Quoted 2 lines
Yes. On top of for next. They don't have to be squashed into one if it makes it harder to review.
Attached.
Volker
Signature · 3 lines
Thanks, Steve
also I added cc:stable (to this and to the followon related patch) ... let me know if any objections
Quoted 20 lines · Steve French
merged into cifs-2.6.git for-next (pending testing and any additional review)
Quoted 8 lines · Volker Lendecke
Am Fri, Feb 10, 2023 at 10:01:37PM -0600 schrieb Steve French:
Quoted 2 lines
Yes. On top of for next. They don't have to be squashed into one if it makes it harder to review.
Attached.
Volker
--
Thanks,Steve
Signature · 3 lines
Thanks, Steve
we also should probably go through all the places that we call SMB2_open_init - various compounded cases and make sure that we request leases when it makes sense (we are missing a few for directory leases e.g.)
Quoted 16 lines · Volker Lendecke
Hi!
Attached find a patch that fixes another case where oparms.mode is uninitialized. This patch fixes it with a struct assignment, relying on the implicit initialization of unmentioned fields. Please note that the assignment does not explicitly mention "reconnect" anymore, relying on the implicit "false" value.
Is this kernel-style? Shall we just go through all of the oparms initializations, there are quite a few other cases that might have the mode uninitialized.
Regards,
Volker
Signature · 3 lines
Thanks, Steve