From patchwork Sun Apr 29 15:56:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Ricardo Leitner X-Patchwork-Id: 906380 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tRFCrMnO"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40YtX62lNzz9ryr for ; Mon, 30 Apr 2018 02:33:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754020AbeD2QdT (ORCPT ); Sun, 29 Apr 2018 12:33:19 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:34212 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754013AbeD2QdR (ORCPT ); Sun, 29 Apr 2018 12:33:17 -0400 Received: by mail-qt0-f193.google.com with SMTP id m5-v6so8365706qti.1; Sun, 29 Apr 2018 09:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7PsM/YK5aisCbaT4YinJrTz1dnD2fKpgvw4r7XSu0Ks=; b=tRFCrMnOCs8ID1nCmMhLrpGfqDtI8vexPGL4HNF9jd+gBnKoF+z9EgeHx9JJzDCcHC RAeSa7F6S/xZjnWy/Czh+da1TA4Zzzpik6bk18o1AGua6cbPCsmJBge4jtia2CLSCDkD UvmfMdicZIrrHSlyLS1Nq6GvmzZOGbB8z408b0LFPGMvpCQQNjnSAfXGyG9nEQX3qpHr PwIo44lRX+EUYbmfXc03sSfkTsb4Un+giko4eRYx5HA80qrrB0iueHtBuRCZtYyz9FoJ h86Y+/gUzMD7M1faH++ppmKlPCddwHNJToqTH2ldf0RvsvSfdDEwEwhz0Q80JoXXHTCr XD6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7PsM/YK5aisCbaT4YinJrTz1dnD2fKpgvw4r7XSu0Ks=; b=fJiTAe/2ZqciMuPk0SzhmiLXX7OPwl26wwPfN2ZRqAtKOaZanI9D9t1OnDJUvOJAlT GuHXpc6Jpzi3t7DAf9Vd5LET+6sII1VWXb8fPkmnb19poKh4TuSd4Kh7gSJ9KvRxJyec 2Mq+qy7j/RxmvRJ/Ps5woispYrIfPzIeffnUsIggP49ouZ25xP6cMf/PDQjChShGiyQK OwKCq8YJihFxdBPGEZnM138wHMO05UVPZ3vpuSuINZuDf8EosZpnJCbvUcEW1Q/Z/awW boo5hYPJW4od/E6XVV8vFK2Y9KI3IJuVBCVIgDA1P97z39ethoogTXOTQp38KYnIK/KC F4NA== X-Gm-Message-State: ALQs6tDhi72v3PbS4V5V50yTg9J5A/L38Q2Z4zLITZgY0tjEop6UZeLx fHsgSNzqNE+XfD9+sX3aANQr+g== X-Google-Smtp-Source: AB8JxZr97xpJq3GKhbDVnOQ3x11bBs+QC4se+uynSBHYzWiDFW73dQh2Ci6pLO42YVXs48pC6qtFDw== X-Received: by 2002:aed:3111:: with SMTP id 17-v6mr9359518qtg.267.1525019596969; Sun, 29 Apr 2018 09:33:16 -0700 (PDT) Received: from localhost.localdomain ([177.10.56.95]) by smtp.gmail.com with ESMTPSA id n14sm4942926qkh.14.2018.04.29.09.33.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 29 Apr 2018 09:33:16 -0700 (PDT) Received: by localhost.localdomain (Postfix, from userid 89) id 92C7B18100C; Sun, 29 Apr 2018 13:35:35 -0300 (-03) Received: by localhost.localdomain (Postfix, from userid 89) id A2FE9180FB4; Sun, 29 Apr 2018 13:25:30 -0300 (-03) Received: by localhost.localdomain (Postfix, from userid 89) id A7C0D180916; Sun, 29 Apr 2018 13:01:57 -0300 (-03) Received: by localhost.localdomain (Postfix, from userid 1000) id BFAD11808BB; Sun, 29 Apr 2018 12:56:37 -0300 (-03) From: Marcelo Ricardo Leitner To: netdev@vger.kernel.org Cc: linux-sctp@vger.kernel.org, Vlad Yasevich , Neil Horman , Xin Long Subject: [PATCH net-next 1/2] sctp: allow sctp_init_cause to return errors Date: Sun, 29 Apr 2018 12:56:31 -0300 Message-Id: <985b5d2b052dd5121ab46be2704543258c6f5e8b.1525017179.git.marcelo.leitner@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org And do so if the skb doesn't have enough space for the payload. This is a preparation for the next patch. Signed-off-by: Marcelo Ricardo Leitner --- include/net/sctp/sm.h | 2 +- net/sctp/sm_make_chunk.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h index f4b657478a304050851f33d92c71162a4a4a2e50..5ef1bad81ef54906b375dbfd0e4fd897d078abce 100644 --- a/include/net/sctp/sm.h +++ b/include/net/sctp/sm.h @@ -215,7 +215,7 @@ struct sctp_chunk *sctp_make_shutdown_ack(const struct sctp_association *asoc, struct sctp_chunk *sctp_make_shutdown_complete( const struct sctp_association *asoc, const struct sctp_chunk *chunk); -void sctp_init_cause(struct sctp_chunk *chunk, __be16 cause, size_t paylen); +int sctp_init_cause(struct sctp_chunk *chunk, __be16 cause, size_t paylen); struct sctp_chunk *sctp_make_abort(const struct sctp_association *asoc, const struct sctp_chunk *chunk, const size_t hint); diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index db93eabd6ef500ab20be6e091ee06bd3b60923c9..e518eb64ccf3578f7892da050c160a56cf3cc833 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -158,8 +158,8 @@ static const struct sctp_paramhdr prsctp_param = { * provided chunk, as most cause codes will be embedded inside an * abort chunk. */ -void sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code, - size_t paylen) +int sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code, + size_t paylen) { struct sctp_errhdr err; __u16 len; @@ -167,8 +167,14 @@ void sctp_init_cause(struct sctp_chunk *chunk, __be16 cause_code, /* Cause code constants are now defined in network order. */ err.cause = cause_code; len = sizeof(err) + paylen; - err.length = htons(len); + err.length = htons(len); + + if (skb_tailroom(chunk->skb) < len) + return -ENOSPC; + chunk->subh.err_hdr = sctp_addto_chunk(chunk, sizeof(err), &err); + + return 0; } /* A helper to initialize an op error inside a