Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2503554ybh; Fri, 24 Jul 2020 14:48:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzvBRyuWBrEkOLWXliXne/LXdQGdeyOEZ/Djn/KjaI9ijoy6gqlt5CYJ46Vrzl1Mf3PdMj X-Received: by 2002:a17:906:950c:: with SMTP id u12mr10776066ejx.37.1595627287612; Fri, 24 Jul 2020 14:48:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595627287; cv=none; d=google.com; s=arc-20160816; b=BDvQT7qe9m2FCBawWdiFLqaAauaowyqYTaATEdJAf50v6+p/7hLyvqf5aDd0mz3YHq ajWFJDnr8gCeIRFN4ttXUjf6OZlfFPKF86iQPj89dqXd8SxwjEsQO/txeZmlAXJmuJx3 jbTou+V+hlQ9//OrFRwzM9sXfN8dF75yyGGDyCgsbOGX2ghYoqNF95sFbUdBUfv7uSMw cQ2JTJiNvbaGenDfb7sUMCpt6sC7kqVoRA7Qd1qEOdsdgXSFN8LWslktegrpL/DkttSb WuoRaq6dxEZNZOixZJYOCeShBQ6fAMpxU67NbtUGrKSOotZUAeYhoNeivg+MKUJa9QDE hdKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=YZGD4OodDleZ/Yxr9/TUm5yXUoLz2XAGYdSqw9Im1hk=; b=aTG0Fv9a9XqrBaYGh0jWll9a1+5Bs7W8h9pUQ7a0v75l0ZkIFmDrVo9ezy3yaPNWyR J1wGUKrF2E/NunjkuklB6kgTvSbpWXurOAx6h0NuC1MekRLD95efeFTmy/UpRq1bLpII pnekKh77JpNw0Jlo6XEDngwAKtg1gOUwtD/HN2mKCsehj247L7bm8YijKGXma4/8q/YZ LAn2a15jXAsSTbAOLPLeKToK+Ew227UikAfvbb6OW5ufSzm+S1PlPz3O2DewiaJoNO+N Sc7SFMNN6nr0NmFfMke1Bjq3h5HNng3SH0ttTQi7yDIamPFNubEgn6m3t/dZVu7V2S9U /FzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=D9i2ZHiT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a3si1324506eju.177.2020.07.24.14.47.43; Fri, 24 Jul 2020 14:48:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=D9i2ZHiT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbgGXVpZ (ORCPT + 99 others); Fri, 24 Jul 2020 17:45:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726625AbgGXVpX (ORCPT ); Fri, 24 Jul 2020 17:45:23 -0400 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 347A4C0619E4 for ; Fri, 24 Jul 2020 14:45:23 -0700 (PDT) Received: by mail-il1-x144.google.com with SMTP id s21so8403277ilk.5 for ; Fri, 24 Jul 2020 14:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=YZGD4OodDleZ/Yxr9/TUm5yXUoLz2XAGYdSqw9Im1hk=; b=D9i2ZHiThHuwK+qViCHANccMkvriE1UbajxhaLuXoQgrdd+KHecfVmrhJ3gXfsvAvF 430N1y4dm8jwgKy5wrm/GEvNNsATIIk4hxos7joFCASijHp6QKQG9C8DedjfutZdarlZ SsaCDprLjV4TdHa/KUr9cymgj2oFF876LhE7f9jjHtFyt3sVvTynypwoA0GfHVV+KX4c l7SZZzp1DKcjiwGGjDYpGWMj8sMq7g1DYck0mVjftTGDkvu8dDjhmzF1BYxMlHdKt7/f 4oQplz8JyWNErMpl+iMiYko/iT11WnrYzab7nyPoGN9dtishcFDzDrotW+dGrR/qFTce BzNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=YZGD4OodDleZ/Yxr9/TUm5yXUoLz2XAGYdSqw9Im1hk=; b=WB9j4tZLOwUqkQ5hWExPT1l5vhUbrMdzTIcTDvvsF9bVECW6kxmAnUwAdRzw6g973f JkRGjEuHG8H7C76MFtFZOAV9joTCWyPkIx5Erc97xde03ziljHF1GifBg2aFxe4jjFWi yt7Q3Z/Aq9gh4t2s0DIeC56IzkVXIwg7D6kP+2bhXKimJLNeF/4JWoOVPGgCPQCZnG/L Maqco9mLqP2bLPSUwL5xvrCCylzwqNcRfEDTYPp4xych6FPd7ehI0X68J8/UsViYhkZ7 9/ybB/2M2+KhO0KXbyua8LdvXsDAJpErhF7Q320G6vvW3pGEe3LLvqYR5ACe6iCDkOsE C1Bw== X-Gm-Message-State: AOAM5302yfEU/GLpICsJN4Dv4siLG2yScTw6knzy7fISXYlh0ZCIdz9a aAU9Tm7JOnSwNrd6NJSw0GFqoA== X-Received: by 2002:a92:c792:: with SMTP id c18mr12541365ilk.223.1595627121666; Fri, 24 Jul 2020 14:45:21 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([2620:15c:211:0:4a0f:cfff:fe35:d61b]) by smtp.googlemail.com with ESMTPSA id f206sm3866369ilh.75.2020.07.24.14.45.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jul 2020 14:45:21 -0700 (PDT) Subject: Re: [PATCH] netlink: add buffer boundary checking To: Jacob Keller , Eric Dumazet , linux-kernel@vger.kernel.org Cc: kernel-team@android.com, netdev@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Thomas Graf References: <20200723182136.2550163-1-salyzyn@android.com> <09cd1829-8e41-bef5-ba5e-1c446c166778@gmail.com> <8bd7695c-0012-83e9-8a5a-94a40d91d6f6@intel.com> From: Mark Salyzyn Message-ID: Date: Fri, 24 Jul 2020 14:45:20 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <8bd7695c-0012-83e9-8a5a-94a40d91d6f6@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/24/20 2:14 PM, Jacob Keller wrote: > > On 7/23/2020 12:35 PM, Eric Dumazet wrote: >> On 7/23/20 11:21 AM, Mark Salyzyn wrote: >>> Many of the nla_get_* inlines fail to check attribute's length before >>> copying the content resulting in possible out-of-boundary accesses. >>> Adjust the inlines to perform nla_len checking, for the most part >>> using the nla_memcpy function to faciliate since these are not >>> necessarily performance critical and do not need a likely fast path. >>> >>> Signed-off-by: Mark Salyzyn >>> Cc: netdev@vger.kernel.org >>> Cc: linux-kernel@vger.kernel.org >>> Cc: kernel-team@android.com >>> Cc: "David S. Miller" >>> Cc: Jakub Kicinski >>> Cc: Thomas Graf >>> Fixes: bfa83a9e03cf ("[NETLINK]: Type-safe netlink messages/attributes interface") >>> --- >>> include/net/netlink.h | 66 +++++++++++++++++++++++++++++++++++-------- >>> 1 file changed, 54 insertions(+), 12 deletions(-) >>> >>> diff --git a/include/net/netlink.h b/include/net/netlink.h >>> index c0411f14fb53..11c0f153be7c 100644 >>> --- a/include/net/netlink.h >>> +++ b/include/net/netlink.h >>> @@ -1538,7 +1538,11 @@ static inline int nla_put_bitfield32(struct sk_buff *skb, int attrtype, >>> */ >>> static inline u32 nla_get_u32(const struct nlattr *nla) >>> { >>> - return *(u32 *) nla_data(nla); >>> + u32 tmp; >>> + >>> + nla_memcpy(&tmp, nla, sizeof(tmp)); >>> + >>> + return tmp; >> I believe this will hide bugs, that syzbot was able to catch. >> >> Instead, you could perhaps introduce a CONFIG_DEBUG_NETLINK option, >> and add a WARN_ON_ONCE(nla_len(nla) < sizeof(u32)) so that we can detect bugs in callers. >> >> > I also think this is a better approach. We (another engineer here) are looking into that and will get back to everyone. Sincerely -- Mark Salyzyn