public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] afs: Use array3_size() helper in afs_extract_to_buf()
@ 2020-06-15 23:27 Gustavo A. R. Silva
  2020-06-16  1:09 ` David Howells
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2020-06-15 23:27 UTC (permalink / raw)
  To: David Howells; +Cc: linux-afs, linux-kernel, Gustavo A. R. Silva, Kees Cook

Use array3_size() helper instead of the open-coded version in
afs_extract_to_buf(). These sorts of multiplication factors need
to be wrapped in array3_size().

This issue was found with the help of Coccinelle and, audited and fixed
manually.

Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 fs/afs/cmservice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/afs/cmservice.c b/fs/afs/cmservice.c
index bef413818af7..4d086f9c829e 100644
--- a/fs/afs/cmservice.c
+++ b/fs/afs/cmservice.c
@@ -268,7 +268,7 @@ static int afs_deliver_cb_callback(struct afs_call *call)
 				       GFP_KERNEL);
 		if (!call->buffer)
 			return -ENOMEM;
-		afs_extract_to_buf(call, call->count * 3 * 4);
+		afs_extract_to_buf(call, array3_size(call->count, 3, 4));
 		call->unmarshall++;
 
 		/* Fall through */
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH][next] afs: Use array3_size() helper in afs_extract_to_buf()
  2020-06-15 23:27 [PATCH][next] afs: Use array3_size() helper in afs_extract_to_buf() Gustavo A. R. Silva
@ 2020-06-16  1:09 ` David Howells
  0 siblings, 0 replies; 2+ messages in thread
From: David Howells @ 2020-06-16  1:09 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: dhowells, linux-afs, linux-kernel, Gustavo A. R. Silva, Kees Cook

Gustavo A. R. Silva <gustavoars@kernel.org> wrote:

> Use array3_size() helper instead of the open-coded version in
> afs_extract_to_buf(). These sorts of multiplication factors need
> to be wrapped in array3_size().

For afs_deliver_cb_callback(), this adds redundant checking, as does the one
on the kmalloc() on the preceding line:

		call->buffer = kmalloc(array3_size(call->count, 3, 4),
				       GFP_KERNEL);
		if (!call->buffer)
			return -ENOMEM;

because directly above them is a range check:

		if (call->count > AFSCBMAX)
			return afs_protocol_error(call, afs_eproto_cb_fid_count);

limiting the array size to 50.

Further, note that it's *not* a 3D array.  3 * 4 is the element size and is
constant.  I've written it that way as the block is 3 XDR units, but the block
size is actually 12 bytes.

The one in the kmalloc() should also not be using array3_size() for the same
reason.

David


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-16  1:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-15 23:27 [PATCH][next] afs: Use array3_size() helper in afs_extract_to_buf() Gustavo A. R. Silva
2020-06-16  1:09 ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox