]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
CVE-2022-32742: s3: smbd: Harden the smbreq_bufrem() macro.
authorJeremy Allison <jra@samba.org>
Tue, 7 Jun 2022 16:53:08 +0000 (09:53 -0700)
committerJule Anger <janger@samba.org>
Wed, 27 Jul 2022 11:46:46 +0000 (11:46 +0000)
Fixes the raw.write.bad-write test.

NB. We need the two (==0) changes in source3/smbd/smb2_reply.c
as the gcc optimizer now knows that the return from
smbreq_bufrem() can never be less than zero.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15085

Remove knownfail.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
Autobuild-User(master): Jule Anger <janger@samba.org>
Autobuild-Date(master): Wed Jul 27 11:46:46 UTC 2022 on sn-devel-184

selftest/knownfail.d/bad-write [deleted file]
source3/include/smb_macros.h
source3/smbd/smb2_reply.c

diff --git a/selftest/knownfail.d/bad-write b/selftest/knownfail.d/bad-write
deleted file mode 100644 (file)
index 5fc1660..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-^samba3.raw.write.bad-write\(nt4_dc_smb1\)
-^samba3.raw.write.bad-write\(ad_dc_smb1\)
index 85ef221ed183a653cc644d0452c6770e61e7ff23..8271dbddfce26493e4d6dc0e8cb6af24ebfd6936 100644 (file)
 #define smb_buflen(buf) (SVAL(buf,smb_vwv0 + (int)CVAL(buf, smb_wct)*2))
 
 /* the remaining number of bytes in smb buffer 'buf' from pointer 'p'. */
-#define smbreq_bufrem(req, p) (req->buflen - PTR_DIFF(p, req->buf))
+#define smbreq_bufrem(req, p) ((req)->buflen < PTR_DIFF((p), (req)->buf) ? 0 : (req)->buflen - PTR_DIFF((p), (req)->buf))
 
 
 /* Note that chain_size must be available as an extern int to this macro. */
index 673c1e2216b70566a7321e0e0dfe73eb660866d1..bf9920259582fc1213345b681367e0a2c64525de 100644 (file)
@@ -344,7 +344,7 @@ size_t srvstr_get_path_req(TALLOC_CTX *mem_ctx, struct smb_request *req,
 {
        ssize_t bufrem = smbreq_bufrem(req, src);
 
-       if (bufrem < 0) {
+       if (bufrem == 0) {
                *err = NT_STATUS_INVALID_PARAMETER;
                return 0;
        }
@@ -382,7 +382,7 @@ size_t srvstr_pull_req_talloc(TALLOC_CTX *ctx, struct smb_request *req,
 {
        ssize_t bufrem = smbreq_bufrem(req, src);
 
-       if (bufrem < 0) {
+       if (bufrem == 0) {
                return 0;
        }