Skip to contentSkip to conversation

cifs: fix error handling cifs_user_readv

PATCH Applied Jeff Layton 2 participants 2 messages Apr 15, 2014 – Apr 17, 2014 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix error handling cifs_user_readv

Coverity says:

*** CID 1202537: Dereference after null check (FORWARD_NULL) /fs/cifs/file.c: 2873 in cifs_user_readv()
2867 cur_len = min_t(const size_t, len - total_read, cifs_sb->rsize);
2868 npages = DIV_ROUND_UP(cur_len, PAGE_SIZE);
2869

2870     		/* allocate a readdata struct */
2871     		rdata = cifs_readdata_alloc(npages,
2872     					    cifs_uncached_readv_complete);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1202537: Dereference after null check (FORWARD_NULL) Comparing "rdata" to null implies that "rdata" might be null.

2873     		if (!rdata) {
2874     			rc = -ENOMEM;
2875     			goto error;
2876     		}

2877
2878 rc = cifs_read_allocate_pages(rdata, npages);

...when we "goto error", rc will be non-zero, and then we end up trying to do a kref_put on the rdata (which is NULL). Fix this by replacing the "goto error" with a "break".

---
 fs/cifs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/file.c +1 -1
index 8616256cb93f..325b74798ef3 100644
@@ -2872,7 +2872,7 @@ ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov,
 					    cifs_uncached_readv_complete);
 		if (!rdata) {
 			rc = -ENOMEM;
-			goto error;
+			break;
 		}
 
 		rc = cifs_read_allocate_pages(rdata, npages);
Signature · 1 line
1.9.0

A message that is not in the archive (sent off-list or not yet received): 1397580529-3305-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

Applied
#2 lore raw

merged into cifs-2.6.git

Quoted 45 lines · Jeff Layton

Coverity says:

*** CID 1202537: Dereference after null check (FORWARD_NULL) /fs/cifs/file.c: 2873 in cifs_user_readv()
2867 cur_len = min_t(const size_t, len - total_read, cifs_sb->rsize);
2868 npages = DIV_ROUND_UP(cur_len, PAGE_SIZE);
2869
2870 /* allocate a readdata struct */
2871 rdata = cifs_readdata_alloc(npages,
2872 cifs_uncached_readv_complete);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1202537: Dereference after null check (FORWARD_NULL) Comparing "rdata" to null implies that "rdata" might be null.

2873 if (!rdata) {
2874 rc = -ENOMEM;
2875 goto error;
2876 }
2877
2878 rc = cifs_read_allocate_pages(rdata, npages);

...when we "goto error", rc will be non-zero, and then we end up trying to do a kref_put on the rdata (which is NULL). Fix this by replacing the "goto error" with a "break".

---
 fs/cifs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/file.c +1 -2
index 8616256cb93f..325b74798ef3 100644
@@ -2872,7 +2872,7 @@ ssize_t cifs_user_readv(struct kiocb *iocb, const struct iovec *iov,
                                            cifs_uncached_readv_complete);
                if (!rdata) {
                        rc = -ENOMEM;
-                       goto error;
+                       break;
                }
 
                rc = cifs_read_allocate_pages(rdata, npages);
--

1.9.0

Signature · 3 lines
Thanks,

Steve