mirror of
https://github.com/samba-team/samba.git
synced 2025-02-26 21:57:41 +03:00
CVE-2015-5370: librpc/rpc: simplify and harden dcerpc_pull_auth_trailer()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11344 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Günther Deschner <gd@samba.org>
This commit is contained in:
parent
63a7d05d8c
commit
8e19ce76da
@ -83,31 +83,44 @@ uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob)
|
||||
*
|
||||
* @return - A NTSTATUS error code.
|
||||
*/
|
||||
NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
|
||||
NTSTATUS dcerpc_pull_auth_trailer(const struct ncacn_packet *pkt,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
DATA_BLOB *pkt_trailer,
|
||||
const DATA_BLOB *pkt_trailer,
|
||||
struct dcerpc_auth *auth,
|
||||
uint32_t *auth_length,
|
||||
uint32_t *_auth_length,
|
||||
bool auth_data_only)
|
||||
{
|
||||
struct ndr_pull *ndr;
|
||||
enum ndr_err_code ndr_err;
|
||||
uint32_t data_and_pad;
|
||||
uint16_t data_and_pad;
|
||||
uint16_t auth_length;
|
||||
uint32_t tmp_length;
|
||||
|
||||
data_and_pad = pkt_trailer->length
|
||||
- (DCERPC_AUTH_TRAILER_LENGTH + pkt->auth_length);
|
||||
|
||||
/* paranoia check for pad size. This would be caught anyway by
|
||||
the ndr_pull_advance() a few lines down, but it scared
|
||||
Jeremy enough for him to call me, so we might as well check
|
||||
it now, just to prevent someone posting a bogus YouTube
|
||||
video in the future.
|
||||
*/
|
||||
if (data_and_pad > pkt_trailer->length) {
|
||||
return NT_STATUS_INFO_LENGTH_MISMATCH;
|
||||
ZERO_STRUCTP(auth);
|
||||
if (_auth_length != NULL) {
|
||||
*_auth_length = 0;
|
||||
}
|
||||
|
||||
*auth_length = pkt_trailer->length - data_and_pad;
|
||||
/* Paranoia checks for auth_length. The caller should check this... */
|
||||
if (pkt->auth_length > pkt->frag_length) {
|
||||
return NT_STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
tmp_length = DCERPC_NCACN_PAYLOAD_OFFSET;
|
||||
tmp_length += DCERPC_AUTH_TRAILER_LENGTH;
|
||||
tmp_length += pkt->auth_length;
|
||||
if (tmp_length > pkt->frag_length) {
|
||||
return NT_STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
if (pkt_trailer->length > UINT16_MAX) {
|
||||
return NT_STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
auth_length = DCERPC_AUTH_TRAILER_LENGTH + pkt->auth_length;
|
||||
if (pkt_trailer->length < auth_length) {
|
||||
return NT_STATUS_RPC_PROTOCOL_ERROR;
|
||||
}
|
||||
|
||||
data_and_pad = pkt_trailer->length - auth_length;
|
||||
|
||||
ndr = ndr_pull_init_blob(pkt_trailer, mem_ctx);
|
||||
if (!ndr) {
|
||||
@ -127,14 +140,28 @@ NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
|
||||
ndr_err = ndr_pull_dcerpc_auth(ndr, NDR_SCALARS|NDR_BUFFERS, auth);
|
||||
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
|
||||
talloc_free(ndr);
|
||||
ZERO_STRUCTP(auth);
|
||||
return ndr_map_error2ntstatus(ndr_err);
|
||||
}
|
||||
|
||||
if (auth_data_only && data_and_pad != auth->auth_pad_length) {
|
||||
DEBUG(1, (__location__ ": WARNING: pad length mismatch. "
|
||||
if (data_and_pad < auth->auth_pad_length) {
|
||||
DEBUG(1, (__location__ ": ERROR: pad length mismatch. "
|
||||
"Calculated %u got %u\n",
|
||||
(unsigned)data_and_pad,
|
||||
(unsigned)auth->auth_pad_length));
|
||||
talloc_free(ndr);
|
||||
ZERO_STRUCTP(auth);
|
||||
return NT_STATUS_RPC_PROTOCOL_ERROR;
|
||||
}
|
||||
|
||||
if (auth_data_only && data_and_pad != auth->auth_pad_length) {
|
||||
DEBUG(1, (__location__ ": ERROR: pad length mismatch. "
|
||||
"Calculated %u got %u\n",
|
||||
(unsigned)data_and_pad,
|
||||
(unsigned)auth->auth_pad_length));
|
||||
talloc_free(ndr);
|
||||
ZERO_STRUCTP(auth);
|
||||
return NT_STATUS_RPC_PROTOCOL_ERROR;
|
||||
}
|
||||
|
||||
DEBUG(6,(__location__ ": auth_pad_length %u\n",
|
||||
@ -143,6 +170,10 @@ NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
|
||||
talloc_steal(mem_ctx, auth->credentials.data);
|
||||
talloc_free(ndr);
|
||||
|
||||
if (_auth_length != NULL) {
|
||||
*_auth_length = auth_length;
|
||||
}
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
|
@ -187,9 +187,9 @@ const char *dcerpc_default_transport_endpoint(TALLOC_CTX *mem_ctx,
|
||||
*
|
||||
* @return - A NTSTATUS error code.
|
||||
*/
|
||||
NTSTATUS dcerpc_pull_auth_trailer(struct ncacn_packet *pkt,
|
||||
NTSTATUS dcerpc_pull_auth_trailer(const struct ncacn_packet *pkt,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
DATA_BLOB *pkt_trailer,
|
||||
const DATA_BLOB *pkt_trailer,
|
||||
struct dcerpc_auth *auth,
|
||||
uint32_t *auth_length,
|
||||
bool auth_data_only);
|
||||
|
Loading…
x
Reference in New Issue
Block a user