From patchwork Tue Sep 24 07:59:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1166425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46ctsp6YH7z9sP3; Tue, 24 Sep 2019 18:00:46 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1iCfkX-0007cn-M9; Tue, 24 Sep 2019 08:00:41 +0000 Received: from mail-pl1-f193.google.com ([209.85.214.193]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iCfkC-0007Op-5o for kernel-team@lists.ubuntu.com; Tue, 24 Sep 2019 08:00:20 +0000 Received: by mail-pl1-f193.google.com with SMTP id q24so616457plr.13 for ; Tue, 24 Sep 2019 01:00:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yRrD6v47Vfn2dLITsO5nqVaw5+3mOVMoLJCI1TsO53E=; b=Y4zvWkV2POFhHYMz8qdPjUcgdN+CapmtSccFq2yULvbQxsZq9DA0AFWTpB2lWl43dS OnSgr0S1Kgr+0Ec4+Yqm+eyFnutwgoB+2EILCw+hQJDAyRk5ErbU9A/d6PhETDe1tBC5 ximy4jCfpoqIcDGVGgPuqLcG8q7Urk0CRIji/pBTHhDtC8BVVWAZ7uQ6PvswQr/mt6B8 o+6TClsAvhpZkGNpWBLlhCl6Dw/RvgB06Of33ax3cI19vj8WRsfrHT6/jqq7vFrQelNu LbvP7W2tutpwd8e6PKs6bPn8zwWNjS/z1ISDhyWUyUlyDl7FTOK1mO9pL0d57nlXCiCR z2FA== X-Gm-Message-State: APjAAAXdAkzzBWm2TVSQceTWuWZwMmf//iC1sYoUT97ydlYqL4vgnUbk p/xC7ME4OoNWcUo9VhcjopptLYjR X-Google-Smtp-Source: APXvYqzL0ePOpU99twJDYCzYcftDJak6HQTqGvLxKm6kjvkOSmSEMNwItOBu+g2BPWQ/w1KM4NI4qA== X-Received: by 2002:a17:902:a615:: with SMTP id u21mr1778507plq.4.1569312017866; Tue, 24 Sep 2019 01:00:17 -0700 (PDT) Received: from localhost.localdomain (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id g202sm1359780pfb.155.2019.09.24.01.00.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Sep 2019 01:00:17 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 04/21][SRU][OEM-OSP1-B] nl80211: use for_each_element() in validate_ie_attr() Date: Tue, 24 Sep 2019 15:59:30 +0800 Message-Id: <20190924075947.33954-5-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190924075947.33954-1-vicamo.yang@canonical.com> References: <20190924075947.33954-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Johannes Berg BugLink: https://bugs.launchpad.net/bugs/1845138 This makes for much simpler code, simply walk through all the elements and check that the last one found ends with the end of the data. This works because if any element is malformed the walk is aborted, we end up with a mismatch. Signed-off-by: Johannes Berg (cherry picked from commit 9f308616b6176b6dc470e6eb3569a09b100a823a) Signed-off-by: You-Sheng Yang --- net/wireless/nl80211.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 58d669690fb20..12265faed00ec 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -203,29 +203,17 @@ cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) static int validate_ie_attr(const struct nlattr *attr, struct netlink_ext_ack *extack) { - const u8 *pos; - int len; + const u8 *data = nla_data(attr); + unsigned int len = nla_len(attr); + struct element *elem; - pos = nla_data(attr); - len = nla_len(attr); - - while (len) { - u8 elemlen; - - if (len < 2) - goto error; - len -= 2; - - elemlen = pos[1]; - if (elemlen > len) - goto error; - - len -= elemlen; - pos += 2 + elemlen; + for_each_element(elem, data, len) { + /* nothing */ } - return 0; -error: + if (for_each_element_completed(elem, data, len)) + return 0; + NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); return -EINVAL; }