Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2646133rwb; Fri, 11 Nov 2022 12:28:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf7XcESURFLd8wK1X2oNMWHR6y1m4odpr0Er6KCbB2B1L7iHAsXR6igRVBkmPcGu/BgPrPeC X-Received: by 2002:a17:906:6d8:b0:7ad:e82b:b66b with SMTP id v24-20020a17090606d800b007ade82bb66bmr3226712ejb.453.1668198527221; Fri, 11 Nov 2022 12:28:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668198527; cv=none; d=google.com; s=arc-20160816; b=PXSnjDRv6O0gPytQkwoTXKHRBKWb/Lidsg5h39KhaDO+S0P04CSHUECXg9LULDqb9r YqS3pDuT/fmM3f0msaGq5GKeTqjUy3USR24IcctjKSOwIPb32d09frzvOuzegKLxUpZf weM3CNpILncofd+kGU6d0wtGcelUCAFT7eRUbuy7Lrn8YU0EJkNJuhxqCzmkhNvZclUO aVtdDLgZNlPURbV36uyil0EtaqaLRqBcEWXNuB5MaORDmaTl203mo7NjgMV+D3+6Y6tC 2qTKSbxLVceE+PAr9D9HNzEUOysB2/AC2+ibuJr7odVsvYB4mKVhr6eN3AZ77kuTYrY8 LbFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=6LNVQVouc+OP1BK7X0ZPCCVP9t58isq5AJxGmdz60sI=; b=sgL8SUah2d0YjwlLCotB4eFoGMY2xO5FfcB26CPJC4OYXZ0BPHv5UwCKJ9N4ipOEmt t5td/nCTjLVvwXeVgoV92neOfox723go+BlYQSnXE9zGqFH29j+qWYeIXZYRBLHG1IBp E+zcO6c5Q3kHLTh785YtOEXsvvow1U6Gx0RL6kvmPdC5veDZFMWDMux+Yor+tiH5xUhq jK1I+KrF9vC5TV8f6sm06gggWwcoUJCLoj8oOZ2wUxbkz458L69yscek24VloIOtQayd Qxsex9iVS6PiHQwgB/zBG/Hvm9je8CI5BIcojpj1lzzxhuInBxVtNxQ+TIydi4/MkcKU uUfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Zw1XnKVX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr11-20020a1709073f8b00b007413b206b16si2343536ejc.843.2022.11.11.12.28.25; Fri, 11 Nov 2022 12:28:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Zw1XnKVX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233899AbiKKTR6 (ORCPT + 90 others); Fri, 11 Nov 2022 14:17:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233437AbiKKTRz (ORCPT ); Fri, 11 Nov 2022 14:17:55 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A766A76F89 for ; Fri, 11 Nov 2022 11:17:54 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id w2-20020a17090a8a0200b002119ea856edso5900780pjn.5 for ; Fri, 11 Nov 2022 11:17:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6LNVQVouc+OP1BK7X0ZPCCVP9t58isq5AJxGmdz60sI=; b=Zw1XnKVX9ymWCWmLkPXsRTLz5PUxcDLfkFWyMVQaG5P+v92bAzbIe7WvZpx3cXWg4B PWn+TCAWaQ9yDT3rgEG0GFMjDyaob+DkR3NK50DHOBAKDLLAFXO7Ul7WXwTb70ooGtFO EpPBTUxyAszBkJEFq25va/NBIekcdsaxbKX83AVi71zyjycSKo1Gfq0ws8tBm7IrbFI2 fOloR4AaYdck0Er135C1fpvD0MmVOQkszST4xxqSJDHMsTKJen9zqApxhi+s8XNv6Vhf e6XkK/oMWsUGLpNggstozb2cyl2qxnMqruSnCuEZkJTAjBN/hnmpNnXIDwr2mtN5aGA/ Y62Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6LNVQVouc+OP1BK7X0ZPCCVP9t58isq5AJxGmdz60sI=; b=f01TDm0tOzWQMroYnhhsy/211CXoDstBDzRP5RSFsCzeAa98kmCfBcT/y3scKTqMMb hzjTIgHgVUsu9OR1NJLc3uRhIR3uOoyoJv1a8ot+WWu7WoStCY4NB5GyZLOUo/C7/Px6 3VawPE2L+cDP0d3V5PBjxRi3Z2fNfRrKtKHm7Q81VPuSo3vHcDdT8+PnxbdhffPNkAxC GJaJAf6mbhE2Wsss8PHZ4mUPfQYywTZDVSemwoVlBO2xZWW2aNgxkLV4VkY8bPm4BHn7 m4xPWbFGgtk9z0VI5f5iPA8NTw7x2OQaIfLyggN9Uto4YRePeCEQN/0DGFuV/Ry4JFLV iVbA== X-Gm-Message-State: ANoB5pn0o8VcGMfMbQ3m+YFTzsyUC3JXs5/Nj+qIsokSJqyH13t5QPrN kjKkh3Qz/WB8L6hMzP/0+mO0bSY= X-Received: from sdf.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5935]) (user=sdf job=sendgmr) by 2002:a17:90a:8a11:b0:213:1935:9744 with SMTP id w17-20020a17090a8a1100b0021319359744mr3409621pjn.207.1668194274187; Fri, 11 Nov 2022 11:17:54 -0800 (PST) Date: Fri, 11 Nov 2022 11:17:52 -0800 In-Reply-To: <20221111125620.754855-1-xukuohai@huaweicloud.com> Mime-Version: 1.0 References: <20221111125620.754855-1-xukuohai@huaweicloud.com> Message-ID: Subject: Re: [PATCH bpf] bpf: Fix offset calculation error in __copy_map_value and zero_map_value From: sdf@google.com To: Xu Kuohai Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , Kumar Kartikeya Dwivedi Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/11, Xu Kuohai wrote: > From: Xu Kuohai > Function __copy_map_value and zero_map_value miscalculated copy offset, > resulting in possible copy of unwanted data to user or kernel. > Fix it. > Fixes: cc48755808c6 ("bpf: Add zero_map_value to zero map value with > special fields") > Fixes: 4d7d7f69f4b1 ("bpf: Adapt copy_map_value for multiple offset case") > Signed-off-by: Xu Kuohai > --- > include/linux/bpf.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 74c6f449d81e..c1bd1bd10506 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -315,7 +315,7 @@ static inline void __copy_map_value(struct bpf_map > *map, void *dst, void *src, b > u32 next_off = map->off_arr->field_off[i]; > memcpy(dst + curr_off, src + curr_off, next_off - curr_off); > - curr_off += map->off_arr->field_sz[i]; > + curr_off = next_off + map->off_arr->field_sz[i]; > } > memcpy(dst + curr_off, src + curr_off, map->value_size - curr_off); > } > @@ -344,7 +344,7 @@ static inline void zero_map_value(struct bpf_map > *map, void *dst) > u32 next_off = map->off_arr->field_off[i]; > memset(dst + curr_off, 0, next_off - curr_off); > - curr_off += map->off_arr->field_sz[i]; > + curr_off = next_off + map->off_arr->field_sz[i]; > } > memset(dst + curr_off, 0, map->value_size - curr_off); > } Hmm, does it mean that it currently works only for the cases where these special fields are first/last? Also, what about bpf-next? The same problem seem to exist there? Might be a good idea to have some selftest to exercise this? > -- > 2.30.2