flar2, thanks for the explanation. You have mostly assuaged my concerns. If neither bio_check_eod() nor get_partition_num_by_name() is a syscall, which I assume is true, then there would be no way to hook them cleanly via the system call table.
I also see what you mean about mem_text_write_kernel_word() handling the cache flush.
I guess my only remaining concern would be that you are returning this meaningless number when get_partition_num_by_name is called on the "system" partition. I'm not sure how easy it would be to determine exactly what kind of unintended consequences this could have. I assume you have searched all the other kernel code for places this is called, but still.
I would suggest trying to use a similar method to
patch the existing bio_check_eod() function.
Code:
#ifdef CONFIG_MMC_MUST_PREVENT_WP_VIOLATION
sprintf(wp_ptn, "mmcblk0p%d", get_partition_num_by_name("system")); //hardcoded to look for system partition
if (!strcmp(bdevname(bio->bi_bdev, b), wp_ptn) && !board_mfg_mode() && //wp_ptn == mmcblk0p45 (/system)
(get_tamper_sf() == 1) && (bio->bi_rw & WRITE)) {
pr_info("blk-core: Attempt to write protected partition %s block %Lu \n",
bdevname(bio->bi_bdev, b), (unsigned long long)bio->bi_sector);
err = 0;
goto wp_end_io;
} else if (atomic_read(&emmc_reboot) && (bio->bi_rw & WRITE)) {
pr_info("%s: Attempt to write eMMC, %s block %Lu \n", current->comm,
bdevname(bio->bi_bdev, b), (unsigned long long)bio->bi_sector);
err = -EROFS;
goto wp_end_io;
}
#endif
You could try to replace that entire first if-block with NOP's (0x00000000). Or if you can find where the "mmcblk0p%d" string literal is allocated and replace it with "mXXXXk0p%d" or something.
Or as a last resort you could modify your replacement get_partition_num_by_name() function to only return the meaningless 666 value for 'system' if the calling function is bio_check_eod()?