Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp11301478rwd; Thu, 22 Jun 2023 11:19:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5rIZ+3EuZ18dlNmDonnce6v4bww5M8FncoV0lheU+EBIRYEoNJdTYn/1V2LFv7ATtOYgLM X-Received: by 2002:a17:903:120e:b0:1b3:b200:a3d7 with SMTP id l14-20020a170903120e00b001b3b200a3d7mr14426467plh.52.1687457955635; Thu, 22 Jun 2023 11:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687457955; cv=none; d=google.com; s=arc-20160816; b=clUgDkDz9XiHhkYXxym2YeH9BQSNj7l+oMquGx373grIWFIcAfc2wsJPdWt4Fimw0j Y9qSRClwE03VCntnI72ZXsLdW8FosnaYpOnzmFFpt0aJZf2VA4KT/KJVvy8JBagwxg4w LTyEEQGMhHrTi6JtMaGBSgMJdcqR/YFVBr4WU+Yd0FQXQh3VmBgKJK+JpLzM/Km5qf/a a0CTAWZYey9+iN3nGR7jJ3uZyVVO4ExlUnr2LoWCZ2Ax2mw+PhURbt5NY/ihYcDF8p30 3JbWXgYQWqDUg9abY6j73t1TqAeicSyghinlHV2O8xdGRl6F0guW4MsrEG6RxOHChDPk yiZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=1XwheaDZGZRpJwzvs7S81oxlOK2dxP/D6trWluCaM6o=; b=VnFuewkadUIBmZVPLOS0NfK7HgDdp12CvNwgg2yMwu9kLhSeU4B5J6+pdw4e+JmYhe fdJO17n2yidjqHL3WSB9gpmrMSAzSXaOn24FSsF/KqHA5Db5x3GSF7EYpSaH7Utidc9A JfYnaHKMBMu0dnb0otdCscL4oRp7s+aomhiVT+6ogMhVjoH3qyfiGwGERvEERPSGXr4Q XrA0RRBcp/Bqx92SV4+qbWHUbLQH+0T019LY/wc251ipcXEbB3vMWOf11/vtTbtYASl8 NNTBOE1Vu31cno3L703jCZpPAsnOs+0OMkIUivMRhwj4GygzDGtFdqTtQtupUACLehPT BmPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D6awooF+; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t5-20020a170902e84500b001b251877944si1707172plg.50.2023.06.22.11.19.03; Thu, 22 Jun 2023 11:19:15 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=D6awooF+; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230444AbjFVRb6 (ORCPT + 99 others); Thu, 22 Jun 2023 13:31:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231249AbjFVRbw (ORCPT ); Thu, 22 Jun 2023 13:31:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0AD21FE9 for ; Thu, 22 Jun 2023 10:31:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687455066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1XwheaDZGZRpJwzvs7S81oxlOK2dxP/D6trWluCaM6o=; b=D6awooF+VGb06s4LnvDd2CVN4Q9SUR0bOkG4NHo04Se0NYGDI88vYJ2W65vfMVxEJG0C1O IGgxUk1t7hS8vIb63ZguyTgMd+4H3OR2h+nUwyFnDLZUq9Vx9EaAEc+P1Xy42tIIG2sRga 0FCHlBd/7kdvuhszwWs0ZfHpZ+i4PV0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-126-m_NT0INGNfOCJC9XE_vJGA-1; Thu, 22 Jun 2023 13:31:02 -0400 X-MC-Unique: m_NT0INGNfOCJC9XE_vJGA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 48F1490ED25; Thu, 22 Jun 2023 17:30:57 +0000 (UTC) Received: from file1-rdu.file-001.prod.rdu2.dc.redhat.com (unknown [10.11.5.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EA6D2166B25; Thu, 22 Jun 2023 17:30:49 +0000 (UTC) Received: by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix, from userid 12668) id 78C5430C0457; Thu, 22 Jun 2023 17:30:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix) with ESMTP id 77DE53F7CF; Thu, 22 Jun 2023 19:30:49 +0200 (CEST) Date: Thu, 22 Jun 2023 19:30:49 +0200 (CEST) From: Mikulas Patocka To: Demi Marie Obenour cc: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [dm-devel] [PATCH v2 2/6] device-mapper: Avoid pointer arithmetic overflow In-Reply-To: <20230603145244.1538-3-demi@invisiblethingslab.com> Message-ID: References: <20230601212456.1533-1-demi@invisiblethingslab.com> <20230603145244.1538-1-demi@invisiblethingslab.com> <20230603145244.1538-3-demi@invisiblethingslab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Sat, 3 Jun 2023, Demi Marie Obenour wrote: > Especially on 32-bit systems, it is possible for the pointer arithmetic > to overflow and cause a userspace pointer to be dereferenced in the > kernel. > > Signed-off-by: Demi Marie Obenour > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > Cc: stable@vger.kernel.org Reviewed-by: Mikulas Patocka > --- > drivers/md/dm-ioctl.c | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c > index 34fa74c6a70db8aa67aaba3f6a2fc4f38ef736bc..64e8f16d344c47057de5e2d29e3d63202197dca0 100644 > --- a/drivers/md/dm-ioctl.c > +++ b/drivers/md/dm-ioctl.c > @@ -1396,6 +1396,25 @@ static int next_target(struct dm_target_spec *last, uint32_t next, void *end, > { > static_assert(_Alignof(struct dm_target_spec) <= 8, > "struct dm_target_spec has excessive alignment requirements"); > + static_assert(offsetof(struct dm_ioctl, data) >= sizeof(struct dm_target_spec), > + "struct dm_target_spec too big"); > + > + /* > + * Number of bytes remaining, starting with last. This is always > + * sizeof(struct dm_target_spec) or more, as otherwise *last was > + * out of bounds already. > + */ > + size_t remaining = (char *)end - (char *)last; > + > + /* > + * There must be room for both the next target spec and the > + * NUL-terminator of the target itself. > + */ > + if (remaining - sizeof(struct dm_target_spec) <= next) { > + DMERR("Target spec extends beyond end of parameters"); > + return -EINVAL; > + } > + > if (next % 8) { > DMERR("Next target spec (offset %u) is not 8-byte aligned", next); > return -EINVAL; > -- > Sincerely, > Demi Marie Obenour (she/her/hers) > Invisible Things Lab > > -- > dm-devel mailing list > dm-devel@redhat.com > https://listman.redhat.com/mailman/listinfo/dm-devel >