From f0e474c4d8257b01815dd23eba491d5c50c7379d Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 12 Jan 2020 05:37:34 +0000 Subject: [PATCH] iscsi-scst: Suppress multiple Coverity complaints Suppress several Coverity "tainted scalar" complaints and also two other false positive Coverity complaints. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8761 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/config.c | 24 ++++++++++++++++++++++++ iscsi-scst/kernel/iscsi.c | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/iscsi-scst/kernel/config.c b/iscsi-scst/kernel/config.c index 464274e45..f6c2628c3 100644 --- a/iscsi-scst/kernel/config.c +++ b/iscsi-scst/kernel/config.c @@ -241,6 +241,14 @@ static int del_session(void __user *ptr) goto out_free; } +#ifdef __COVERITY__ + /* To suppress a Coverity "tainted scalar" complaint. */ + if (info->initiator_name[sizeof(info->initiator_name) - 1]) { + err = -EINVAL; + goto out_free; + } +#endif + info->initiator_name[sizeof(info->initiator_name)-1] = '\0'; target = target_lookup_by_id(info->tid); @@ -322,6 +330,14 @@ static int iscsi_initiator_allowed(void __user *ptr) goto out; } +#ifdef __COVERITY__ + /* To suppress a Coverity "tainted scalar" complaint. */ + if (cinfo.full_initiator_name[sizeof(cinfo.full_initiator_name) - 1]) { + err = -EINVAL; + goto out_free; + } +#endif + cinfo.full_initiator_name[sizeof(cinfo.full_initiator_name)-1] = '\0'; target = target_lookup_by_id(cinfo.tid); @@ -735,6 +751,14 @@ static int add_target(void __user *ptr) } else uinfo = NULL; +#ifdef __COVERITY__ + /* To suppress a Coverity "tainted scalar" complaint (CID 344743). */ + if (info->attrs_num > 65536) { + err = -EINVAL; + goto out_free; + } +#endif + err = __add_target(info); if (uinfo != NULL) { diff --git a/iscsi-scst/kernel/iscsi.c b/iscsi-scst/kernel/iscsi.c index b211d6b4d..f187bf88b 100644 --- a/iscsi-scst/kernel/iscsi.c +++ b/iscsi-scst/kernel/iscsi.c @@ -335,6 +335,9 @@ static struct iscsi_cmnd *cmnd_alloc(struct iscsi_conn *conn, /* ToDo: __GFP_NOFAIL?? */ cmnd = kmem_cache_zalloc(iscsi_cmnd_cache, GFP_KERNEL|__GFP_NOFAIL); + /* Tell Coverity about __GFP_NOFAIL. */ + EXTRACHECKS_BUG_ON(cmnd == NULL); + iscsi_cmnd_init(conn, cmnd, parent); TRACE_DBG("conn %p, parent %p, cmnd %p", conn, parent, cmnd); @@ -1620,6 +1623,8 @@ static int cmnd_prepare_recv_pdu(struct iscsi_conn *conn, offset = 0; } + /* To suppress a false positive Coverity complaint. */ + EXTRACHECKS_BUG_ON(sg == &dummy_sg[0] && idx > 0); addr = page_address(sg_page(&sg[idx])); EXTRACHECKS_BUG_ON(addr == NULL); sg_len = sg[idx].offset + sg[idx].length - offset;