From b5bc2f593d364bf173c13ef0cca9663db6019b69 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 21 Mar 2018 12:52:49 -0700 Subject: [PATCH] s3: smbd: SMB2: Add DBGC_SMB2_CREDITS class to specifically debug credit issues. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit https://bugzilla.samba.org/show_bug.cgi?id=13347 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Böhme (cherry picked from commit ad973fddef00d6d92443be89e7f5404006a94d99) --- lib/util/debug.c | 1 + lib/util/debug.h | 1 + source3/smbd/smb2_server.c | 48 +++++++++++++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/util/debug.c b/lib/util/debug.c index 47590403e1d..d010b724203 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -542,6 +542,7 @@ static const char *default_classname_table[] = { [DBGC_KERBEROS] = "kerberos", [DBGC_DRS_REPL] = "drs_repl", [DBGC_SMB2] = "smb2", + [DBGC_SMB2_CREDITS] = "smb2_credits", }; /* diff --git a/lib/util/debug.h b/lib/util/debug.h index 1b17fad9694..1e184b47de9 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -94,6 +94,7 @@ bool dbghdr( int level, const char *location, const char *func); #define DBGC_KERBEROS 26 #define DBGC_DRS_REPL 27 #define DBGC_SMB2 28 +#define DBGC_SMB2_CREDITS 29 /* So you can define DBGC_CLASS before including debug.h */ #ifndef DBGC_CLASS diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c index c44f9cda850..ee03a8eb0bb 100644 --- a/source3/smbd/smb2_server.c +++ b/source3/smbd/smb2_server.c @@ -616,34 +616,37 @@ static bool smb2_validate_sequence_number(struct smbXsrv_connection *xconn, seq_tmp = xconn->smb2.credits.seq_low; if (seq_id < seq_tmp) { - DEBUG(0,("smb2_validate_sequence_number: bad message_id " + DBGC_ERR(DBGC_SMB2_CREDITS, + "smb2_validate_sequence_number: bad message_id " "%llu (sequence id %llu) " "(granted = %u, low = %llu, range = %u)\n", (unsigned long long)message_id, (unsigned long long)seq_id, (unsigned int)xconn->smb2.credits.granted, (unsigned long long)xconn->smb2.credits.seq_low, - (unsigned int)xconn->smb2.credits.seq_range)); + (unsigned int)xconn->smb2.credits.seq_range); return false; } seq_tmp += xconn->smb2.credits.seq_range; if (seq_id >= seq_tmp) { - DEBUG(0,("smb2_validate_sequence_number: bad message_id " + DBGC_ERR(DBGC_SMB2_CREDITS, + "smb2_validate_sequence_number: bad message_id " "%llu (sequence id %llu) " "(granted = %u, low = %llu, range = %u)\n", (unsigned long long)message_id, (unsigned long long)seq_id, (unsigned int)xconn->smb2.credits.granted, (unsigned long long)xconn->smb2.credits.seq_low, - (unsigned int)xconn->smb2.credits.seq_range)); + (unsigned int)xconn->smb2.credits.seq_range); return false; } offset = seq_id % xconn->smb2.credits.max; if (bitmap_query(credits_bm, offset)) { - DEBUG(0,("smb2_validate_sequence_number: duplicate message_id " + DBGC_ERR(DBGC_SMB2_CREDITS, + "smb2_validate_sequence_number: duplicate message_id " "%llu (sequence id %llu) " "(granted = %u, low = %llu, range = %u) " "(bm offset %u)\n", @@ -652,7 +655,7 @@ static bool smb2_validate_sequence_number(struct smbXsrv_connection *xconn, (unsigned int)xconn->smb2.credits.granted, (unsigned long long)xconn->smb2.credits.seq_low, (unsigned int)xconn->smb2.credits.seq_range, - offset)); + offset); return false; } @@ -668,10 +671,11 @@ static bool smb2_validate_sequence_number(struct smbXsrv_connection *xconn, * already seen. */ while (bitmap_query(credits_bm, offset)) { - DEBUG(10,("smb2_validate_sequence_number: clearing " + DBGC_DEBUG(DBGC_SMB2_CREDITS, + "smb2_validate_sequence_number: clearing " "id %llu (position %u) from bitmap\n", (unsigned long long)(xconn->smb2.credits.seq_low), - offset)); + offset); bitmap_clear(credits_bm, offset); xconn->smb2.credits.seq_low += 1; @@ -700,7 +704,9 @@ static bool smb2_validate_message_id(struct smbXsrv_connection *xconn, credit_charge = MAX(credit_charge, 1); } - DEBUG(11, ("smb2_validate_message_id: mid %llu (charge %llu), " + DEBUGC(11, + DBGC_SMB2_CREDITS, + ("smb2_validate_message_id: mid %llu (charge %llu), " "credits_granted %llu, " "seqnum low/range: %llu/%llu\n", (unsigned long long) message_id, @@ -710,7 +716,8 @@ static bool smb2_validate_message_id(struct smbXsrv_connection *xconn, (unsigned long long) xconn->smb2.credits.seq_range)); if (xconn->smb2.credits.granted < credit_charge) { - DEBUG(0, ("smb2_validate_message_id: client used more " + DBGC_ERR(DBGC_SMB2_CREDITS, + "smb2_validate_message_id: client used more " "credits than granted, mid %llu, charge %llu, " "credits_granted %llu, " "seqnum low/range: %llu/%llu\n", @@ -718,7 +725,7 @@ static bool smb2_validate_message_id(struct smbXsrv_connection *xconn, (unsigned long long) credit_charge, (unsigned long long) xconn->smb2.credits.granted, (unsigned long long) xconn->smb2.credits.seq_low, - (unsigned long long) xconn->smb2.credits.seq_range)); + (unsigned long long) xconn->smb2.credits.seq_range); return false; } @@ -734,7 +741,9 @@ static bool smb2_validate_message_id(struct smbXsrv_connection *xconn, uint64_t id = message_id + i; bool ok; - DEBUG(11, ("Iterating mid %llu charge %u (sequence %llu)\n", + DEBUGC(11, + DBGC_SMB2_CREDITS, + ("Iterating mid %llu charge %u (sequence %llu)\n", (unsigned long long)message_id, credit_charge, (unsigned long long)id)); @@ -912,7 +921,8 @@ static void smb2_set_operation_credit(struct smbXsrv_connection *xconn, xconn->smb2.credits.granted += credits_granted; xconn->smb2.credits.seq_range += credits_granted; - DEBUG(10,("smb2_set_operation_credit: requested %u, charge %u, " + DBGC_DEBUG(DBGC_SMB2_CREDITS, + "smb2_set_operation_credit: requested %u, charge %u, " "granted %u, current possible/max %u/%u, " "total granted/max/low/range %u/%u/%llu/%u\n", (unsigned int)credits_requested, @@ -923,7 +933,7 @@ static void smb2_set_operation_credit(struct smbXsrv_connection *xconn, (unsigned int)xconn->smb2.credits.granted, (unsigned int)xconn->smb2.credits.max, (unsigned long long)xconn->smb2.credits.seq_low, - (unsigned int)xconn->smb2.credits.seq_range)); + (unsigned int)xconn->smb2.credits.seq_range); } static void smb2_calculate_credits(const struct smbd_smb2_request *inreq, @@ -1981,13 +1991,15 @@ NTSTATUS smbd_smb2_request_verify_creditcharge(struct smbd_smb2_request *req, needed_charge = (data_length - 1)/ 65536 + 1; - DEBUG(10, ("mid %llu, CreditCharge: %d, NeededCharge: %d\n", + DBGC_DEBUG(DBGC_SMB2_CREDITS, + "mid %llu, CreditCharge: %d, NeededCharge: %d\n", (unsigned long long) BVAL(inhdr, SMB2_HDR_MESSAGE_ID), - credit_charge, needed_charge)); + credit_charge, needed_charge); if (needed_charge > credit_charge) { - DEBUG(2, ("CreditCharge too low, given %d, needed %d\n", - credit_charge, needed_charge)); + DBGC_WARNING(DBGC_SMB2_CREDITS, + "CreditCharge too low, given %d, needed %d\n", + credit_charge, needed_charge); return NT_STATUS_INVALID_PARAMETER; } -- 2.11.4.GIT