All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Anthony Krowiak" <akrowiak@linux.ibm.com>,
	linux-s390@vger.kernel.org, kvm@vger.kernel.org
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH v9 11/15] s390/vfio-ap: File ops called to resume the vfio device migration
Date: Tue, 13 Oct 2026 16:14:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-170099@kernel.org> (raw)
In-Reply-To: <20261013153219.3534306-12-akrowiak@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] fortify: __counted_by() traps on memcpy() of ap_config causing kernel panic
- [Low] build: incompatible pointer type warning for num_queues in vfio_ap_get_config()
--

commit 1f3606fec30cc37e82a55e4d85b768771f43fc2f
Author: Anthony Krowiak <akrowiak@linux.ibm.com>

s390/vfio-ap: File ops called to resume the vfio device migration

This commit implements the write callback function for the file stream
created to restore the state of the vfio-ap device on the destination system.
Userspace reads the source guest's saved vfio-ap device state and writes it
to this file stream. The write callback copies each chunk into a pre-allocated
vfio_ap_config structure and validates it against the destination host's
configuration.

> --- a/drivers/s390/crypto/vfio_ap_migration.c
> +++ b/drivers/s390/crypto/vfio_ap_migration.c

[ ... ]

> @@ -284,7 +340,7 @@ static int vfio_ap_get_config(struct ap_matrix_mdev *matrix_mdev)
>  
>  	lockdep_assert_held(&matrix_dev->mdevs_lock);
>  
> -	ap_config_size = vfio_ap_config_size(matrix_mdev, (int *)&num_queues);
> +	ap_config_size = vfio_ap_config_size(matrix_mdev, &num_queues);

[Severity: Low]
Is it possible this causes a build failure? vfio_ap_config_size() expects
an int pointer for its second argument, but num_queues is declared as an
unsigned int. Passing an unsigned int pointer here introduces an
incompatible pointer type warning which breaks the build under
CONFIG_WERROR.

[ ... ]

> +static ssize_t vfio_ap_resuming_write(struct file *filp, const char __user *buf,
> +				      size_t len, loff_t *pos)
> +{

[ ... ]

> +	ret = validate_resuming_write_parms(filp, len);
> +	if (ret)
> +		goto out_unlock;
> +
> +	ap_config = matrix_mdev->mig_data->resuming_mig_file.ap_config;
> +
> +	memcpy((char *)ap_config + *pos, kbuf, len);

[Severity: High]
Does this memcpy() trigger a fortify panic? The struct vfio_ap_config
utilizes the __counted_by(num_queues) annotation for its flexible array.
During the resuming phase, ap_config is allocated with num_queues initialized
to 0.

Because memcpy() is fortified, it evaluates the maximum size of the
destination object using __builtin_dynamic_object_size(). At the time of
this memcpy(), ap_config->num_queues is still 0, so the compiler evaluates
the destination capacity strictly as the struct header size.

If userspace writes the migration data in a chunk larger than the header
size, the bounds check will fail before num_queues can be overwritten,
triggering a panic and crashing the system.

> +	*pos += len;
> +
> +	/*
> +	 * Check whether we have received all the data.  We know the total
> +	 * expected size once num_queues has arrived, i.e. once *pos is past
> +	 * the fixed header.  Until then keep accumulating.
> +	 */
> +	if (*pos >= offsetofend(struct vfio_ap_config, num_queues)) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013153219.3534306-1-akrowiak@linux.ibm.com?part=11

  reply	other threads:[~2026-10-13 16:14 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 15:32 [PATCH v9 00/15] s390/vfio-ap: Add live guest migration support Anthony Krowiak
2026-10-13 15:32 ` [PATCH v9 01/15] s390/vfio-ap: Provide function to get the number of queues assigned to mdev Anthony Krowiak
2026-10-13 15:38   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 02/15] s390/vfio-ap: Data structures for facilitating vfio device migration Anthony Krowiak
2026-10-13 15:40   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 03/15] s390/vfio-ap: Functions to initialize/release vfio device migration data Anthony Krowiak
2026-10-13 15:47   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 04/15] s390/vfio-ap: Reset migration state in VFIO_DEVICE_RESET ioctl handler Anthony Krowiak
2026-10-13 15:50   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 05/15] s390/vfio-ap: Callback to get/set vfio device mig state during guest migration Anthony Krowiak
2026-10-13 15:48   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 06/15] s390/vfio-ap: Transition guest migration state from STOP to STOP_COPY Anthony Krowiak
2026-10-13 15:55   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 07/15] s390/vfio-ap: File ops called to save the vfio device migration state Anthony Krowiak
2026-10-13 15:59   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 08/15] s390/vfio-ap: Transition device migration state from STOP to RESUMING Anthony Krowiak
2026-10-13 16:00   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 09/15] s390/vfio-ap: Prepare lock helpers and matrix init for cross-file use Anthony Krowiak
2026-10-13 16:00   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 10/15] s390/vfio-ap: Add method to set a new guest AP configuration Anthony Krowiak
2026-10-13 16:03   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 11/15] s390/vfio-ap: File ops called to resume the vfio device migration Anthony Krowiak
2026-10-13 16:14   ` sashiko-bot [this message]
2026-10-13 15:32 ` [PATCH v9 12/15] s390/vfio-ap: Transition device migration state to from/to STOP Anthony Krowiak
2026-10-13 16:08   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 13/15] s390/vfio-ap: Callback to get the size of data to be migrated during guest migration Anthony Krowiak
2026-10-13 16:10   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 14/15] s390/vfio-ap: Add 'migratable' feature to sysfs 'features' attribute Anthony Krowiak
2026-10-13 16:12   ` sashiko-bot
2026-10-13 15:32 ` [PATCH v9 15/15] s390/vfio-ap: Add live guest migration chapter to vfio-ap.rst Anthony Krowiak
2026-10-13 16:10   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-170099@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.